Search in sources :

Example 81 with ByteOrder

use of java.nio.ByteOrder in project simple-binary-encoding by real-logic.

the class CSharpGenerator method generateEnumProperty.

private CharSequence generateEnumProperty(final String propertyName, final Token token, final String indent) {
    final String enumName = formatClassName(token.applicableTypeName());
    final String typePrefix = toUpperFirstChar(token.encoding().primitiveType().primitiveName());
    final String enumUnderlyingType = cSharpTypeName(token.encoding().primitiveType());
    final int offset = token.offset();
    final ByteOrder byteOrder = token.encoding().byteOrder();
    final String byteOrderStr = generateByteOrder(byteOrder, token.encoding().primitiveType().size());
    final StringBuilder sb = new StringBuilder();
    sb.append(String.format("\n" + indent + INDENT + "public %1$s %2$s\n" + indent + INDENT + "{\n" + indent + INDENT + INDENT + "get\n" + indent + INDENT + INDENT + "{\n" + "%3$s" + indent + INDENT + INDENT + INDENT + "return (%4$s)_buffer.%5$sGet%7$s(_offset + %6$d);\n" + indent + INDENT + INDENT + "}\n" + indent + INDENT + INDENT + "set\n" + indent + INDENT + INDENT + "{\n" + indent + INDENT + INDENT + INDENT + "_buffer.%5$sPut%7$s(_offset + %6$d, (%8$s)value);\n" + indent + INDENT + INDENT + "}\n" + indent + INDENT + "}\n\n", enumName, toUpperFirstChar(propertyName), generateEnumFieldNotPresentCondition(token.version(), enumName, indent), enumName, typePrefix, offset, byteOrderStr, enumUnderlyingType));
    return sb;
}
Also used : ByteOrder(java.nio.ByteOrder)

Example 82 with ByteOrder

use of java.nio.ByteOrder in project simple-binary-encoding by real-logic.

the class CSharpGenerator method generateVarData.

private CharSequence generateVarData(final List<Token> tokens, final String indent) {
    final StringBuilder sb = new StringBuilder();
    for (int i = 0, size = tokens.size(); i < size; i++) {
        final Token token = tokens.get(i);
        if (token.signal() == Signal.BEGIN_VAR_DATA) {
            generateFieldIdMethod(sb, token, indent);
            final String characterEncoding = tokens.get(i + 3).encoding().characterEncoding();
            generateCharacterEncodingMethod(sb, token.name(), characterEncoding, indent);
            generateFieldMetaAttributeMethod(sb, token, indent);
            final String propertyName = toUpperFirstChar(token.name());
            final Token lengthToken = tokens.get(i + 2);
            final int sizeOfLengthField = lengthToken.encodedLength();
            final Encoding lengthEncoding = lengthToken.encoding();
            final String lengthCSharpType = cSharpTypeName(lengthEncoding.primitiveType());
            final String lengthTypePrefix = toUpperFirstChar(lengthEncoding.primitiveType().primitiveName());
            final ByteOrder byteOrder = lengthEncoding.byteOrder();
            final String byteOrderStr = generateByteOrder(byteOrder, lengthEncoding.primitiveType().size());
            sb.append(String.format("\n" + indent + "public const int %sHeaderSize = %d;\n", propertyName, sizeOfLengthField));
            sb.append(String.format("\n" + indent + "public int Get%1$s(byte[] dst, int dstOffset, int length)\n" + indent + "{\n" + "%2$s" + indent + INDENT + "const int sizeOfLengthField = %3$d;\n" + indent + INDENT + "int limit = _parentMessage.Limit;\n" + indent + INDENT + "_buffer.CheckLimit(limit + sizeOfLengthField);\n" + indent + INDENT + "int dataLength = (int)_buffer.%4$sGet%5$s(limit);\n" + indent + INDENT + "int bytesCopied = Math.Min(length, dataLength);\n" + indent + INDENT + "_parentMessage.Limit = limit + sizeOfLengthField + dataLength;\n" + indent + INDENT + "_buffer.GetBytes(limit + sizeOfLengthField, dst, dstOffset, bytesCopied);\n\n" + indent + INDENT + "return bytesCopied;\n" + indent + "}\n", propertyName, generateArrayFieldNotPresentCondition(token.version(), indent), sizeOfLengthField, lengthTypePrefix, byteOrderStr));
            sb.append(String.format("\n" + indent + "public int Set%1$s(byte[] src, int srcOffset, int length)\n" + indent + "{\n" + indent + INDENT + "const int sizeOfLengthField = %2$d;\n" + indent + INDENT + "int limit = _parentMessage.Limit;\n" + indent + INDENT + "_parentMessage.Limit = limit + sizeOfLengthField + length;\n" + indent + INDENT + "_buffer.%3$sPut%5$s(limit, (%4$s)length);\n" + indent + INDENT + "_buffer.SetBytes(limit + sizeOfLengthField, src, srcOffset, length);\n\n" + indent + INDENT + "return length;\n" + indent + "}\n", propertyName, sizeOfLengthField, lengthTypePrefix, lengthCSharpType, byteOrderStr));
        }
    }
    return sb;
}
Also used : ByteOrder(java.nio.ByteOrder)

Example 83 with ByteOrder

use of java.nio.ByteOrder in project simple-binary-encoding by real-logic.

the class CSharpGenerator method generateSingleValueProperty.

private CharSequence generateSingleValueProperty(final String propertyName, final Token token, final String indent) {
    final String typeName = cSharpTypeName(token.encoding().primitiveType());
    final String typePrefix = toUpperFirstChar(token.encoding().primitiveType().primitiveName());
    final int offset = token.offset();
    final ByteOrder byteOrder = token.encoding().byteOrder();
    final String byteOrderStr = generateByteOrder(byteOrder, token.encoding().primitiveType().size());
    final StringBuilder sb = new StringBuilder();
    sb.append(String.format("\n" + indent + "public %1$s %2$s\n" + indent + "{\n" + indent + INDENT + "get\n" + indent + INDENT + "{\n" + "%3$s" + indent + INDENT + INDENT + "return _buffer.%4$sGet%6$s(_offset + %5$d);\n" + indent + INDENT + "}\n" + indent + INDENT + "set\n" + indent + INDENT + "{\n" + indent + INDENT + INDENT + "_buffer.%4$sPut%6$s(_offset + %5$d, value);\n" + indent + INDENT + "}\n" + indent + "}\n\n", typeName, toUpperFirstChar(propertyName), generateFieldNotPresentCondition(token.version(), token.encoding(), indent), typePrefix, offset, byteOrderStr));
    return sb;
}
Also used : ByteOrder(java.nio.ByteOrder)

Example 84 with ByteOrder

use of java.nio.ByteOrder in project simple-binary-encoding by real-logic.

the class IrDecoder method decode.

public Ir decode() {
    decodeFrame();
    final List<Token> tokens = new ArrayList<>();
    while (offset < length) {
        tokens.add(decodeToken());
    }
    int i = 0;
    if (tokens.get(0).signal() == Signal.BEGIN_COMPOSITE) {
        i = captureHeader(tokens);
    }
    final ByteOrder byteOrder = tokens.size() > 0 ? tokens.get(0).encoding().byteOrder() : null;
    final Ir ir = new Ir(irPackageName, irNamespaceName, irId, irVersion, semanticVersion, byteOrder, irHeader);
    for (int size = tokens.size(); i < size; i++) {
        if (tokens.get(i).signal() == Signal.BEGIN_MESSAGE) {
            i = captureMessage(tokens, i, ir);
        }
    }
    return ir;
}
Also used : ArrayList(java.util.ArrayList) ByteOrder(java.nio.ByteOrder)

Example 85 with ByteOrder

use of java.nio.ByteOrder in project bitrafael_public by GENERALBYTESCOM.

the class Keccak256 method digest.

public void digest(ByteBuffer out) {
    int outBytes = out.remaining();
    if (outBytes <= 0)
        return;
    long[] state = this.state;
    int rateBits = this.rateBits;
    int rateBytes;
    if (!padded) {
        pad();
        padded = true;
        rateBits = 0;
        rateBytes = 0;
    } else {
        if ((rateBits & 0x7) > 0)
            // this could be implemented but would introduce considerable performance degradation - also, it's never technically possible.
            throw new IllegalStateException("Cannot digest while in bit-mode");
        rateBytes = rateBits >>> 3;
        int rateBytesWord = rateBytes & 0x7;
        if (rateBytesWord > 0) {
            int c = 8 - rateBytesWord;
            if (c > outBytes)
                c = outBytes;
            long w = state[rateBytes >>> 3];
            outBytes -= c;
            rateBytes += c;
            rateBytesWord <<= 3;
            c = (c << 3) + rateBytesWord;
            do {
                out.put((byte) (w >>> rateBytesWord));
                rateBytesWord += 8;
            } while (rateBytesWord < c);
            if (outBytes <= 0) {
                this.rateBits = rateBytes << 3;
                return;
            }
        }
    }
    int rateSizeWords = rateSizeBits >>> 6;
    int rateWords = rateBytes >>> 3;
    int outWords = outBytes >>> 3;
    if (outWords > 0) {
        ByteOrder order = out.order();
        try {
            out.order(ByteOrder.LITTLE_ENDIAN);
            do {
                if (rateWords >= rateSizeWords) {
                    squeeze();
                    rateWords = 0;
                }
                int c = rateSizeWords - rateWords;
                if (c > outWords)
                    c = outWords;
                outWords -= c;
                c += rateWords;
                do {
                    out.putLong(state[rateWords]);
                    rateWords++;
                } while (rateWords < c);
            } while (outWords > 0);
        } finally {
            out.order(order);
        }
        outBytes &= 0x7;
        if (outBytes <= 0) {
            this.rateBits = rateWords << 6;
            return;
        }
    }
    if (rateWords >= rateSizeWords) {
        squeeze();
        rateWords = 0;
    }
    long w = state[rateWords];
    outBytes <<= 3;
    int i = 0;
    do {
        out.put((byte) (w >>> i));
        i += 8;
    } while (i < outBytes);
    this.rateBits = (rateWords << 6) | outBytes;
}
Also used : ByteOrder(java.nio.ByteOrder)

Aggregations

ByteOrder (java.nio.ByteOrder)111 ByteBuffer (java.nio.ByteBuffer)39 IOException (java.io.IOException)8 Test (org.junit.Test)7 QuickTest (com.hazelcast.test.annotation.QuickTest)5 DataInputStream (java.io.DataInputStream)5 FileInputStream (java.io.FileInputStream)5 UUID (java.util.UUID)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 HKL (ffx.crystal.HKL)3 DataOutputStream (java.io.DataOutputStream)3 EOFException (java.io.EOFException)3 FileOutputStream (java.io.FileOutputStream)3 ShortBuffer (java.nio.ShortBuffer)3 ArrayList (java.util.ArrayList)3 Element (org.jdom.Element)3 InvalidDumpFormatException (com.ibm.j9ddr.corereaders.InvalidDumpFormatException)2 Point (com.revolsys.geometry.model.Point)2 Crystal (ffx.crystal.Crystal)2 BigInteger (java.math.BigInteger)2