codecs/encoding/format/
native.rs1use bytes::BytesMut;
2use prost::Message;
3use serde::{Deserialize, Serialize};
4use tokio_util::codec::Encoder;
5use vector_core::{
6 config::DataType,
7 event::{proto, Event, EventArray},
8 schema,
9};
10
11#[derive(Debug, Clone, Default, Deserialize, Serialize)]
13pub struct NativeSerializerConfig;
14
15impl NativeSerializerConfig {
16 pub const fn build(&self) -> NativeSerializer {
18 NativeSerializer
19 }
20
21 pub fn input_type(&self) -> DataType {
23 DataType::all_bits()
24 }
25
26 pub fn schema_requirement(&self) -> schema::Requirement {
28 schema::Requirement::empty()
29 }
30}
31
32#[derive(Debug, Clone)]
34pub struct NativeSerializer;
35
36impl Encoder<Event> for NativeSerializer {
37 type Error = vector_common::Error;
38
39 fn encode(&mut self, event: Event, buffer: &mut BytesMut) -> Result<(), Self::Error> {
40 let array = EventArray::from(event);
41 let proto = proto::EventArray::from(array);
42 proto.encode(buffer)?;
43 Ok(())
44 }
45}