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::{CodecError, Reader, Writer, decode, encode};
22pub use compose::{
23    MODULES_STATE_TYPE, ModulePart, SET_ENABLED, command_offsets, compose, module_state_type,
24};
25pub use descriptor::{
26    CommandPolicy, CommandSpec, Concurrency, DescriptorError, EventSpec, ExternalNames,
27    MODULES_NAMESPACE, OperationKind, ParamSpec, ProtocolDescriptor, RESERVED_NAMESPACES, Retry,
28    Scope, StateField, check_external_names, valid_name,
29};
30pub use error::{CommandError, SchemaError};
31pub use message::{Cancellation, CommandOutcome, CommandStatus, Invocation, StateUpdate};
32pub use resource::check_resource_name;
33pub use session::{SessionCommand, session_catalog};
34pub use text::{LocalizedText, label_key};
35pub use types::{EnumDef, FieldDef, RecordDef, Type, TypeTable, VariantDef};
36pub use value::Value;
37
38/// Version of the application protocol messages exchanged between entries
39/// and an engine host. Incompatible peers must fail during the handshake.
40pub const PROTOCOL_VERSION: u32 = 1;
41
42/// Version of the serialized protocol descriptor layout.
43pub const DESCRIPTOR_VERSION: u32 = 1;
44
45/// Stable 64-bit FNV-1a hash used for catalog fingerprints.
46pub fn fingerprint_bytes(bytes: &[u8]) -> u64 {
47    let mut hash = 0xcbf2_9ce4_8422_2325u64;
48    for byte in bytes {
49        hash ^= u64::from(*byte);
50        hash = hash.wrapping_mul(0x0100_0000_01b3);
51    }
52    hash
53}