codecs/decoding/format/
mod.rs

1//! A collection of formats that can be used to convert from byte frames to
2//! structured events.
3
4#![deny(missing_docs)]
5
6mod avro;
7mod bytes;
8mod gelf;
9mod influxdb;
10mod json;
11mod native;
12mod native_json;
13mod protobuf;
14#[cfg(feature = "syslog")]
15mod syslog;
16mod vrl;
17
18use ::bytes::Bytes;
19pub use avro::{AvroDeserializer, AvroDeserializerConfig, AvroDeserializerOptions};
20use dyn_clone::DynClone;
21pub use gelf::{GelfDeserializer, GelfDeserializerConfig, GelfDeserializerOptions};
22pub use influxdb::{InfluxdbDeserializer, InfluxdbDeserializerConfig};
23pub use json::{JsonDeserializer, JsonDeserializerConfig, JsonDeserializerOptions};
24pub use native::{NativeDeserializer, NativeDeserializerConfig};
25pub use native_json::{
26    NativeJsonDeserializer, NativeJsonDeserializerConfig, NativeJsonDeserializerOptions,
27};
28pub use protobuf::{ProtobufDeserializer, ProtobufDeserializerConfig, ProtobufDeserializerOptions};
29use smallvec::SmallVec;
30#[cfg(feature = "syslog")]
31pub use syslog::{SyslogDeserializer, SyslogDeserializerConfig, SyslogDeserializerOptions};
32use vector_core::{config::LogNamespace, event::Event};
33
34pub use self::{
35    bytes::{BytesDeserializer, BytesDeserializerConfig},
36    vrl::{VrlDeserializer, VrlDeserializerConfig, VrlDeserializerOptions},
37};
38
39/// Parse structured events from bytes.
40pub trait Deserializer: DynClone + Send + Sync {
41    /// Parses structured events from bytes.
42    ///
43    /// It returns a `SmallVec` rather than an `Event` directly, since one byte
44    /// frame can potentially hold multiple events, e.g. when parsing a JSON
45    /// array. However, we optimize the most common case of emitting one event
46    /// by not requiring heap allocations for it.
47    ///
48    /// **Note**: The type of the produced events depends on the implementation.
49    fn parse(
50        &self,
51        bytes: Bytes,
52        log_namespace: LogNamespace,
53    ) -> vector_common::Result<SmallVec<[Event; 1]>>;
54
55    /// Parses trace events from bytes.
56    fn parse_traces(&self, _bytes: Bytes) -> vector_common::Result<SmallVec<[Event; 1]>> {
57        unimplemented!()
58    }
59}
60
61dyn_clone::clone_trait_object!(Deserializer);
62
63/// A `Box` containing a `Deserializer`.
64pub type BoxedDeserializer = Box<dyn Deserializer>;
65
66/// Default value for the UTF-8 lossy option.
67const fn default_lossy() -> bool {
68    true
69}