Skip to content

Commit 80de667

Browse files
committed
[Java] Add schema id and version to fixed flyweights. Issue aeron-io#593.
1 parent daf6bc3 commit 80de667

File tree

5 files changed

+67
-32
lines changed

5 files changed

+67
-32
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ private void generateCompositeFlyweightHeader(
10891089
{
10901090
out.append(generateFileHeader(ir.applicableNamespace(), fqBuffer));
10911091
out.append(generateDeclaration(typeName, implementsString, token));
1092-
out.append(generateCompositeFlyweightCode(typeName, token.encodedLength(), buffer));
1092+
out.append(generateFixedFlyweightCode(typeName, token.encodedLength(), buffer));
10931093
}
10941094

10951095
private void generateEnum(final List<Token> tokens) throws IOException
@@ -2173,40 +2173,15 @@ private static CharSequence generateByteLiteralList(final byte[] bytes)
21732173
return values;
21742174
}
21752175

2176-
private static CharSequence generateFixedFlyweightCode(
2176+
private CharSequence generateFixedFlyweightCode(
21772177
final String className, final int size, final String bufferImplementation)
21782178
{
2179-
return String.format(
2180-
" public static final int ENCODED_LENGTH = %2$d;\n" +
2181-
" private %3$s buffer;\n" +
2182-
" private int offset;\n\n" +
2183-
" public %1$s wrap(final %3$s buffer, final int offset)\n" +
2184-
" {\n" +
2185-
" this.buffer = buffer;\n" +
2186-
" this.offset = offset;\n\n" +
2187-
" return this;\n" +
2188-
" }\n\n" +
2189-
" public %3$s buffer()\n" +
2190-
" {\n" +
2191-
" return buffer;\n" +
2192-
" }\n\n" +
2193-
" public int offset()\n" +
2194-
" {\n" +
2195-
" return offset;\n" +
2196-
" }\n\n" +
2197-
" public int encodedLength()\n" +
2198-
" {\n" +
2199-
" return ENCODED_LENGTH;\n" +
2200-
" }\n",
2201-
className,
2202-
size,
2203-
bufferImplementation);
2204-
}
2179+
final String schemaIdType = javaTypeName(ir.headerStructure().schemaIdType());
2180+
final String schemaVersionType = javaTypeName(ir.headerStructure().schemaVersionType());
22052181

2206-
private CharSequence generateCompositeFlyweightCode(
2207-
final String className, final int size, final String bufferImplementation)
2208-
{
22092182
return String.format(
2183+
" public static final %5$s SCHEMA_ID = %6$s;\n" +
2184+
" public static final %7$s SCHEMA_VERSION = %8$s;\n" +
22102185
" public static final int ENCODED_LENGTH = %2$d;\n" +
22112186
" public static final java.nio.ByteOrder BYTE_ORDER = java.nio.ByteOrder.%4$s;\n\n" +
22122187
" private int offset;\n" +
@@ -2228,11 +2203,23 @@ private CharSequence generateCompositeFlyweightCode(
22282203
" public int encodedLength()\n" +
22292204
" {\n" +
22302205
" return ENCODED_LENGTH;\n" +
2206+
" }\n\n" +
2207+
" public %5$s sbeSchemaId()\n" +
2208+
" {\n" +
2209+
" return SCHEMA_ID;\n" +
2210+
" }\n\n" +
2211+
" public %7$s sbeSchemaVersion()\n" +
2212+
" {\n" +
2213+
" return SCHEMA_VERSION;\n" +
22312214
" }\n",
22322215
className,
22332216
size,
22342217
bufferImplementation,
2235-
ir.byteOrder());
2218+
ir.byteOrder(),
2219+
schemaIdType,
2220+
generateLiteral(ir.headerStructure().schemaIdType(), Integer.toString(ir.id())),
2221+
schemaVersionType,
2222+
generateLiteral(ir.headerStructure().schemaVersionType(), Integer.toString(ir.version())));
22362223
}
22372224

22382225
private CharSequence generateDecoderFlyweightCode(final String className, final Token token)

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/MessageHeaderDecoder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
@SuppressWarnings("all")
1010
public class MessageHeaderDecoder
1111
{
12+
public static final int SCHEMA_ID = 1;
13+
public static final int SCHEMA_VERSION = 0;
1214
public static final int ENCODED_LENGTH = 8;
1315
public static final java.nio.ByteOrder BYTE_ORDER = java.nio.ByteOrder.LITTLE_ENDIAN;
1416

@@ -38,6 +40,16 @@ public int encodedLength()
3840
return ENCODED_LENGTH;
3941
}
4042

43+
public int sbeSchemaId()
44+
{
45+
return SCHEMA_ID;
46+
}
47+
48+
public int sbeSchemaVersion()
49+
{
50+
return SCHEMA_VERSION;
51+
}
52+
4153
public static int blockLengthEncodingOffset()
4254
{
4355
return 0;

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/MessageHeaderEncoder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
@SuppressWarnings("all")
1010
public class MessageHeaderEncoder
1111
{
12+
public static final int SCHEMA_ID = 1;
13+
public static final int SCHEMA_VERSION = 0;
1214
public static final int ENCODED_LENGTH = 8;
1315
public static final java.nio.ByteOrder BYTE_ORDER = java.nio.ByteOrder.LITTLE_ENDIAN;
1416

@@ -38,6 +40,16 @@ public int encodedLength()
3840
return ENCODED_LENGTH;
3941
}
4042

43+
public int sbeSchemaId()
44+
{
45+
return SCHEMA_ID;
46+
}
47+
48+
public int sbeSchemaVersion()
49+
{
50+
return SCHEMA_VERSION;
51+
}
52+
4153
public static int blockLengthEncodingOffset()
4254
{
4355
return 0;

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/VarDataEncodingDecoder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
@SuppressWarnings("all")
77
public class VarDataEncodingDecoder
88
{
9+
public static final int SCHEMA_ID = 1;
10+
public static final int SCHEMA_VERSION = 0;
911
public static final int ENCODED_LENGTH = -1;
1012
public static final java.nio.ByteOrder BYTE_ORDER = java.nio.ByteOrder.LITTLE_ENDIAN;
1113

@@ -35,6 +37,16 @@ public int encodedLength()
3537
return ENCODED_LENGTH;
3638
}
3739

40+
public int sbeSchemaId()
41+
{
42+
return SCHEMA_ID;
43+
}
44+
45+
public int sbeSchemaVersion()
46+
{
47+
return SCHEMA_VERSION;
48+
}
49+
3850
public static int lengthEncodingOffset()
3951
{
4052
return 0;

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/VarDataEncodingEncoder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
@SuppressWarnings("all")
77
public class VarDataEncodingEncoder
88
{
9+
public static final int SCHEMA_ID = 1;
10+
public static final int SCHEMA_VERSION = 0;
911
public static final int ENCODED_LENGTH = -1;
1012
public static final java.nio.ByteOrder BYTE_ORDER = java.nio.ByteOrder.LITTLE_ENDIAN;
1113

@@ -35,6 +37,16 @@ public int encodedLength()
3537
return ENCODED_LENGTH;
3638
}
3739

40+
public int sbeSchemaId()
41+
{
42+
return SCHEMA_ID;
43+
}
44+
45+
public int sbeSchemaVersion()
46+
{
47+
return SCHEMA_VERSION;
48+
}
49+
3850
public static int lengthEncodingOffset()
3951
{
4052
return 0;

0 commit comments

Comments
 (0)