Skip to main content

bern_protocol/
lib.rs

1//! Application protocol shared by every Bern entry point.
2//!
3//! The schema here is independent of UI frameworks and of any transport
4//! encoding. Adapters translate it to a wire format (JSON for control
5//! channels, a compact binary layout for in-process bridges) but the meaning
6//! of commands, state and values is defined once.
7
8mod codec;
9mod compose;
10mod descriptor;
11mod error;
12pub mod format;
13mod message;
14mod resource;
15mod session;
16pub mod shortcut;
17mod text;
18mod types;
19mod value;
20
21pub use codec::{
22    CodecError, Reader, Writer, decode, decode_state_field, encode, encode_state_field,
23};
24pub use compose::{
25    MODULES_STATE_TYPE, ModulePart, SET_ENABLED, command_offsets, compose, module_state_type,
26    state_offsets,
27};
28pub use descriptor::{
29    CommandPolicy, CommandSpec, Concurrency, DescriptorError, EventSpec, ExternalNames,
30    MODULES_NAMESPACE, OperationKind, ParamSpec, ProtocolDescriptor, RESERVED_NAMESPACES, Retry,
31    Scope, StateField, check_external_names, valid_name,
32};
33pub use error::{CommandError, SchemaError};
34pub use message::{Cancellation, CommandOutcome, CommandStatus, Invocation, StateUpdate};
35pub use resource::check_resource_name;
36pub use session::{SessionCommand, session_catalog};
37pub use text::{LocalizedText, label_key};
38pub use types::{EnumDef, FieldDef, RecordDef, Type, TypeTable, VariantDef};
39pub use value::Value;
40
41/// Version of the application protocol messages exchanged between entries
42/// and an engine host. Incompatible peers must fail during the handshake.
43pub const PROTOCOL_VERSION: u32 = 1;
44
45/// Version of the serialized protocol descriptor layout.
46pub const DESCRIPTOR_VERSION: u32 = 1;
47
48/// Stable 64-bit FNV-1a hash used for catalog fingerprints.
49pub fn fingerprint_bytes(bytes: &[u8]) -> u64 {
50    let mut hash = 0xcbf2_9ce4_8422_2325u64;
51    for byte in bytes {
52        hash ^= u64::from(*byte);
53        hash = hash.wrapping_mul(0x0100_0000_01b3);
54    }
55    hash
56}