(
row: &RowRef,
typ: &SqlRelationType,
out: &mut Vec<u8>,
)
| 23 | static END_OF_COPY_MARKER: &[u8] = b"\\."; |
| 24 | |
| 25 | fn encode_copy_row_binary( |
| 26 | row: &RowRef, |
| 27 | typ: &SqlRelationType, |
| 28 | out: &mut Vec<u8>, |
| 29 | ) -> Result<(), io::Error> { |
| 30 | const NULL_BYTES: [u8; 4] = (-1i32).to_be_bytes(); |
| 31 | |
| 32 | // 16-bit int of number of tuples. |
| 33 | let count = i16::try_from(typ.column_types.len()).map_err(|_| { |
| 34 | io::Error::new( |
| 35 | io::ErrorKind::InvalidData, |
| 36 | "column count does not fit into an i16", |
| 37 | ) |
| 38 | })?; |
| 39 | |
| 40 | out.extend(count.to_be_bytes()); |
| 41 | let mut buf = BytesMut::new(); |
| 42 | for (field, typ) in row |
| 43 | .iter() |
| 44 | .zip_eq(&typ.column_types) |
| 45 | .map(|(datum, typ)| (mz_pgrepr::Value::from_datum(datum, &typ.scalar_type), typ)) |
| 46 | { |
| 47 | match field { |
| 48 | None => out.extend(NULL_BYTES), |
| 49 | Some(field) => { |
| 50 | buf.clear(); |
| 51 | field.encode_binary(&mz_pgrepr::Type::from(&typ.scalar_type), &mut buf)?; |
| 52 | out.extend( |
| 53 | i32::try_from(buf.len()) |
| 54 | .map_err(|_| { |
| 55 | io::Error::new( |
| 56 | io::ErrorKind::InvalidData, |
| 57 | "field length does not fit into an i32", |
| 58 | ) |
| 59 | })? |
| 60 | .to_be_bytes(), |
| 61 | ); |
| 62 | out.extend(&buf); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | Ok(()) |
| 67 | } |
| 68 | |
| 69 | fn encode_copy_row_text( |
| 70 | CopyTextFormatParams { null, delimiter }: &CopyTextFormatParams, |
no test coverage detected