pub struct RawEvent { /* private fields */ }Expand description
A pre-serialized event with cached hash.
This is the high-performance event type for schema-agnostic ingestion. By storing the raw bytes and pre-computed hash, we avoid:
- Re-serialization on every operation
- Repeated hashing for shard selection
§Example
// From network buffer or file (zero-copy if Bytes is used)
let raw = RawEvent::from_bytes(network_buffer);
// From existing JSON value (serializes once)
let raw = RawEvent::from_value(json!({"key": "value"}));
// Ingestion uses cached hash - no re-serialization
bus.ingest_raw(raw)?;Implementations§
Source§impl RawEvent
impl RawEvent
Sourcepub fn from_bytes(bytes: impl Into<Bytes>) -> Self
pub fn from_bytes(bytes: impl Into<Bytes>) -> Self
Create a raw event from bytes.
The bytes must be valid JSON. No validation is performed for performance.
Use from_bytes_validated if you need validation.
Sourcepub fn from_bytes_with_hash(bytes: impl Into<Bytes>, hash: u64) -> Self
pub fn from_bytes_with_hash(bytes: impl Into<Bytes>, hash: u64) -> Self
Create a raw event from bytes with a pre-computed hash.
Use this when you’ve already computed the xxhash (e.g., for reused events). The caller is responsible for ensuring the hash matches the bytes.
Sourcepub fn from_bytes_validated(bytes: impl Into<Bytes>) -> Result<Self, Error>
pub fn from_bytes_validated(bytes: impl Into<Bytes>) -> Result<Self, Error>
Create a raw event from bytes with JSON validation.
Sourcepub fn from_value(value: JsonValue) -> Self
pub fn from_value(value: JsonValue) -> Self
Create a raw event from a JSON value.
This serializes the value once and caches the result.
serde_json::to_vec(&JsonValue) is infallible by
construction — the value tree is a known-good JSON
structure with no fallible serializer in the path —
modulo OOM, which the global allocator handles via
abort. The unwrap_or_default() fallback keeps the
non-panic contract for a hypothetical future serde-json
change that introduced a fallible path on Value. Pre-
fix expect("Value serialization is infallible") panicked
at the call site if the assumption ever broke; the panic
would unwind across from_value’s callers (bus ingest,
FFI ingest paths) where the contract is non-panicking.
Sourcepub fn from_str(s: &str) -> Self
pub fn from_str(s: &str) -> Self
Creates a RawEvent from a string. No validation is performed for
performance — see from_bytes_validated for a validating alternative.