Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
to wire for int array
Browse files Browse the repository at this point in the history
  • Loading branch information
ragibkl committed Nov 20, 2023
1 parent fcb2346 commit 4e49d67
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ async-trait = "0.1"
chrono = "0.4"
tracing = "0.1.37"
rand = "0.8.5"
rust_decimal = {version = "*", features = ["db-postgres"]}
rust_decimal = { version = "*", features = ["db-postgres"] }
postgres_array = "*"
postgres-types = "*"
pretty_assertions = "1.4.0"

Expand Down
55 changes: 55 additions & 0 deletions convergence/src/to_wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,61 @@ impl ToWire for Decimal {
}
}

impl ToWire for postgres_array::Array<i16> {
fn to_binary(&self) -> Vec<u8> {
let mut b = BytesMut::new();
self.to_sql(&postgres_types::Type::INT2_ARRAY, &mut b).unwrap();
b.into()
}
fn to_text(&self) -> Vec<u8> {
self.to_string().as_bytes().into()
}
}

impl ToWire for postgres_array::Array<i32> {
fn to_binary(&self) -> Vec<u8> {
let mut b = BytesMut::new();
self.to_sql(&postgres_types::Type::INT4_ARRAY, &mut b).unwrap();
b.into()
}
fn to_text(&self) -> Vec<u8> {
self.to_string().as_bytes().into()
}
}

impl ToWire for postgres_array::Array<i64> {
fn to_binary(&self) -> Vec<u8> {
let mut b = BytesMut::new();
self.to_sql(&postgres_types::Type::INT8_ARRAY, &mut b).unwrap();
b.into()
}
fn to_text(&self) -> Vec<u8> {
self.to_string().as_bytes().into()
}
}

impl ToWire for postgres_array::Array<f32> {
fn to_binary(&self) -> Vec<u8> {
let mut b = BytesMut::new();
self.to_sql(&postgres_types::Type::FLOAT4_ARRAY, &mut b).unwrap();
b.into()
}
fn to_text(&self) -> Vec<u8> {
self.to_string().as_bytes().into()
}
}

impl ToWire for postgres_array::Array<f64> {
fn to_binary(&self) -> Vec<u8> {
let mut b = BytesMut::new();
self.to_sql(&postgres_types::Type::FLOAT8_ARRAY, &mut b).unwrap();
b.into()
}
fn to_text(&self) -> Vec<u8> {
self.to_string().as_bytes().into()
}
}

macro_rules! to_wire {
($type: ident) => {
#[allow(missing_docs)]
Expand Down

0 comments on commit 4e49d67

Please sign in to comment.