Skip to content

Commit

Permalink
fix: implement DecodeScalar for Bytes (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
ifiokjr authored Aug 26, 2024
1 parent 7b4e9fe commit 99de7ec
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
11 changes: 11 additions & 0 deletions edgedb-protocol/src/serialization/decode/queryable/scalars.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use bytes::Bytes;

use crate::queryable::DescriptorMismatch;
use crate::queryable::{Decoder, DescriptorContext, Queryable};

Expand Down Expand Up @@ -56,6 +58,15 @@ impl DecodeScalar for String {
}
}

impl DecodeScalar for Bytes {
fn uuid() -> Uuid {
codec::STD_BYTES
}
fn typename() -> &'static str {
"std::bytes"
}
}

impl DecodeScalar for Json {
fn uuid() -> Uuid {
codec::STD_JSON
Expand Down
4 changes: 1 addition & 3 deletions edgedb-protocol/src/value.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/*!
Contains the [Value] enum.
*/
use bytes::Bytes;

pub use crate::codec::EnumValue;
use crate::codec::{NamedTupleShape, ObjectShape, ShapeElement};
use crate::common::Cardinality;
Expand All @@ -15,7 +13,7 @@ pub enum Value {
Nothing,
Uuid(Uuid),
Str(String),
Bytes(Bytes),
Bytes(bytes::Bytes),
Int16(i16),
Int32(i32),
Int64(i64),
Expand Down
19 changes: 19 additions & 0 deletions edgedb-tokio/tests/func/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,22 @@ async fn big_num() -> anyhow::Result<()> {

Ok(())
}

#[tokio::test]
async fn bytes() -> anyhow::Result<()> {
let client = Client::new(&SERVER.config);
client.ensure_connected().await?;

#[derive(Queryable)]
struct MyResult {
data: bytes::Bytes,
}

let res = client
.query_required_single::<MyResult, _>("select { data := b'101' } limit 1", &())
.await
.unwrap();

assert_eq!(res.data, b"101"[..]);
Ok(())
}
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
buildInputs = [
(fenix_pkgs.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-6eN/GKzjVSjEhGO9FhWObkRFaE1Jf+uqMSdQnb8lcB4=";
sha256 = "sha256-3jVIIf5XPnUU1CRaTyAiO0XHVbJl12MSx3eucTXCjtE=";
})
] ++ common;
};
Expand Down

0 comments on commit 99de7ec

Please sign in to comment.