Skip to content

Commit

Permalink
[Java] Add common methods to codec interfaces. Issue #593.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed Oct 29, 2018
1 parent 4a4edb3 commit 8542d80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ project(':sbe-samples') {
systemProperties(
'sbe.output.dir': 'build/generated',
'sbe.target.language': 'Java',
'sbe.java.generate.interfaces': 'false',
'sbe.java.generate.interfaces': 'true',
'sbe.validation.stop.on.error': 'true',
'sbe.validation.xsd': validationXsdPath)
args = ['src/main/resources/example-schema.xml',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ enum CodecType
private static final String META_ATTRIBUTE_ENUM = "MetaAttribute";
private static final String BASE_INDENT = "";
private static final String INDENT = " ";
private static final String GEN_COMPOSITE_DECODER_FLYWEIGHT = "CompositeDecoderFlyweight";
private static final String GEN_COMPOSITE_ENCODER_FLYWEIGHT = "CompositeEncoderFlyweight";
private static final String GEN_MESSAGE_DECODER_FLYWEIGHT = "MessageDecoderFlyweight";
private static final String GEN_MESSAGE_ENCODER_FLYWEIGHT = "MessageEncoderFlyweight";
private static final String FLYWEIGHT = "Flyweight";
private static final String COMPOSITE_DECODER_FLYWEIGHT = "CompositeDecoderFlyweight";
private static final String COMPOSITE_ENCODER_FLYWEIGHT = "CompositeEncoderFlyweight";
private static final String MESSAGE_DECODER_FLYWEIGHT = "MessageDecoderFlyweight";
private static final String MESSAGE_ENCODER_FLYWEIGHT = "MessageEncoderFlyweight";

private final Ir ir;
private final OutputManager outputManager;
Expand Down Expand Up @@ -194,7 +195,7 @@ private void generateEncoder(
final Token msgToken) throws IOException
{
final String className = formatClassName(encoderName(msgToken.name()));
final String implementsString = implementsInterface(GEN_MESSAGE_ENCODER_FLYWEIGHT);
final String implementsString = implementsInterface(MESSAGE_ENCODER_FLYWEIGHT);

try (Writer out = outputManager.createOutput(className))
{
Expand Down Expand Up @@ -225,7 +226,7 @@ private void generateDecoder(
final Token msgToken) throws IOException
{
final String className = formatClassName(decoderName(msgToken.name()));
final String implementsString = implementsInterface(GEN_MESSAGE_DECODER_FLYWEIGHT);
final String implementsString = implementsInterface(MESSAGE_DECODER_FLYWEIGHT);

try (Writer out = outputManager.createOutput(className))
{
Expand Down Expand Up @@ -1076,10 +1077,11 @@ private void generateBitSet(final List<Token> tokens) throws IOException
final String decoderName = decoderName(bitSetName);
final String encoderName = encoderName(bitSetName);
final List<Token> messageBody = getMessageBody(tokens);
final String implementsString = implementsInterface(FLYWEIGHT);

try (Writer out = outputManager.createOutput(decoderName))
{
generateFixedFlyweightHeader(token, decoderName, out, readOnlyBuffer, fqReadOnlyBuffer);
generateFixedFlyweightHeader(token, decoderName, implementsString, out, readOnlyBuffer, fqReadOnlyBuffer);
out.append(generateChoiceIsEmpty(token.encoding().primitiveType()));
out.append(generateChoiceDecoders(messageBody));
out.append(generateChoiceDisplay(messageBody));
Expand All @@ -1088,7 +1090,7 @@ private void generateBitSet(final List<Token> tokens) throws IOException

try (Writer out = outputManager.createOutput(encoderName))
{
generateFixedFlyweightHeader(token, encoderName, out, mutableBuffer, fqMutableBuffer);
generateFixedFlyweightHeader(token, encoderName, implementsString, out, mutableBuffer, fqMutableBuffer);
out.append(generateChoiceClear(encoderName, token));
out.append(generateChoiceEncoders(encoderName, messageBody));
out.append("}\n");
Expand All @@ -1098,12 +1100,13 @@ private void generateBitSet(final List<Token> tokens) throws IOException
private void generateFixedFlyweightHeader(
final Token token,
final String typeName,
final String implementsString,
final Writer out,
final String buffer,
final String fqBuffer) throws IOException
{
out.append(generateFileHeader(ir.applicableNamespace(), fqBuffer));
out.append(generateDeclaration(typeName, "", token));
out.append(generateDeclaration(typeName, implementsString, token));
out.append(generateFixedFlyweightCode(typeName, token.encodedLength(), buffer));
}

Expand Down Expand Up @@ -1148,7 +1151,7 @@ private void generateComposite(final List<Token> tokens) throws IOException

try (Writer out = outputManager.createOutput(decoderName))
{
final String implementsString = implementsInterface(GEN_COMPOSITE_DECODER_FLYWEIGHT);
final String implementsString = implementsInterface(COMPOSITE_DECODER_FLYWEIGHT);
generateCompositeFlyweightHeader(
token, decoderName, out, readOnlyBuffer, fqReadOnlyBuffer, implementsString);

Expand Down Expand Up @@ -1196,7 +1199,7 @@ private void generateComposite(final List<Token> tokens) throws IOException

try (Writer out = outputManager.createOutput(encoderName))
{
final String implementsString = implementsInterface(GEN_COMPOSITE_ENCODER_FLYWEIGHT);
final String implementsString = implementsInterface(COMPOSITE_ENCODER_FLYWEIGHT);
generateCompositeFlyweightHeader(token, encoderName, out, mutableBuffer, fqMutableBuffer, implementsString);

for (int i = 1, end = tokens.size() - 1; i < end;)
Expand Down

0 comments on commit 8542d80

Please sign in to comment.