From 3b31fb96049a1d0e1ed9dc109379e2b1ff15aa25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Tue, 28 Jan 2025 13:29:36 +0000 Subject: [PATCH] nexus: consistent binary serialization (#2497) bytes are encoded as base64, but then hex for arrays of bytes always serialize to json as base64 --- nexus/Cargo.lock | 1 - nexus/value/Cargo.toml | 1 - nexus/value/src/array.rs | 5 +++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/nexus/Cargo.lock b/nexus/Cargo.lock index 1fddcc4a66..4f42c6ccdc 100644 --- a/nexus/Cargo.lock +++ b/nexus/Cargo.lock @@ -4769,7 +4769,6 @@ dependencies = [ "base64 0.22.1", "bytes", "chrono", - "hex", "pgwire", "postgres", "postgres-inet", diff --git a/nexus/value/Cargo.toml b/nexus/value/Cargo.toml index 4071b1dea2..514f3473c6 100644 --- a/nexus/value/Cargo.toml +++ b/nexus/value/Cargo.toml @@ -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" diff --git a/nexus/value/src/array.rs b/nexus/value/src/array.rs index c07921daa5..225c7f6dfa 100644 --- a/nexus/value/src/array.rs +++ b/nexus/value/src/array.rs @@ -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; @@ -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(