Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

GenerationConfig options

Every option except new("module_name") is a chained builder method. Boolean flags default to the value shown.

OptionDefaultPurpose
new("module") / lean("module")Full / Leanlean() is new().profile(Lean), with no Display/Debug, meta attrs, or dispatch
with_module_name(name)from newOverride the output module when cloning a base config
with_conversion(selector)noneGeneric *_as::<T>() / *_from(&t) per selected field
with_domain_type(selector, path)noneOne canonical app type per field (implies conversion); Generated impl
with_manual_domain_type(selector, path)noneSame signatures, caller supplies TryFromSbe/TryToSbe
with_enum_mapping(EnumMapping)noneGenerated TryFromSbe/TryToSbe between an SBE enum and your enum, an exhaustive match with renames; NullVal (and an unknown value) is an error (App Types)
with_composite_mapping(CompositeMapping)noneGenerated struct-literal mapping between a composite and your struct, member by member with renames; constants skipped, optional members Option
with_source_traits(enable: bool)false{Message}Source trait per message; encode_from(&src) encodes your own type, groups and var-data included, without allocating
with_validate(enable: bool)falseOpt-in validate() on message decoders, group entries and AnyMessage: declared value ranges, enum discriminants, set bits (sbe_rt::ValidateError; Trust Boundary)
with_domain_objects(var_data)offOwned *Domain + encode; Strings → String (bad UTF-8 → InvalidUtf8), Bytes → Vec<u8>
with_display_debug(enable: bool)trueEmit Debug/Display impls on generated types
with_meta_attributes(enable: bool)trueEmit *_ENCODING_OFFSET, *_ID, *_META_ATTRIBUTE etc.
with_dispatch(enable: bool)trueEmit AnyMessage/FrameCursor/MessageVisitor dispatch
with_bool_domain_type(enable: bool)falseAuto-register bool converters for every boolean enum (name, semanticType, or {0,1} value pair)
with_null_as_option(selector)noneNullVal → None for the enum’s fields; getter returns Option<Enum>. Only named_type(<enum>); any other selector is InvalidConfiguration
with_all_enums_as_option()falseAll enums → Option<Enum>; blanket form of with_null_as_option
profile(GenerationProfile)FullPreset: Full (default conveniences) or Lean (off: Display/Debug, meta attrs, dispatch; domains stay off unless re-enabled). Individual with_* overrides still apply after profile.
with_deprecated_attrs(enable: bool)false#[deprecated(note = "deprecated since schema version N")] on decoder getters of deprecated="N" fields
with_shared_module(name)noneMulti-schema shared types module
with_external_sbe_rt(path)noneShare one sbe_rt runtime module instead of inlining
with_keyword_append_token(token)"_"Schema type → Rust type_
with_encode_version(version)noneEncoder writes version and omits members above it; the decoder still reads every version in the schema
with_hook(fn)noneRegister a code-generation hook (serde, custom traits, …); contexts
with_try_hook(fn)noneA hook that can fail generation: Err(reason) becomes GenerateError::Hook naming the item (hooks)
with_extension_consts(enable: bool)falseEvery schema extension mark (attribute or foreign child element) as a &'static str const next to its item: {Name}Schema::{FIELD}_{ATTR}, {Group}Decoder::{FIELD}_{ATTR}, {Enum}::{VALUE}_{ATTR} (Extension XML)

Selector kinds (field_path, semantic_type, extension_attr, named_type) and their precedence: with_conversion vs with_domain_type.

Turn off with_display_debug, with_meta_attributes, and with_dispatch to shrink generated code. Text fields stay bytes unless the schema declares a character encoding (then strict UTF-8/ASCII helpers apply).

Decoder lanes (no configuration needed)

Memoization is a runtime lane, not a generation knob.

let decoder = CarDecoder::try_from(bytes)?;  // small, Sync, recalculates tails
let decoder = decoder.memoized();            // lazy cache, no allocation

Build it once and share & references. The base decoder is Sync; the memoized one is Send but not Sync. Lanes: Decoder lanes.

Typed error conversions

Implement From on the generated sbe_rt types so ? converts and needed/available survive:

#![allow(unused)]
fn main() {
enum AppError {
    Encode(sbe_rt::EncodeError),
    Decode(sbe_rt::DecodeError),
}

impl From<sbe_rt::EncodeError> for AppError {
    fn from(error: sbe_rt::EncodeError) -> Self {
        match error {
            sbe_rt::EncodeError::BufferTooShort {
                field,
                needed,
                available,
            } => {
                let _ = (field, needed, available);
                Self::Encode(error)
            }
            other => Self::Encode(other),
        }
    }
}

impl From<sbe_rt::DecodeError> for AppError {
    fn from(error: sbe_rt::DecodeError) -> Self {
        Self::Decode(error)
    }
}
}