Skip to content

Commit

Permalink
nexus: consistent binary serialization (#2497)
Browse files Browse the repository at this point in the history
bytes are encoded as base64, but then hex for arrays of bytes

always serialize to json as base64
  • Loading branch information
serprex authored Jan 28, 2025
1 parent ff5e3fb commit 3b31fb9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion nexus/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion nexus/value/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ bytes = "1.1"
chrono.workspace = true
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
hex = "0.4"
pgwire.workspace = true
postgres = { version = "0.19", features = ["with-chrono-0_4"] }
postgres-inet = "0.19.0"
Expand Down
5 changes: 3 additions & 2 deletions nexus/value/src/array.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::error::Error;

use base64::prelude::{Engine as _, BASE64_STANDARD};
use bytes::{BufMut, Bytes, BytesMut};
use chrono::{DateTime, NaiveDate, NaiveTime, Utc};
use pgwire::types::ToSqlText;
Expand Down Expand Up @@ -88,12 +89,12 @@ impl ArrayValue {
),
ArrayValue::Binary(arr) => serde_json::Value::Array(
arr.iter()
.map(|v| serde_json::Value::String(hex::encode(v)))
.map(|v| serde_json::Value::String(BASE64_STANDARD.encode(v)))
.collect(),
),
ArrayValue::VarBinary(arr) => serde_json::Value::Array(
arr.iter()
.map(|v| serde_json::Value::String(hex::encode(v)))
.map(|v| serde_json::Value::String(BASE64_STANDARD.encode(v)))
.collect(),
),
ArrayValue::Uuid(arr) => serde_json::Value::Array(
Expand Down

0 comments on commit 3b31fb9

Please sign in to comment.