private static void generateEntryPoint( final String messageTypeName, final OutputManager outputManager, final String topType, final RustCodecType codecType) throws IOException { try (Writer writer = outputManager.createOutput(messageTypeName + format(" %s entry point", codecType.name()))) { final String gerund = codecType.gerund(); writer.append(format("pub fn start_%s_%s<%s>(data: &%s%s [u8]) -> %s {\n", gerund, formatMethodName(messageTypeName), DATA_LIFETIME, DATA_LIFETIME, codecType == RustCodecType.Encoder ? " mut" : "", withLifetime(topType))); indent(writer, 1, "%s::wrap(%s { data: data, pos: 0 })\n", topType, codecType.scratchType()); writer.append("}\n"); } }
private static String generateFixedFieldCoder( final String messageTypeName, final OutputManager outputManager, final String topType, final Optional<FieldsRepresentationSummary> fieldsRepresentationOptional, final RustCodecType codecType) throws IOException { if (!fieldsRepresentationOptional.isPresent()) { return topType; } final FieldsRepresentationSummary fieldsRepresentation = fieldsRepresentationOptional.get(); try (Writer writer = outputManager.createOutput(messageTypeName + " Fixed fields " + codecType.name())) { final String representationStruct = fieldsRepresentation.typeName; final String decoderName = representationStruct + codecType.name(); codecType.appendScratchWrappingStruct(writer, decoderName); appendImplWithLifetimeHeader(writer, decoderName); codecType.appendWrapMethod(writer, decoderName); codecType.appendDirectCodeMethods(writer, formatMethodName(messageTypeName) + "_fields", representationStruct, topType, fieldsRepresentation.numBytes); writer.append("}\n"); // TODO - Move read position further if in-message blockLength exceeds fixed fields representation size // will require piping some data from the previously-read message header return decoderName; } }
String generateMessageHeaderCoder( final String messageTypeName, final OutputManager outputManager, final String topType, final int headerSize) throws IOException { final String messageHeaderRepresentation = "MessageHeader"; final String headerCoderType = messageTypeName + messageHeaderRepresentation + name(); try (Writer writer = outputManager.createOutput(headerCoderType)) { appendScratchWrappingStruct(writer, headerCoderType); RustGenerator.appendImplWithLifetimeHeader(writer, headerCoderType); appendWrapMethod(writer, headerCoderType); appendDirectCodeMethods(writer, "header", messageHeaderRepresentation, topType, headerSize); writer.append("}\n"); } return headerCoderType; } }
final String memberCoderType = node.contextualName + "Member" + codecType.name(); String nextCoderType = memberCoderType;
String generateDoneCoderType( final OutputManager outputManager, final String messageTypeName) throws IOException { final String doneTypeName = messageTypeName + name() + "Done"; try (Writer writer = outputManager.createOutput(doneTypeName)) { appendScratchWrappingStruct(writer, doneTypeName); RustGenerator.appendImplWithLifetimeHeader(writer, doneTypeName); indent(writer, 1, "/// Returns the number of bytes %s\n", this == Encoder ? "encoded" : "decoded"); indent(writer, 1, "pub fn unwrap(self) -> usize {\n"); indent(writer, 2, "self.%s.pos\n", scratchProperty()); indent(writer, 1, "}\n"); appendWrapMethod(writer, doneTypeName); writer.append("}\n"); } return doneTypeName; }
final String decoderType = parentContextualName + formatTypeName(name) + codecType.name(); try (Writer writer = outputManager.createOutput(name + " variable-length data"))
private static void generateEntryPoint( final String messageTypeName, final OutputManager outputManager, final String topType, final RustCodecType codecType) throws IOException { try (Writer writer = outputManager.createOutput(messageTypeName + format(" %s entry point", codecType.name()))) { final String gerund = codecType.gerund(); writer.append(format("pub fn start_%s_%s<%s>(data: &%s%s [u8]) -> %s {\n", gerund, formatMethodName(messageTypeName), DATA_LIFETIME, DATA_LIFETIME, codecType == RustCodecType.Encoder ? " mut" : "", withLifetime(topType))); indent(writer, 1, "%s::wrap(%s { data: data, pos: 0 })\n", topType, codecType.scratchType()); writer.append("}\n"); } }
private static void generateEntryPoint( final String messageTypeName, final OutputManager outputManager, final String topType, final RustCodecType codecType) throws IOException { try (Writer writer = outputManager.createOutput(messageTypeName + format(" %s entry point", codecType.name()))) { final String gerund = codecType.gerund(); writer.append(format("pub fn start_%s_%s<%s>(data: &%s%s [u8]) -> %s {\n", gerund, formatMethodName(messageTypeName), DATA_LIFETIME, DATA_LIFETIME, codecType == RustCodecType.Encoder ? " mut" : "", withLifetime(topType))); indent(writer, 1, "%s::wrap(%s { data: data, pos: 0 })\n", topType, codecType.scratchType()); writer.append("}\n"); } }
private static String generateFixedFieldCoder( final String messageTypeName, final OutputManager outputManager, final String topType, final Optional<FieldsRepresentationSummary> fieldsRepresentationOptional, final RustCodecType codecType) throws IOException { if (!fieldsRepresentationOptional.isPresent()) { return topType; } final FieldsRepresentationSummary fieldsRepresentation = fieldsRepresentationOptional.get(); try (Writer writer = outputManager.createOutput(messageTypeName + " Fixed fields " + codecType.name())) { final String representationStruct = fieldsRepresentation.typeName; final String decoderName = representationStruct + codecType.name(); codecType.appendScratchWrappingStruct(writer, decoderName); appendImplWithLifetimeHeader(writer, decoderName); codecType.appendWrapMethod(writer, decoderName); codecType.appendDirectCodeMethods(writer, formatMethodName(messageTypeName) + "_fields", representationStruct, topType, fieldsRepresentation.numBytes); writer.append("}\n"); // TODO - Move read position further if in-message blockLength exceeds fixed fields representation size // will require piping some data from the previously-read message header return decoderName; } }
private static String generateFixedFieldCoder( final String messageTypeName, final OutputManager outputManager, final String topType, final Optional<FieldsRepresentationSummary> fieldsRepresentationOptional, final RustCodecType codecType) throws IOException { if (!fieldsRepresentationOptional.isPresent()) { return topType; } final FieldsRepresentationSummary fieldsRepresentation = fieldsRepresentationOptional.get(); try (Writer writer = outputManager.createOutput(messageTypeName + " Fixed fields " + codecType.name())) { final String representationStruct = fieldsRepresentation.typeName; final String decoderName = representationStruct + codecType.name(); codecType.appendScratchWrappingStruct(writer, decoderName); appendImplWithLifetimeHeader(writer, decoderName); codecType.appendWrapMethod(writer, decoderName); codecType.appendDirectCodeMethods(writer, formatMethodName(messageTypeName) + "_fields", representationStruct, topType, fieldsRepresentation.numBytes); writer.append("}\n"); // TODO - Move read position further if in-message blockLength exceeds fixed fields representation size // will require piping some data from the previously-read message header return decoderName; } }
String generateMessageHeaderCoder( final String messageTypeName, final OutputManager outputManager, final String topType, final int headerSize) throws IOException { final String messageHeaderRepresentation = "MessageHeader"; final String headerCoderType = messageTypeName + messageHeaderRepresentation + name(); try (Writer writer = outputManager.createOutput(headerCoderType)) { appendScratchWrappingStruct(writer, headerCoderType); RustGenerator.appendImplWithLifetimeHeader(writer, headerCoderType); appendWrapMethod(writer, headerCoderType); appendDirectCodeMethods(writer, "header", messageHeaderRepresentation, topType, headerSize); writer.append("}\n"); } return headerCoderType; } }
String generateMessageHeaderCoder( final String messageTypeName, final OutputManager outputManager, final String topType, final int headerSize) throws IOException { final String messageHeaderRepresentation = "MessageHeader"; final String headerCoderType = messageTypeName + messageHeaderRepresentation + name(); try (Writer writer = outputManager.createOutput(headerCoderType)) { appendScratchWrappingStruct(writer, headerCoderType); RustGenerator.appendImplWithLifetimeHeader(writer, headerCoderType); appendWrapMethod(writer, headerCoderType); appendDirectCodeMethods(writer, "header", messageHeaderRepresentation, topType, headerSize); writer.append("}\n"); } return headerCoderType; } }
final String memberCoderType = node.contextualName + "Member" + codecType.name(); String nextCoderType = memberCoderType;
final String memberCoderType = node.contextualName + "Member" + codecType.name(); String nextCoderType = memberCoderType;
String generateDoneCoderType( final OutputManager outputManager, final String messageTypeName) throws IOException { final String doneTypeName = messageTypeName + name() + "Done"; try (Writer writer = outputManager.createOutput(doneTypeName)) { appendScratchWrappingStruct(writer, doneTypeName); RustGenerator.appendImplWithLifetimeHeader(writer, doneTypeName); indent(writer, 1, "/// Returns the number of bytes %s\n", this == Encoder ? "encoded" : "decoded"); indent(writer, 1, "pub fn unwrap(self) -> usize {\n"); indent(writer, 2, "self.%s.pos\n", scratchProperty()); indent(writer, 1, "}\n"); appendWrapMethod(writer, doneTypeName); writer.append("}\n"); } return doneTypeName; }
String generateDoneCoderType( final OutputManager outputManager, final String messageTypeName) throws IOException { final String doneTypeName = messageTypeName + name() + "Done"; try (Writer writer = outputManager.createOutput(doneTypeName)) { appendScratchWrappingStruct(writer, doneTypeName); RustGenerator.appendImplWithLifetimeHeader(writer, doneTypeName); indent(writer, 1, "/// Returns the number of bytes %s\n", this == Encoder ? "encoded" : "decoded"); indent(writer, 1, "pub fn unwrap(self) -> usize {\n"); indent(writer, 2, "self.%s.pos\n", scratchProperty()); indent(writer, 1, "}\n"); appendWrapMethod(writer, doneTypeName); writer.append("}\n"); } return doneTypeName; }
final String decoderType = parentContextualName + formatTypeName(name) + codecType.name(); try (Writer writer = outputManager.createOutput(name + " variable-length data"))
final String decoderType = parentContextualName + formatTypeName(name) + codecType.name(); try (Writer writer = outputManager.createOutput(name + " variable-length data"))