Skip to content

Commit

Permalink
some more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
scMarkus committed Aug 28, 2023
1 parent f761a17 commit 6224fe2
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/codecs/src/encoding/format/csv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::encoding::BuildError;
use bytes::BytesMut;
use chrono::SecondsFormat;
use csv_core::{WriteResult, Writer, WriterBuilder};
use lookup::lookup_v2::ConfigTargetPath;
use tokio_util::codec::Encoder;
use vector_core::{
Expand Down Expand Up @@ -178,9 +179,9 @@ impl CsvSerializerOptions {
/// Serializer that converts an `Event` to bytes using the CSV format.
#[derive(Debug, Clone)]
pub struct CsvSerializer {
// Box because of clippy error: 'large size difference between variants'
// Box because of clippy error: 'large size difference between variants'
// in SerializerConfig enum
writer: Box<csv_core::Writer>,
writer: Box<Writer>,
fields: Vec<ConfigTargetPath>,
internal_buffer: Vec<u8>,
}
Expand All @@ -190,7 +191,7 @@ impl CsvSerializer {
pub fn new(config: CsvSerializerConfig) -> Self {
// 'flexible' is not needed since every event is a single context free csv line
let writer = Box::new(
csv_core::WriterBuilder::new()
WriterBuilder::new()
.delimiter(config.csv.delimiter)
.double_quote(config.csv.double_quote)
.escape(config.csv.escape)
Expand Down Expand Up @@ -231,10 +232,10 @@ impl Encoder<Event> for CsvSerializer {
.delimiter(&mut self.internal_buffer[used_buffer_bytes..]);
used_buffer_bytes += bytes_written;
match res {
csv_core::WriteResult::InputEmpty => {
WriteResult::InputEmpty => {
break;
}
csv_core::WriteResult::OutputFull => {
WriteResult::OutputFull => {
buffer.extend_from_slice(&self.internal_buffer[..used_buffer_bytes]);
used_buffer_bytes = 0;
}
Expand Down Expand Up @@ -269,8 +270,8 @@ impl Encoder<Event> for CsvSerializer {
used_buffer_bytes += bytes_written;

match res {
csv_core::WriteResult::InputEmpty => break,
csv_core::WriteResult::OutputFull => {
WriteResult::InputEmpty => break,
WriteResult::OutputFull => {
buffer.extend_from_slice(&self.internal_buffer[..used_buffer_bytes]);
used_buffer_bytes = 0;
}
Expand All @@ -285,8 +286,8 @@ impl Encoder<Event> for CsvSerializer {
.finish(&mut self.internal_buffer[used_buffer_bytes..]);
used_buffer_bytes += bytes_written;
match res {
csv_core::WriteResult::InputEmpty => break,
csv_core::WriteResult::OutputFull => {
WriteResult::InputEmpty => break,
WriteResult::OutputFull => {
buffer.extend_from_slice(&self.internal_buffer[..used_buffer_bytes]);
used_buffer_bytes = 0;
}
Expand Down Expand Up @@ -558,8 +559,8 @@ mod tests {

#[test]
fn multiple_events() {
let (fields, event1) = make_event_with_fields(vec![("field1", "foo\"")]);
let (_, event2) = make_event_with_fields(vec![("field1", "\"bar")]);
let (fields, event1) = make_event_with_fields(vec![("field1", "foo,")]);
let (_, event2) = make_event_with_fields(vec![("field1", "\nbar")]);
let opts = CsvSerializerOptions {
fields,
..Default::default()
Expand All @@ -571,6 +572,6 @@ mod tests {
serializer.encode(event1, &mut bytes).unwrap();
serializer.encode(event2, &mut bytes).unwrap();

assert_eq!(bytes.freeze(), b"\"foo\"\"\"\"\"bar\"".as_slice());
assert_eq!(bytes.freeze(), b"\"foo,\"\"\nbar\"".as_slice());
}
}

0 comments on commit 6224fe2

Please sign in to comment.