real-logic / simple-binary-encoding

Simple Binary Encoding (SBE) - High Performance Message Codec
Apache License 2.0
3.12k stars 523 forks source link

[Rust] add messageSchema level info (SBE_SCHEMA_ID/SBE_SCHEMA_VERSION and more) in lib.rs #1018

Closed wbprime closed 1 week ago

wbprime commented 3 weeks ago

There currently generate following const items in message codec files:

pub const SBE_BLOCK_LENGTH: u16 = 26;
pub const SBE_TEMPLATE_ID: u16 = 400;
pub const SBE_SCHEMA_ID: u16 = 10;
pub const SBE_SCHEMA_VERSION: u16 = 1;
pub const SBE_SEMANTIC_VERSION: &str = "1.0.0";

Actually SBE_SCHEMA_ID and SBE_SCHEMA_VERSION and SBE_SEMANTIC_VERSION were crate level info, and might also be placed in lib.rs.

pub const SBE_SCHEMA_ID: u16 = 10;
pub const SBE_SCHEMA_VERSION: u16 = 1;
pub const SBE_SEMANTIC_VERSION: &str = "1.0.0";

A typical usecase for this is that when using multi sbe generated crates in a single bin crate to decode bytes. Each sbe crate may contain multi message types. So a general pattern to decode bytes was:

let frame_container = ...;
let msg_schema = frame_container.message_schema();
match msg_schema {
crate_a::SBE_SCHEMA_ID => {
    // use crate_a specific ReadBuf and HeaderDecoder and ...
}
crate_b::SBE_SCHEMA_ID => {
    // use crate_b specific ReadBuf and HeaderDecoder and ...
}
_ => {}
}
wbprime commented 3 weeks ago

Hi I've attached a pr to address this #1019. Could someone help check if it could be accepted ?