Skip to content

Commit 0385eb7

Browse files
Added semantic version as a static public member (#931)
* Added semantic version as a static public member accessible in the generated stubs. * Added generated java ir codecs. * Added constexpr in static c++ semanticVersion. * Fixing cpp codeGenTest. * Adjustments based on the pr comments. * Adjustments based on the pr comments.
1 parent 7186909 commit 0385eb7

16 files changed

+62
-9
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,7 @@ private CharSequence generateMessageFlyweightFunctions(
18941894
final String schemaVersionType = cTypeName(ir.headerStructure().schemaVersionType());
18951895
final String semanticType = token.encoding().semanticType() == null ? "" : token.encoding().semanticType();
18961896
final String messageHeaderStruct = formatScopedName(scope, "messageHeader");
1897+
final String semanticVersion = ir.semanticVersion() == null ? "" : ir.semanticVersion();
18971898

18981899
return String.format("\n" +
18991900
"SBE_ONE_DEF uint64_t %10$s_sbe_position(\n" +
@@ -1974,6 +1975,11 @@ private CharSequence generateMessageFlyweightFunctions(
19741975
" return %8$s;\n" +
19751976
"}\n\n" +
19761977

1978+
"SBE_ONE_DEF const char* %10$s_sbe_semantic_version(void)\n" +
1979+
"{\n" +
1980+
" return \"%12$s\";\n" +
1981+
"}\n\n" +
1982+
19771983
"SBE_ONE_DEF const char *%10$s_sbe_semantic_type(void)\n" +
19781984
"{\n" +
19791985
" return \"%9$s\";\n" +
@@ -2093,7 +2099,8 @@ private CharSequence generateMessageFlyweightFunctions(
20932099
generateLiteral(ir.headerStructure().schemaVersionType(), Integer.toString(ir.version())),
20942100
semanticType,
20952101
structName,
2096-
messageHeaderStruct);
2102+
messageHeaderStruct,
2103+
semanticVersion);
20972104
}
20982105

20992106
private CharSequence generateFieldFunctions(

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public void generate() throws IOException
169169
generateDisplay(sb, msgToken.name(), fields, groups, varData);
170170
sb.append(generateMessageLength(groups, varData, BASE_INDENT));
171171
sb.append("};\n");
172+
sb.append(generateStaticVariablesInitialization(className));
172173
sb.append(CppUtil.closingBraces(ir.namespaces().length)).append("#endif\n");
173174
out.append(sb);
174175
}
@@ -1973,6 +1974,7 @@ private CharSequence generateMessageFlyweightCode(final String className, final
19731974
final String schemaVersionType = cppTypeName(ir.headerStructure().schemaVersionType());
19741975
final String semanticType = token.encoding().semanticType() == null ? "" : token.encoding().semanticType();
19751976
final String headerType = ir.headerStructure().tokens().get(0).name();
1977+
final String semanticVersion = ir.semanticVersion() == null ? "" : ir.semanticVersion();
19761978

19771979
return String.format(
19781980
"private:\n" +
@@ -1992,7 +1994,8 @@ private CharSequence generateMessageFlyweightCode(final String className, final
19921994
" static const %1$s SBE_BLOCK_LENGTH = %2$s;\n" +
19931995
" static const %3$s SBE_TEMPLATE_ID = %4$s;\n" +
19941996
" static const %5$s SBE_SCHEMA_ID = %6$s;\n" +
1995-
" static const %7$s SBE_SCHEMA_VERSION = %8$s;\n\n" +
1997+
" static const %7$s SBE_SCHEMA_VERSION = %8$s;\n" +
1998+
" static const char* SBE_SEMANTIC_VERSION;\n\n" +
19961999

19972000
" enum MetaAttribute\n" +
19982001
" {\n" +
@@ -2039,6 +2042,11 @@ private CharSequence generateMessageFlyweightCode(final String className, final
20392042
" return %8$s;\n" +
20402043
" }\n\n" +
20412044

2045+
" SBE_NODISCARD static const char *sbeSemanticVersion() SBE_NOEXCEPT\n" +
2046+
" {\n" +
2047+
" return \"%13$s\";\n" +
2048+
" }\n\n" +
2049+
20422050
" SBE_NODISCARD static SBE_CONSTEXPR const char *sbeSemanticType() SBE_NOEXCEPT\n" +
20432051
" {\n" +
20442052
" return \"%9$s\";\n" +
@@ -2151,7 +2159,8 @@ private CharSequence generateMessageFlyweightCode(final String className, final
21512159
semanticType,
21522160
className,
21532161
generateConstructorsAndOperators(className),
2154-
formatClassName(headerType));
2162+
formatClassName(headerType),
2163+
semanticVersion);
21552164
}
21562165

21572166
private void generateFields(
@@ -3184,4 +3193,15 @@ private CharSequence generateMessageLength(final List<Token> groups, final List<
31843193

31853194
return sb;
31863195
}
3196+
3197+
private CharSequence generateStaticVariablesInitialization(final String className)
3198+
{
3199+
final String semanticVersion = ir.semanticVersion() == null ? "" : ir.semanticVersion();
3200+
3201+
return String.format(
3202+
"\n" +
3203+
"const char* %1$s::SBE_SEMANTIC_VERSION = \"%2$s\";\n\n",
3204+
className,
3205+
semanticVersion);
3206+
}
31873207
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,13 +1163,15 @@ private CharSequence generateMessageFlyweightCode(final String className, final
11631163
final String schemaIdType = cSharpTypeName(ir.headerStructure().schemaIdType());
11641164
final String schemaVersionType = cSharpTypeName(ir.headerStructure().schemaVersionType());
11651165
final String semanticType = token.encoding().semanticType() == null ? "" : token.encoding().semanticType();
1166+
final String semanticVersion = ir.semanticVersion() == null ? "" : ir.semanticVersion();
11661167

11671168
return String.format(
11681169
indent + INDENT + "public const %1$s BlockLength = %2$s;\n" +
11691170
indent + INDENT + "public const %3$s TemplateId = %4$s;\n" +
11701171
indent + INDENT + "public const %5$s SchemaId = %6$s;\n" +
11711172
indent + INDENT + "public const %7$s SchemaVersion = %8$s;\n" +
1172-
indent + INDENT + "public const string SemanticType = \"%9$s\";\n\n" +
1173+
indent + INDENT + "public const string SemanticType = \"%9$s\";\n" +
1174+
indent + INDENT + "public const string SemanticVersion = \"%11$s\";\n\n" +
11731175
indent + INDENT + "private readonly %10$s _parentMessage;\n" +
11741176
indent + INDENT + "private DirectBuffer _buffer;\n" +
11751177
indent + INDENT + "private int _offset;\n" +
@@ -1238,7 +1240,8 @@ private CharSequence generateMessageFlyweightCode(final String className, final
12381240
schemaVersionType,
12391241
generateLiteral(ir.headerStructure().schemaVersionType(), Integer.toString(ir.version())),
12401242
semanticType,
1241-
className);
1243+
className,
1244+
semanticVersion);
12421245
}
12431246

12441247
private CharSequence generateFields(final List<Token> tokens, final String indent)

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,7 @@ private void generateMessageCode(
20992099
final String templateIdType = golangTypeName(ir.headerStructure().templateIdType());
21002100
final String schemaIdType = golangTypeName(ir.headerStructure().schemaIdType());
21012101
final String schemaVersionType = golangTypeName(ir.headerStructure().schemaVersionType());
2102+
final String semanticVersion = ir.semanticVersion() == null ? "" : ir.semanticVersion();
21022103

21032104
generateEncodeDecode(sb, typeName, tokens, true, true);
21042105

@@ -2117,6 +2118,9 @@ private void generateMessageCode(
21172118
"}\n" +
21182119
"\nfunc (*%1$s) SbeSemanticType() (semanticType []byte) {\n" +
21192120
"\treturn []byte(\"%10$s\")\n" +
2121+
"}\n" +
2122+
"\nfunc (*%1$s) SbeSemanticVersion() (semanticVersion string) {\n" +
2123+
"\treturn \"%11$s\"\n" +
21202124
"}\n",
21212125
typeName,
21222126
blockLengthType,
@@ -2127,7 +2131,8 @@ private void generateMessageCode(
21272131
generateLiteral(ir.headerStructure().schemaIdType(), Integer.toString(ir.id())),
21282132
schemaVersionType,
21292133
generateLiteral(ir.headerStructure().schemaVersionType(), Integer.toString(ir.version())),
2130-
semanticType));
2134+
semanticType,
2135+
semanticVersion));
21312136
}
21322137

21332138
// Used for groups which need to know the schema's definition

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,10 +2611,12 @@ private CharSequence generateFixedFlyweightCode(
26112611
final String schemaIdAccessorType = shouldGenerateInterfaces ? "int" : schemaIdType;
26122612
final String schemaVersionType = javaTypeName(ir.headerStructure().schemaVersionType());
26132613
final String schemaVersionAccessorType = shouldGenerateInterfaces ? "int" : schemaVersionType;
2614+
final String semanticVersion = ir.semanticVersion() == null ? "" : ir.semanticVersion();
26142615

26152616
return String.format(
26162617
" public static final %5$s SCHEMA_ID = %6$s;\n" +
26172618
" public static final %7$s SCHEMA_VERSION = %8$s;\n" +
2619+
" public static final String SEMANTIC_VERSION = \"%11$s\";\n" +
26182620
" public static final int ENCODED_LENGTH = %2$d;\n" +
26192621
" public static final java.nio.ByteOrder BYTE_ORDER = java.nio.ByteOrder.%4$s;\n\n" +
26202622
" private int offset;\n" +
@@ -2657,7 +2659,8 @@ private CharSequence generateFixedFlyweightCode(
26572659
schemaVersionType,
26582660
generateLiteral(ir.headerStructure().schemaVersionType(), Integer.toString(ir.version())),
26592661
schemaIdAccessorType,
2660-
schemaVersionAccessorType);
2662+
schemaVersionAccessorType,
2663+
semanticVersion);
26612664
}
26622665

26632666
private CharSequence generateDecoderFlyweightCode(final String className, final Token token)
@@ -2735,6 +2738,7 @@ private CharSequence generateFlyweightCode(
27352738
final String schemaVersionType = javaTypeName(headerStructure.schemaVersionType());
27362739
final String schemaVersionAccessorType = shouldGenerateInterfaces ? "int" : schemaVersionType;
27372740
final String semanticType = token.encoding().semanticType() == null ? "" : token.encoding().semanticType();
2741+
final String semanticVersion = ir.semanticVersion() == null ? "" : ir.semanticVersion();
27382742
final String actingFields = codecType == CodecType.ENCODER ?
27392743
"" :
27402744
" int actingBlockLength;\n" +
@@ -2745,6 +2749,7 @@ private CharSequence generateFlyweightCode(
27452749
" public static final %3$s TEMPLATE_ID = %4$s;\n" +
27462750
" public static final %5$s SCHEMA_ID = %6$s;\n" +
27472751
" public static final %7$s SCHEMA_VERSION = %8$s;\n" +
2752+
" public static final String SEMANTIC_VERSION = \"%19$s\";\n" +
27482753
" public static final java.nio.ByteOrder BYTE_ORDER = java.nio.ByteOrder.%14$s;\n\n" +
27492754
" private final %9$s parentMessage = this;\n" +
27502755
" private %11$s buffer;\n" +
@@ -2815,7 +2820,8 @@ private CharSequence generateFlyweightCode(
28152820
blockLengthAccessorType,
28162821
templateIdAccessorType,
28172822
schemaIdAccessorType,
2818-
schemaVersionAccessorType);
2823+
schemaVersionAccessorType,
2824+
semanticVersion);
28192825
}
28202826

28212827
private CharSequence generateEncoderFlyweightCode(final String className, final Token token)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,12 @@ public void generate() throws IOException
157157
final String templateIdType = rustTypeName(ir.headerStructure().templateIdType());
158158
final String schemaIdType = rustTypeName(ir.headerStructure().schemaIdType());
159159
final String schemaVersionType = schemaVersionType();
160+
final String semanticVersion = ir.semanticVersion() == null ? "" : ir.semanticVersion();
160161
indent(out, 0, "pub const SBE_BLOCK_LENGTH: %s = %d;\n", blockLengthType, msgToken.encodedLength());
161162
indent(out, 0, "pub const SBE_TEMPLATE_ID: %s = %d;\n", templateIdType, msgToken.id());
162163
indent(out, 0, "pub const SBE_SCHEMA_ID: %s = %d;\n", schemaIdType, ir.id());
163-
indent(out, 0, "pub const SBE_SCHEMA_VERSION: %s = %d;\n\n", schemaVersionType, ir.version());
164+
indent(out, 0, "pub const SBE_SCHEMA_VERSION: %s = %d;\n", schemaVersionType, ir.version());
165+
indent(out, 0, "pub const SBE_SEMANTIC_VERSION: &str = \"%s\";\n\n", semanticVersion);
164166

165167
MessageCoderDef.generateEncoder(ir, out, msgToken, fields, groups, varData);
166168
MessageCoderDef.generateDecoder(ir, out, msgToken, fields, groups, varData);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public final class FrameCodecDecoder
1515
public static final int TEMPLATE_ID = 1;
1616
public static final int SCHEMA_ID = 1;
1717
public static final int SCHEMA_VERSION = 0;
18+
public static final String SEMANTIC_VERSION = "";
1819
public static final java.nio.ByteOrder BYTE_ORDER = java.nio.ByteOrder.LITTLE_ENDIAN;
1920

2021
private final FrameCodecDecoder parentMessage = this;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public final class FrameCodecEncoder
1515
public static final int TEMPLATE_ID = 1;
1616
public static final int SCHEMA_ID = 1;
1717
public static final int SCHEMA_VERSION = 0;
18+
public static final String SEMANTIC_VERSION = "";
1819
public static final java.nio.ByteOrder BYTE_ORDER = java.nio.ByteOrder.LITTLE_ENDIAN;
1920

2021
private final FrameCodecEncoder parentMessage = this;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public final class MessageHeaderDecoder
1212
{
1313
public static final int SCHEMA_ID = 1;
1414
public static final int SCHEMA_VERSION = 0;
15+
public static final String SEMANTIC_VERSION = "";
1516
public static final int ENCODED_LENGTH = 8;
1617
public static final java.nio.ByteOrder BYTE_ORDER = java.nio.ByteOrder.LITTLE_ENDIAN;
1718

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public final class MessageHeaderEncoder
1212
{
1313
public static final int SCHEMA_ID = 1;
1414
public static final int SCHEMA_VERSION = 0;
15+
public static final String SEMANTIC_VERSION = "";
1516
public static final int ENCODED_LENGTH = 8;
1617
public static final java.nio.ByteOrder BYTE_ORDER = java.nio.ByteOrder.LITTLE_ENDIAN;
1718

0 commit comments

Comments
 (0)