@@ -108,8 +108,7 @@ private static String validateBufferImplementation(
108
108
}
109
109
catch (final ClassNotFoundException ex )
110
110
{
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 );
113
112
}
114
113
}
115
114
@@ -198,7 +197,7 @@ private void generateEncoder(
198
197
199
198
try (Writer out = outputManager .createOutput (className ))
200
199
{
201
- out .append (generateMainHeader (ir .applicableNamespace ()));
200
+ out .append (generateMainHeader (ir .applicableNamespace (), ENCODER , ! varData . isEmpty () ));
202
201
203
202
generateAnnotations (BASE_INDENT , className , groups , out , 0 , this ::encoderName );
204
203
out .append (generateDeclaration (className , implementsString , msgToken ));
@@ -225,7 +224,7 @@ private void generateDecoder(
225
224
226
225
try (Writer out = outputManager .createOutput (className ))
227
226
{
228
- out .append (generateMainHeader (ir .applicableNamespace ()));
227
+ out .append (generateMainHeader (ir .applicableNamespace (), DECODER , ! varData . isEmpty () ));
229
228
230
229
generateAnnotations (BASE_INDENT , className , groups , out , 0 , this ::decoderName );
231
230
out .append (generateDeclaration (className , implementsString , msgToken ));
@@ -1546,37 +1545,41 @@ private String interfaceImportLine()
1546
1545
private CharSequence generateFileHeader (final String packageName , final String fqBuffer )
1547
1546
{
1548
1547
return
1549
- "/* Generated SBE (Simple Binary Encoding) message codec */\n " +
1548
+ "/* Generated SBE (Simple Binary Encoding) message codec. */\n " +
1550
1549
"package " + packageName + ";\n \n " +
1551
1550
"import " + fqBuffer + ";\n " +
1552
1551
interfaceImportLine ();
1553
1552
}
1554
1553
1555
- private CharSequence generateMainHeader (final String packageName )
1554
+ private CharSequence generateMainHeader (
1555
+ final String packageName , final CodecType codecType , final boolean hasVarData )
1556
1556
{
1557
1557
if (fqMutableBuffer .equals (fqReadOnlyBuffer ))
1558
1558
{
1559
1559
return
1560
- "/* Generated SBE (Simple Binary Encoding) message codec */\n " +
1560
+ "/* Generated SBE (Simple Binary Encoding) message codec. */\n " +
1561
1561
"package " + packageName + ";\n \n " +
1562
1562
"import " + fqMutableBuffer + ";\n " +
1563
1563
interfaceImportLine ();
1564
1564
}
1565
1565
else
1566
1566
{
1567
+ final boolean hasMutableBuffer = ENCODER == codecType || hasVarData ;
1568
+ final boolean hasReadOnlyBuffer = DECODER == codecType || hasVarData ;
1569
+
1567
1570
return
1568
- "/* Generated SBE (Simple Binary Encoding) message codec */\n " +
1571
+ "/* Generated SBE (Simple Binary Encoding) message codec. */\n " +
1569
1572
"package " + packageName + ";\n \n " +
1570
- "import " + fqMutableBuffer + ";\n " +
1571
- "import " + fqReadOnlyBuffer + ";\n " +
1573
+ ( hasMutableBuffer ? "import " + fqMutableBuffer + ";\n " : "" ) +
1574
+ ( hasReadOnlyBuffer ? "import " + fqReadOnlyBuffer + ";\n " : "" ) +
1572
1575
interfaceImportLine ();
1573
1576
}
1574
1577
}
1575
1578
1576
1579
private static CharSequence generateEnumFileHeader (final String packageName )
1577
1580
{
1578
1581
return
1579
- "/* Generated SBE (Simple Binary Encoding) message codec */\n " +
1582
+ "/* Generated SBE (Simple Binary Encoding) message codec. */\n " +
1580
1583
"package " + packageName + ";\n \n " ;
1581
1584
}
1582
1585
@@ -3138,27 +3141,26 @@ private CharSequence generateCompositeEncoderDisplay(final String decoderName)
3138
3141
3139
3142
private CharSequence generateCompositeDecoderDisplay (final List <Token > tokens )
3140
3143
{
3141
- final String indent = INDENT ;
3142
3144
final StringBuilder sb = new StringBuilder ();
3143
3145
3144
- appendToString (sb , indent );
3146
+ appendToString (sb , INDENT );
3145
3147
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 , " }" );
3152
3154
sb .append ('\n' );
3153
- Separators .BEGIN_COMPOSITE .appendToGeneratedBuilder (sb , indent + INDENT , "builder" );
3155
+ Separators .BEGIN_COMPOSITE .appendToGeneratedBuilder (sb , INDENT + INDENT , "builder" );
3154
3156
3155
3157
int lengthBeforeLastGeneratedSeparator = -1 ;
3156
3158
3157
3159
for (int i = 1 , end = tokens .size () - 1 ; i < end ;)
3158
3160
{
3159
3161
final Token encodingToken = tokens .get (i );
3160
3162
final String propertyName = formatPropertyName (encodingToken .name ());
3161
- lengthBeforeLastGeneratedSeparator = writeTokenDisplay (propertyName , encodingToken , sb , indent + INDENT );
3163
+ lengthBeforeLastGeneratedSeparator = writeTokenDisplay (propertyName , encodingToken , sb , INDENT + INDENT );
3162
3164
i += encodingToken .componentTokenCount ();
3163
3165
}
3164
3166
@@ -3167,10 +3169,10 @@ private CharSequence generateCompositeDecoderDisplay(final List<Token> tokens)
3167
3169
sb .setLength (lengthBeforeLastGeneratedSeparator );
3168
3170
}
3169
3171
3170
- Separators .END_COMPOSITE .appendToGeneratedBuilder (sb , indent + INDENT , "builder" );
3172
+ Separators .END_COMPOSITE .appendToGeneratedBuilder (sb , INDENT + INDENT , "builder" );
3171
3173
sb .append ('\n' );
3172
- append (sb , indent , " return builder;" );
3173
- append (sb , indent , "}" );
3174
+ append (sb , INDENT , " return builder;" );
3175
+ append (sb , INDENT , "}" );
3174
3176
3175
3177
return sb ;
3176
3178
}
@@ -3219,45 +3221,44 @@ private void generateDecoderDisplay(
3219
3221
final List <Token > groups ,
3220
3222
final List <Token > varData )
3221
3223
{
3222
- final String indent = INDENT ;
3223
3224
final String decoderName = decoderName (name );
3224
3225
3225
- appendMessageToString (sb , indent , decoderName );
3226
+ appendMessageToString (sb , INDENT , decoderName );
3226
3227
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 , " }" );
3233
3234
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 );
3256
3257
sb .append ('\n' );
3257
- append (sb , indent , " limit(originalLimit);" );
3258
+ append (sb , INDENT , " limit(originalLimit);" );
3258
3259
sb .append ('\n' );
3259
- append (sb , indent , " return builder;" );
3260
- append (sb , indent , "}" );
3260
+ append (sb , INDENT , " return builder;" );
3261
+ append (sb , INDENT , "}" );
3261
3262
}
3262
3263
3263
3264
private void appendGroupInstanceDecoderDisplay (
0 commit comments