Skip to content

Commit

Permalink
Merge pull request #28 from imor/binary_tuples
Browse files Browse the repository at this point in the history
add support for binary format in tuple data
  • Loading branch information
petrosagg authored Nov 28, 2024
2 parents 548f00c + 20265ef commit 7d2f14e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions postgres-replication/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const TUPLE_OLD_TAG: u8 = b'O';
const TUPLE_DATA_NULL_TAG: u8 = b'n';
const TUPLE_DATA_TOAST_TAG: u8 = b'u';
const TUPLE_DATA_TEXT_TAG: u8 = b't';
const TUPLE_DATA_BINARY_TAG: u8 = b'b';

// replica identity tags
const REPLICA_IDENTITY_DEFAULT_TAG: u8 = b'd';
Expand Down Expand Up @@ -428,6 +429,8 @@ pub enum TupleData {
UnchangedToast,
/// Column data as text formatted value.
Text(Bytes),
/// Column data as binary formatted value.
Binary(Bytes),
}

impl TupleData {
Expand All @@ -443,6 +446,12 @@ impl TupleData {
buf.read_exact(&mut data)?;
TupleData::Text(data.into())
}
TUPLE_DATA_BINARY_TAG => {
let len = buf.read_i32::<BigEndian>()?;
let mut data = vec![0; len as usize];
buf.read_exact(&mut data)?;
TupleData::Binary(data.into())
}
tag => {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
Expand Down

0 comments on commit 7d2f14e

Please sign in to comment.