Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for protocol v2.0 #354

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion edgedb-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rust-version.workspace = true

[dependencies]
bytes = "1.5.0"
snafu = {version="0.8.0"}
snafu = {version="0.8.0", features=["backtrace"]}
uuid = "1.1.2"
num-bigint = {version="0.4.3", optional=true}
num-traits = {version="0.2.10", optional=true}
Expand Down
59 changes: 57 additions & 2 deletions edgedb-protocol/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ pub struct ShapeElement {
pub name: String,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InputObjectShape(pub(crate) Arc<InputObjectShapeInfo>);

#[derive(Debug, PartialEq, Eq)]
pub struct InputObjectShapeInfo {
pub elements: Vec<InputShapeElement>,
}

#[derive(Debug, PartialEq, Eq)]
pub struct InputShapeElement {
pub cardinality: Option<Cardinality>,
pub name: String,
}

#[derive(Debug, PartialEq, Eq)]
pub struct NamedTupleShapeInfo {
pub elements: Vec<TupleElement>,
Expand Down Expand Up @@ -179,7 +193,7 @@ pub struct Object {

#[derive(Debug)]
pub struct Input {
shape: ObjectShape,
shape: InputObjectShape,
codecs: Vec<Arc<dyn Codec>>,
}

Expand Down Expand Up @@ -247,6 +261,19 @@ impl Deref for ObjectShape {
}
}

impl InputObjectShape {
pub fn new(elements: Vec<InputShapeElement>) -> Self {
InputObjectShape(Arc::new(InputObjectShapeInfo { elements }))
}
}

impl Deref for InputObjectShape {
type Target = InputObjectShapeInfo;
fn deref(&self) -> &InputObjectShapeInfo {
&self.0
}
}

impl Deref for NamedTupleShape {
type Target = NamedTupleShapeInfo;
fn deref(&self) -> &NamedTupleShapeInfo {
Expand All @@ -263,7 +290,10 @@ impl<'a> CodecBuilder<'a> {
D::Set(d) => Ok(Arc::new(Set::build(d, self)?)),
D::ObjectShape(d) => Ok(Arc::new(Object::build(d, self)?)),
D::Scalar(d) => Ok(Arc::new(Scalar {
inner: self.build(d.base_type_pos)?,
inner: match d.base_type_pos {
Some(type_pos) => self.build(type_pos)?,
None => scalar_codec(&d.id)?,
},
})),
D::Tuple(d) => Ok(Arc::new(Tuple::build(d, self)?)),
D::NamedTuple(d) => Ok(Arc::new(NamedTuple::build(d, self)?)),
Expand All @@ -281,6 +311,8 @@ impl<'a> CodecBuilder<'a> {
D::Enumeration(d) => Ok(Arc::new(Enum {
members: d.members.iter().map(|x| x[..].into()).collect(),
})),
D::Object(_) => Ok(Arc::new(Nothing {})),
D::Compound(_) => Ok(Arc::new(Nothing {})),
D::InputShape(d) => Ok(Arc::new(Input::build(d, self)?)),
// type annotations are stripped from codecs array before
// building a codec
Expand Down Expand Up @@ -815,6 +847,7 @@ impl<'a> From<&'a descriptors::ShapeElement> for ShapeElement {
cardinality,
name,
type_pos: _,
source_type_pos: _,
} = e;
ShapeElement {
flag_implicit: *flag_implicit,
Expand All @@ -826,6 +859,28 @@ impl<'a> From<&'a descriptors::ShapeElement> for ShapeElement {
}
}

impl<'a> From<&'a [descriptors::InputShapeElement]> for InputObjectShape {
fn from(shape: &'a [descriptors::InputShapeElement]) -> InputObjectShape {
InputObjectShape(Arc::new(InputObjectShapeInfo {
elements: shape.iter().map(InputShapeElement::from).collect(),
}))
}
}

impl<'a> From<&'a descriptors::InputShapeElement> for InputShapeElement {
fn from(e: &'a descriptors::InputShapeElement) -> InputShapeElement {
let descriptors::InputShapeElement {
cardinality,
name,
type_pos: _,
} = e;
InputShapeElement {
cardinality: *cardinality,
name: name.clone(),
}
}
}

impl<'a> From<&'a [descriptors::TupleElement]> for NamedTupleShape {
fn from(shape: &'a [descriptors::TupleElement]) -> NamedTupleShape {
NamedTupleShape(Arc::new(NamedTupleShapeInfo {
Expand Down
Loading
Loading