Skip to content

Commit 5d33b22

Browse files
committed
[Rust] generate message schema level info in lib.rs
1. add `SBE_SCHEMA_ID` 2. add `SBE_SCHEMA_VERSION` 3. add `SBE_SEMANTIC_VERSION`
1 parent ae002c2 commit 5d33b22

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.ArrayList;
2424
import java.util.LinkedHashSet;
2525
import java.util.stream.Stream;
26+
import uk.co.real_logic.sbe.ir.Ir;
2627

2728
import static java.nio.ByteOrder.LITTLE_ENDIAN;
2829
import static uk.co.real_logic.sbe.generation.rust.RustGenerator.*;
@@ -54,7 +55,7 @@ class LibRsDef
5455
this.schemaVersionType = schemaVersionType;
5556
}
5657

57-
void generate() throws IOException
58+
void generate(final Ir ir) throws IOException
5859
{
5960
try (Writer libRs = outputManager.createOutput("lib"))
6061
{
@@ -84,6 +85,8 @@ void generate() throws IOException
8485
}
8586
indent(libRs, 0, "\n");
8687

88+
generateSbeSchemaConsts(libRs, ir);
89+
8790
generateSbeErrorEnum(libRs);
8891
generateEitherEnum(libRs);
8992

@@ -123,6 +126,17 @@ static void generateDecoderTraits(final String schemaVersionType, final Writer w
123126
indent(writer, 0, "}\n\n");
124127
}
125128

129+
static void generateSbeSchemaConsts(final Writer writer, final Ir ir) throws IOException
130+
{
131+
final String schemaIdType = rustTypeName(ir.headerStructure().schemaIdType());
132+
final String schemaVersionType = rustTypeName(ir.headerStructure().schemaVersionType());
133+
final String semanticVersion = ir.semanticVersion() == null ? "" : ir.semanticVersion();
134+
135+
indent(writer, 0, "pub const SBE_SCHEMA_ID: %s = %d;\n", schemaIdType, ir.id());
136+
indent(writer, 0, "pub const SBE_SCHEMA_VERSION: %s = %d;\n", schemaVersionType, ir.version());
137+
indent(writer, 0, "pub const SBE_SEMANTIC_VERSION: &str = \"%s\";\n\n", semanticVersion);
138+
}
139+
126140
static void generateSbeErrorEnum(final Writer writer) throws IOException
127141
{
128142
indent(writer, 0, "pub type SbeResult<T> = core::result::Result<T, SbeErr>;\n\n");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public void generate() throws IOException
175175
}
176176
}
177177

178-
libRsDef.generate();
178+
libRsDef.generate(ir);
179179
}
180180

181181
String blockLengthType()

0 commit comments

Comments
 (0)