@@ -108,8 +108,7 @@ private static String validateBufferImplementation(
108108 }
109109 catch (final ClassNotFoundException ex )
110110 {
111- throw new IllegalArgumentException (
112- "Unable to validate " + fullyQualifiedBufferImplementation + " because it can't be found" , ex );
111+ throw new IllegalArgumentException ("Unable to find " + fullyQualifiedBufferImplementation , ex );
113112 }
114113 }
115114
@@ -198,7 +197,7 @@ private void generateEncoder(
198197
199198 try (Writer out = outputManager .createOutput (className ))
200199 {
201- out .append (generateMainHeader (ir .applicableNamespace ()));
200+ out .append (generateMainHeader (ir .applicableNamespace (), ENCODER , ! varData . isEmpty () ));
202201
203202 generateAnnotations (BASE_INDENT , className , groups , out , 0 , this ::encoderName );
204203 out .append (generateDeclaration (className , implementsString , msgToken ));
@@ -225,7 +224,7 @@ private void generateDecoder(
225224
226225 try (Writer out = outputManager .createOutput (className ))
227226 {
228- out .append (generateMainHeader (ir .applicableNamespace ()));
227+ out .append (generateMainHeader (ir .applicableNamespace (), DECODER , ! varData . isEmpty () ));
229228
230229 generateAnnotations (BASE_INDENT , className , groups , out , 0 , this ::decoderName );
231230 out .append (generateDeclaration (className , implementsString , msgToken ));
@@ -1546,37 +1545,41 @@ private String interfaceImportLine()
15461545 private CharSequence generateFileHeader (final String packageName , final String fqBuffer )
15471546 {
15481547 return
1549- "/* Generated SBE (Simple Binary Encoding) message codec */\n " +
1548+ "/* Generated SBE (Simple Binary Encoding) message codec. */\n " +
15501549 "package " + packageName + ";\n \n " +
15511550 "import " + fqBuffer + ";\n " +
15521551 interfaceImportLine ();
15531552 }
15541553
1555- private CharSequence generateMainHeader (final String packageName )
1554+ private CharSequence generateMainHeader (
1555+ final String packageName , final CodecType codecType , final boolean hasVarData )
15561556 {
15571557 if (fqMutableBuffer .equals (fqReadOnlyBuffer ))
15581558 {
15591559 return
1560- "/* Generated SBE (Simple Binary Encoding) message codec */\n " +
1560+ "/* Generated SBE (Simple Binary Encoding) message codec. */\n " +
15611561 "package " + packageName + ";\n \n " +
15621562 "import " + fqMutableBuffer + ";\n " +
15631563 interfaceImportLine ();
15641564 }
15651565 else
15661566 {
1567+ final boolean hasMutableBuffer = ENCODER == codecType || hasVarData ;
1568+ final boolean hasReadOnlyBuffer = DECODER == codecType || hasVarData ;
1569+
15671570 return
1568- "/* Generated SBE (Simple Binary Encoding) message codec */\n " +
1571+ "/* Generated SBE (Simple Binary Encoding) message codec. */\n " +
15691572 "package " + packageName + ";\n \n " +
1570- "import " + fqMutableBuffer + ";\n " +
1571- "import " + fqReadOnlyBuffer + ";\n " +
1573+ ( hasMutableBuffer ? "import " + fqMutableBuffer + ";\n " : "" ) +
1574+ ( hasReadOnlyBuffer ? "import " + fqReadOnlyBuffer + ";\n " : "" ) +
15721575 interfaceImportLine ();
15731576 }
15741577 }
15751578
15761579 private static CharSequence generateEnumFileHeader (final String packageName )
15771580 {
15781581 return
1579- "/* Generated SBE (Simple Binary Encoding) message codec */\n " +
1582+ "/* Generated SBE (Simple Binary Encoding) message codec. */\n " +
15801583 "package " + packageName + ";\n \n " ;
15811584 }
15821585
@@ -3138,27 +3141,26 @@ private CharSequence generateCompositeEncoderDisplay(final String decoderName)
31383141
31393142 private CharSequence generateCompositeDecoderDisplay (final List <Token > tokens )
31403143 {
3141- final String indent = INDENT ;
31423144 final StringBuilder sb = new StringBuilder ();
31433145
3144- appendToString (sb , indent );
3146+ appendToString (sb , INDENT );
31453147 sb .append ('\n' );
3146- append (sb , indent , "public StringBuilder appendTo(final StringBuilder builder)" );
3147- append (sb , indent , "{" );
3148- append (sb , indent , " if (null == buffer)" );
3149- append (sb , indent , " {" );
3150- append (sb , indent , " return builder;" );
3151- append (sb , indent , " }" );
3148+ append (sb , INDENT , "public StringBuilder appendTo(final StringBuilder builder)" );
3149+ append (sb , INDENT , "{" );
3150+ append (sb , INDENT , " if (null == buffer)" );
3151+ append (sb , INDENT , " {" );
3152+ append (sb , INDENT , " return builder;" );
3153+ append (sb , INDENT , " }" );
31523154 sb .append ('\n' );
3153- Separators .BEGIN_COMPOSITE .appendToGeneratedBuilder (sb , indent + INDENT , "builder" );
3155+ Separators .BEGIN_COMPOSITE .appendToGeneratedBuilder (sb , INDENT + INDENT , "builder" );
31543156
31553157 int lengthBeforeLastGeneratedSeparator = -1 ;
31563158
31573159 for (int i = 1 , end = tokens .size () - 1 ; i < end ;)
31583160 {
31593161 final Token encodingToken = tokens .get (i );
31603162 final String propertyName = formatPropertyName (encodingToken .name ());
3161- lengthBeforeLastGeneratedSeparator = writeTokenDisplay (propertyName , encodingToken , sb , indent + INDENT );
3163+ lengthBeforeLastGeneratedSeparator = writeTokenDisplay (propertyName , encodingToken , sb , INDENT + INDENT );
31623164 i += encodingToken .componentTokenCount ();
31633165 }
31643166
@@ -3167,10 +3169,10 @@ private CharSequence generateCompositeDecoderDisplay(final List<Token> tokens)
31673169 sb .setLength (lengthBeforeLastGeneratedSeparator );
31683170 }
31693171
3170- Separators .END_COMPOSITE .appendToGeneratedBuilder (sb , indent + INDENT , "builder" );
3172+ Separators .END_COMPOSITE .appendToGeneratedBuilder (sb , INDENT + INDENT , "builder" );
31713173 sb .append ('\n' );
3172- append (sb , indent , " return builder;" );
3173- append (sb , indent , "}" );
3174+ append (sb , INDENT , " return builder;" );
3175+ append (sb , INDENT , "}" );
31743176
31753177 return sb ;
31763178 }
@@ -3219,45 +3221,44 @@ private void generateDecoderDisplay(
32193221 final List <Token > groups ,
32203222 final List <Token > varData )
32213223 {
3222- final String indent = INDENT ;
32233224 final String decoderName = decoderName (name );
32243225
3225- appendMessageToString (sb , indent , decoderName );
3226+ appendMessageToString (sb , INDENT , decoderName );
32263227 sb .append ('\n' );
3227- append (sb , indent , "public StringBuilder appendTo(final StringBuilder builder)" );
3228- append (sb , indent , "{" );
3229- append (sb , indent , " if (null == buffer)" );
3230- append (sb , indent , " {" );
3231- append (sb , indent , " return builder;" );
3232- append (sb , indent , " }" );
3228+ append (sb , INDENT , "public StringBuilder appendTo(final StringBuilder builder)" );
3229+ append (sb , INDENT , "{" );
3230+ append (sb , INDENT , " if (null == buffer)" );
3231+ append (sb , INDENT , " {" );
3232+ append (sb , INDENT , " return builder;" );
3233+ append (sb , INDENT , " }" );
32333234 sb .append ('\n' );
3234- append (sb , indent , " final int originalLimit = limit();" );
3235- append (sb , indent , " limit(initialOffset + actingBlockLength);" );
3236- append (sb , indent , " builder.append(\" [" + name + "](sbeTemplateId=\" );" );
3237- append (sb , indent , " builder.append(TEMPLATE_ID);" );
3238- append (sb , indent , " builder.append(\" |sbeSchemaId=\" );" );
3239- append (sb , indent , " builder.append(SCHEMA_ID);" );
3240- append (sb , indent , " builder.append(\" |sbeSchemaVersion=\" );" );
3241- append (sb , indent , " if (parentMessage.actingVersion != SCHEMA_VERSION)" );
3242- append (sb , indent , " {" );
3243- append (sb , indent , " builder.append(parentMessage.actingVersion);" );
3244- append (sb , indent , " builder.append('/');" );
3245- append (sb , indent , " }" );
3246- append (sb , indent , " builder.append(SCHEMA_VERSION);" );
3247- append (sb , indent , " builder.append(\" |sbeBlockLength=\" );" );
3248- append (sb , indent , " if (actingBlockLength != BLOCK_LENGTH)" );
3249- append (sb , indent , " {" );
3250- append (sb , indent , " builder.append(actingBlockLength);" );
3251- append (sb , indent , " builder.append('/');" );
3252- append (sb , indent , " }" );
3253- append (sb , indent , " builder.append(BLOCK_LENGTH);" );
3254- append (sb , indent , " builder.append(\" ):\" );" );
3255- appendDecoderDisplay (sb , tokens , groups , varData , indent + INDENT );
3235+ append (sb , INDENT , " final int originalLimit = limit();" );
3236+ append (sb , INDENT , " limit(initialOffset + actingBlockLength);" );
3237+ append (sb , INDENT , " builder.append(\" [" + name + "](sbeTemplateId=\" );" );
3238+ append (sb , INDENT , " builder.append(TEMPLATE_ID);" );
3239+ append (sb , INDENT , " builder.append(\" |sbeSchemaId=\" );" );
3240+ append (sb , INDENT , " builder.append(SCHEMA_ID);" );
3241+ append (sb , INDENT , " builder.append(\" |sbeSchemaVersion=\" );" );
3242+ append (sb , INDENT , " if (parentMessage.actingVersion != SCHEMA_VERSION)" );
3243+ append (sb , INDENT , " {" );
3244+ append (sb , INDENT , " builder.append(parentMessage.actingVersion);" );
3245+ append (sb , INDENT , " builder.append('/');" );
3246+ append (sb , INDENT , " }" );
3247+ append (sb , INDENT , " builder.append(SCHEMA_VERSION);" );
3248+ append (sb , INDENT , " builder.append(\" |sbeBlockLength=\" );" );
3249+ append (sb , INDENT , " if (actingBlockLength != BLOCK_LENGTH)" );
3250+ append (sb , INDENT , " {" );
3251+ append (sb , INDENT , " builder.append(actingBlockLength);" );
3252+ append (sb , INDENT , " builder.append('/');" );
3253+ append (sb , INDENT , " }" );
3254+ append (sb , INDENT , " builder.append(BLOCK_LENGTH);" );
3255+ append (sb , INDENT , " builder.append(\" ):\" );" );
3256+ appendDecoderDisplay (sb , tokens , groups , varData , INDENT + INDENT );
32563257 sb .append ('\n' );
3257- append (sb , indent , " limit(originalLimit);" );
3258+ append (sb , INDENT , " limit(originalLimit);" );
32583259 sb .append ('\n' );
3259- append (sb , indent , " return builder;" );
3260- append (sb , indent , "}" );
3260+ append (sb , INDENT , " return builder;" );
3261+ append (sb , INDENT , "}" );
32613262 }
32623263
32633264 private void appendGroupInstanceDecoderDisplay (
0 commit comments