/** * The encodedLength (in octets) of the encodingType * * @return encodedLength of the encodingType */ public int encodedLength() { return encodingType.size(); }
/** * 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 ""; } }
/** * Return the Golang 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 "binary.Write(buf, order, obj)"; case 4: return "binary.Write(buf, order, obj)"; case 8: return "binary.Write(buf, order, obj)"; default: return ""; } }
/** * The encodedLength (in octets) of the encodingType * * @return encodedLength of the encodingType */ public int encodedLength() { if (presence() == Presence.CONSTANT) { return 0; } return encodingType.size(); }
private static int sizeOfPrimitive(final Encoding encoding) { return encoding.primitiveType().size(); }
/** * The encodedLength (in octets) of the encoding as length of the primitiveType times its count. * * @return encodedLength of the encoding */ public int encodedLength() { if (presence() == CONSTANT) { return 0; } if (varLen) { return Token.VARIABLE_LENGTH; } return primitiveType.size() * length; }
/** * The number of encoded primitives in this type. * * @return number of encoded primitives in this type. */ public int arrayLength() { if (null == encoding.primitiveType() || 0 == encodedLength) { return 0; } return encodedLength / encoding.primitiveType().size(); }
private static Object generateBitsetProperty(final String propertyName, final Token token, final String indent) { final StringBuilder sb = new StringBuilder(); final String bitsetName = formatClassName(token.applicableTypeName()); final int offset = token.offset(); sb.append(String.format("\n" + indent + "private:\n" + indent + " %1$s m_%2$s;\n\n" + indent + "public:\n", bitsetName, propertyName)); sb.append(String.format("\n" + indent + " %1$s &%2$s()\n" + indent + " {\n" + indent + " m_%2$s.wrap(m_buffer, m_offset + %3$d, m_actingVersion, m_bufferLength);\n" + indent + " return m_%2$s;\n" + indent + " }\n", bitsetName, propertyName, offset)); sb.append(String.format("\n" + indent + " static SBE_CONSTEXPR std::size_t %1$sEncodingLength() SBE_NOEXCEPT\n" + indent + " {\n" + indent + " return %2$d;\n" + indent + " }\n", propertyName, token.encoding().primitiveType().size())); return sb; }
/** * Construct a Choice given the XML node and the encodingType * * @param node that contains the validValue * @param encodingType for the enum */ public Choice(final Node node, final PrimitiveType encodingType) { name = getAttributeValue(node, "name"); description = getAttributeValueOrNull(node, "description"); value = PrimitiveValue.parse(node.getFirstChild().getNodeValue(), encodingType); sinceVersion = Integer.parseInt(getAttributeValue(node, "sinceVersion", "0")); deprecated = Integer.parseInt(getAttributeValue(node, "deprecated", "0")); // choice values are bit positions (0, 1, 2, 3, 4, etc.) from LSB to MSB if (value.longValue() >= (encodingType.size() * 8)) { throw new IllegalArgumentException("Choice value out of bounds: " + value.longValue()); } checkForValidName(node, name); }
final int elementSize = encoding.primitiveType().size();
private static void appendFixedSizeMemberGroupDecoderMethods( final String initialNextDecoderType, final GroupTreeNode node, final boolean atEndOfParent, final Writer out, final String contentProperty) throws IOException { indent(out, 1, "pub fn %s_as_slice(mut self) -> CodecResult<(&%s [%s], %s)> {\n", formatMethodName(node.originalName), DATA_LIFETIME, node.contextualName + "Member", initialNextDecoderType.startsWith("Either") ? initialNextDecoderType : withLifetime(initialNextDecoderType)); indent(out, 2, "%s.skip_bytes(%s)?; // Skip reading block length for now\n", toScratchChain(node), node.blockLengthType.size()); indent(out, 2, "let count = *%s.read_type::<%s>(%s)?;\n", toScratchChain(node), rustTypeName(node.numInGroupType), node.numInGroupType.size()); indent(out, 2, "let s = %s.read_slice::<%s>(count as usize, %s)?;\n", toScratchChain(node), node.contextualName + "Member", node.blockLength); indent(out, 2, "Ok((s,%s))\n", atEndOfParent ? "self.parent.after_member()" : format("%s::wrap(self.%s)", initialNextDecoderType, contentProperty)); indent(out, 1, "}\n"); }
indent + " }\n", propertyName, token.encoding().primitiveType().size() * token.arrayLength()));
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, 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);
atEndOfGroup ? nextDecoderType : withLifetime(nextDecoderType)); indent(writer, 2, "let count = *%s.read_type::<%s>(%s)?;\n", toScratchChain(groupDepth), rustTypeName(this.lengthType), this.lengthType.size()); rustTypeName(this.dataType), this.dataType.size(), goToNext); indent(writer).append("}\n");
indent(writer, 2, "%s.write_type::<%s>(&(l as %s), %s)?; // group length\n", toScratchChain(groupDepth), rustTypeName(this.lengthType), rustTypeName(this.lengthType), this.lengthType.size()); indent(writer, 2).append(format("%s.write_slice_without_count::<%s>(s, %s)?;\n", toScratchChain(groupDepth), rustTypeName(this.dataType), this.dataType.size())); indent(writer, 2, "Ok(%s)\n", atEndOfGroup ? "self.parent" : format("%s::wrap(self.%s)", nextCoderType, contentPropertyName));
final int elementSize = encoding.primitiveType().size();
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()); return 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); }
private void add(final SetType type, final int offset, final Field field) { final PrimitiveType encodingType = type.encodingType(); final Encoding encoding = new Encoding.Builder() .semanticType(semanticTypeOf(type, field)) .primitiveType(encodingType) .build(); final Token.Builder builder = new Token.Builder() .signal(Signal.BEGIN_SET) .name(type.name()) .referencedName(type.referencedName()) .size(encodingType.size()) .offset(offset) .version(type.sinceVersion()) .deprecated(type.deprecated()) .description(type.description()) .encoding(encoding); if (null != field) { builder.version(Math.max(field.sinceVersion(), type.sinceVersion())); } tokenList.add(builder.build()); for (final SetType.Choice choice : type.choices()) { add(choice, encodingType); } builder.signal(Signal.END_SET); tokenList.add(builder.build()); }
private String generateBitSetProperty(final String propertyName, final Token token, final String indent) { final String bitSetName = formatClassName(token.applicableTypeName()); final int offset = token.offset(); final String typePrefix = toUpperFirstChar(token.encoding().primitiveType().primitiveName()); final ByteOrder byteOrder = token.encoding().byteOrder(); final String byteOrderStr = generateByteOrder(byteOrder, token.encoding().primitiveType().size()); final String typeName = cSharpTypeName(token.encoding().primitiveType()); return 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", bitSetName, toUpperFirstChar(propertyName), generateTypeFieldNotPresentCondition(token.version(), indent), bitSetName, typePrefix, offset, byteOrderStr, typeName); }
.name(type.name()) .referencedName(type.referencedName()) .size(encodingType.size()) .offset(offset) .version(type.sinceVersion())