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());
scratchChain, rustTypeName(node.blockLengthType), generateRustLiteral(node.blockLengthType, Integer.toString(node.blockLength)), node.blockLengthType.size()); indent(out, 2, "%s.write_type::<%s>(&count, %s)?; // group count\n", scratchChain, rustCountType, node.numInGroupType.size()); indent(out, 2, "let c = count as usize;\n"); indent(out, 2, "let group_slice = %s.writable_slice::<%s>(c, %s)?;\n", scratchChain, rustTypeName(node.blockLengthType), generateRustLiteral(node.blockLengthType, Integer.toString(node.blockLength)), node.blockLengthType.size()); indent(out, 2, "let count = s.len();\n"); indent(out, 2, "if count > %s {\n", node.numInGroupType.maxValue()); indent(out, 3).append("return Err(CodecErr::SliceIsLongerThanAllowedBySchema)\n"); indent(out, 2).append("}\n"); indent(out, 2, "%s.write_type::<%s>(&(count as %s), %s)?; // group count\n", scratchChain, rustCountType, rustCountType, node.numInGroupType.size()); indent(out, 2, "%s.write_slice_without_count::<%s>(s, %s)?;\n", scratchChain, fieldsType, node.blockLength);
/** * The encodedLength (in octets) of the encodingType * * @return encodedLength of the encodingType */ public int encodedLength() { return encodingType.size(); }
static String generateRustLiteral(final PrimitiveType type, final String value) { Verify.notNull(type, "type"); Verify.notNull(value, "value"); final String typeName = rustTypeName(type); if (typeName == null) { throw new IllegalArgumentException("Unknown Rust type name found for primitive " + type.primitiveName()); } switch (type) { case CHAR: case UINT8: case INT8: case INT16: case UINT16: case INT32: case INT64: case UINT32: case UINT64: return value + typeName; case FLOAT: case DOUBLE: return value.endsWith("NaN") ? typeName + "::NAN" : value + typeName; default: throw new IllegalArgumentException("Unsupported literal generation for type: " + type.primitiveName()); } }
else if (!isUnsigned(blockLengthType.primitiveType())) else if (!isUnsigned(numInGroupType.primitiveType())) numInGroupMaxValue.longValue() : numInGroupType.primitiveType().maxValue().longValue();
/** * The most applicable max value for the encoded type. * * @return most applicable max value for the encoded type. */ public PrimitiveValue applicableMaxValue() { if (null != maxValue) { return maxValue; } return primitiveType.maxValue(); }
/** * The most applicable min value for the encoded type. * * @return most applicable min value for the encoded type. */ public PrimitiveValue applicableMinValue() { if (null != minValue) { return minValue; } return primitiveType.minValue(); }
/** * The most applicable null value for the encoded type. * * @return most applicable null value for the encoded type. */ public PrimitiveValue applicableNullValue() { if (null != nullValue) { return nullValue; } return primitiveType.nullValue(); }
if (!isUnsigned(primitiveType))
/** * Return the Cpp98 formatted byte order encoding string to use for a given byte order and primitiveType * * @param byteOrder of the {@link uk.co.real_logic.sbe.ir.Token} * @param primitiveType of the {@link uk.co.real_logic.sbe.ir.Token} * @return the string formatted as the byte ordering encoding */ public static String formatByteOrderEncoding(final ByteOrder byteOrder, final PrimitiveType primitiveType) { switch (primitiveType.size()) { case 2: return "SBE_" + byteOrder + "_ENCODE_16"; case 4: return "SBE_" + byteOrder + "_ENCODE_32"; case 8: return "SBE_" + byteOrder + "_ENCODE_64"; default: return ""; } }
private void add(final EnumType type, final int offset, final Field field) { final PrimitiveType encodingType = type.encodingType(); final Encoding.Builder encodingBuilder = new Encoding.Builder() .primitiveType(encodingType) .semanticType(semanticTypeOf(type, field)) .byteOrder(byteOrder); if (type.presence() == Presence.OPTIONAL) { encodingBuilder.nullValue(encodingType.nullValue()); } final Token.Builder builder = new Token.Builder() .signal(Signal.BEGIN_ENUM) .name(type.name()) .size(encodingType.size()) .offset(offset) .encoding(encodingBuilder.build()); if (field != null) { builder.version(field.sinceVersion()); } tokenList.add(builder.build()); for (final EnumType.ValidValue validValue : type.validValues()) { add(validValue, encodingType, field); } builder.signal(Signal.END_ENUM); tokenList.add(builder.build()); }
static String generateRustLiteral(final PrimitiveType type, final String value) { Verify.notNull(type, "type"); Verify.notNull(value, "value"); final String typeName = rustTypeName(type); if (typeName == null) { throw new IllegalArgumentException("Unknown Rust type name found for primitive " + type.primitiveName()); } switch (type) { case CHAR: case UINT8: case INT8: case INT16: case UINT16: case INT32: case INT64: case UINT32: case UINT64: return value + typeName; case FLOAT: case DOUBLE: return value.endsWith("NaN") ? typeName + "::NAN" : value + typeName; default: throw new IllegalArgumentException("Unsupported literal generation for type: " + type.primitiveName()); } }
else if (!isUnsigned(blockLengthType.primitiveType())) else if (!isUnsigned(numInGroupType.primitiveType())) numInGroupMaxValue.longValue() : numInGroupType.primitiveType().maxValue().longValue();
private static void validateGroupMaxValue( final Node node, final PrimitiveType primitiveType, final PrimitiveValue value) { if (null != value) { final long longValue = value.longValue(); final long allowedValue = primitiveType.maxValue().longValue(); if (longValue > allowedValue) { XmlSchemaParser.handleError(node, String.format( "maxValue greater than allowed for type: maxValue=%d allowed=%d", longValue, allowedValue)); } final long maxInt = INT32.maxValue().longValue(); if (primitiveType == UINT32 && longValue > maxInt) { XmlSchemaParser.handleError(node, String.format( "maxValue greater than allowed for type: maxValue=%d allowed=%d", longValue, maxInt)); } } else if (primitiveType == UINT32) { final long maxInt = INT32.maxValue().longValue(); XmlSchemaParser.handleError(node, String.format( "maxValue must be set for varData UINT32 type: max value allowed=%d", maxInt)); } }
/** * The most applicable min value for the encoded type. * * @return most applicable min value for the encoded type. */ public PrimitiveValue applicableMinValue() { if (null != minValue) { return minValue; } return primitiveType.minValue(); }
/** * The most applicable null value for the encoded type. * * @return most applicable null value for the encoded type. */ public PrimitiveValue applicableNullValue() { if (null != nullValue) { return nullValue; } return primitiveType.nullValue(); }
else if (!isUnsigned(blockLengthType.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 int fieldLength = token.arrayLength(); final int typeSize = token.encoding().primitiveType().size(); final String propName = toUpperFirstChar(propertyName);