MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / encode_copy_row_text

Function encode_copy_row_text

src/pgcopy/src/copy.rs:69–100  ·  view source on GitHub ↗
(
    CopyTextFormatParams { null, delimiter }: &CopyTextFormatParams,
    row: &RowRef,
    typ: &SqlRelationType,
    out: &mut Vec<u8>,
)

Source from the content-addressed store, hash-verified

67}
68
69fn encode_copy_row_text(
70 CopyTextFormatParams { null, delimiter }: &CopyTextFormatParams,
71 row: &RowRef,
72 typ: &SqlRelationType,
73 out: &mut Vec<u8>,
74) -> Result<(), io::Error> {
75 let null = null.as_bytes();
76 let mut buf = BytesMut::new();
77 for (idx, field) in mz_pgrepr::values_from_row(row, typ).into_iter().enumerate() {
78 if idx > 0 {
79 out.push(*delimiter);
80 }
81 match field {
82 None => out.extend(null),
83 Some(field) => {
84 buf.clear();
85 field.encode_text(&mut buf);
86 for b in &buf {
87 match b {
88 b'\\' => out.extend(b"\\\\"),
89 b'\n' => out.extend(b"\\n"),
90 b'\r' => out.extend(b"\\r"),
91 b'\t' => out.extend(b"\\t"),
92 _ => out.push(*b),
93 }
94 }
95 }
96 }
97 }
98 out.push(b'\n');
99 Ok(())
100}
101
102fn encode_copy_row_csv(
103 CopyCsvFormatParams {

Callers 1

encode_copy_formatFunction · 0.85

Calls 8

values_from_rowFunction · 0.85
enumerateMethod · 0.80
encode_textMethod · 0.80
as_bytesMethod · 0.45
into_iterMethod · 0.45
pushMethod · 0.45
extendMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected