Skip to content
Draft
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
12 changes: 1 addition & 11 deletions gel-db-protocol/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ message_group!(
Execute,
Sync,
Terminate,
Dump,
Dump3,
Restore,
RestoreBlock,
RestoreEof
Expand Down Expand Up @@ -294,16 +294,6 @@ struct AuthenticationSASLFinal<'a>: Message {
sasl_data: Array<'a, u32, u8>,
}

/// The `Dump` struct represents a dump message from the client.
struct Dump<'a>: Message {
/// Identifies the message as dump.
mtype: u8 = '>',
/// Length of message contents in bytes, including self.
mlen: len,
/// Message annotations.
annotations: Array<'a, i16, Annotation<'a>>,
}

/// The `Dump2` struct represents a dump message from the client.
struct Dump2<'a>: Message {
/// Identifies the message as dump.
Expand Down
50 changes: 1 addition & 49 deletions gel-derive/src/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,45 +52,6 @@ pub fn derive_struct(
};
let fieldname = fields.iter().map(|f| f.name.clone()).collect::<Vec<_>>();
let base_fields = fields.len();
let type_id_block = Some(quote! {
if #decoder.has_implicit_tid {
#elements.skip_element()?;
}
});
let type_name_block = Some(quote! {
if #decoder.has_implicit_tname {
#elements.skip_element()?;
}
});
let id_block = Some(quote! {
if #decoder.has_implicit_id {
#elements.skip_element()?;
}
});
let type_id_check = Some(quote! {
if ctx.has_implicit_tid {
if(!shape.elements[idx].flag_implicit) {
return ::std::result::Result::Err(ctx.expected("implicit __tid__"));
}
idx += 1;
}
});
let type_name_check = Some(quote! {
if ctx.has_implicit_tname {
if(!shape.elements[idx].flag_implicit) {
return ::std::result::Result::Err(ctx.expected("implicit __tname__"));
}
idx += 1;
}
});
let id_check = Some(quote! {
if ctx.has_implicit_id {
if(!shape.elements[idx].flag_implicit) {
return ::std::result::Result::Err(ctx.expected("implicit id"));
}
idx += 1;
}
});
let field_decoders = fields
.iter()
.enumerate()
Expand Down Expand Up @@ -189,17 +150,11 @@ pub fn derive_struct(
(#order, #sub_args): &Self::Args,
#buf: &[u8]
) -> ::std::result::Result<Self, #gel_protocol::errors::DecodeError> {
let #nfields = #base_fields
+ if #decoder.has_implicit_id { 1 } else { 0 }
+ if #decoder.has_implicit_tid { 1 } else { 0 }
+ if #decoder.has_implicit_tname { 1 } else { 0 };
let #nfields = #base_fields;
let mut #elements =
#gel_protocol::serialization::decode::DecodeTupleLike
::new_object(#buf, #nfields)?;

#type_id_block
#type_name_block
#id_block
let fields = #elements.read_n(#field_count)?;
#field_decoders
::std::result::Result::Ok(#name {
Expand All @@ -224,9 +179,6 @@ pub fn derive_struct(

// TODO(tailhook) cache shape.id somewhere
let mut idx = 0;
#type_id_check
#type_name_check
#id_check
if(shape.elements.len() != #field_count) {
return ::std::result::Result::Err(ctx.field_number(
#field_count, shape.elements.len())
Expand Down
17 changes: 3 additions & 14 deletions gel-derive/tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,11 @@ struct JsonRow {
field2: u32,
}

fn old_decoder() -> Decoder {
let mut dec = Decoder::default();
dec.has_implicit_id = true;
dec.has_implicit_tid = true;
dec
}

#[test]
fn json_field() {
let data = b"\0\0\0\x04\0\0\x0b\x86\0\0\0\x10\xf2R\
\x04I\xd7\x04\x11\xea\xaeX\xcf\xdf\xf6\xd0Q\xac\
\0\0\x0b\x86\0\0\0\x10\xf2\xe6F9\xd7\x04\x11\xea\
\xa0<\x83\x9f\xd9\xbd\x88\x94\0\0\0\x19\
\0\0\0\x02id\0\0\x0e\xda\0\0\0\x10\x01{\"field1\": 123}";
let data = b"\0\0\0\x02\0\0\0\x19\0\0\0\x02id\0\0\x0e\xda\0\0\0\x10\x01{\"field1\": 123}";
let order = (vec![0_usize, 1], ((), ()));
let res = ShapeWithJson::decode(&old_decoder(), &order, data);
let res = ShapeWithJson::decode(&Decoder::default(), &order, data);
assert_eq!(
res.unwrap(),
ShapeWithJson {
Expand All @@ -48,6 +37,6 @@ fn json_field() {
#[test]
fn json_row() {
let data = b"\x01{\"field2\": 234}";
let res = JsonRow::decode(&old_decoder(), &(), data);
let res = JsonRow::decode(&Decoder::default(), &(), data);
assert_eq!(res.unwrap(), JsonRow { field2: 234 });
}
26 changes: 0 additions & 26 deletions gel-derive/tests/list_scalar_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ struct ScalarType {
kind: String,
}

fn old_decoder() -> Decoder {
let mut dec = Decoder::default();
dec.has_implicit_id = true;
dec.has_implicit_tid = true;
dec
}

#[test]
fn decode_new() {
let data = b"\0\0\0\x03\0\0\0\x19\0\0\0\x0fcal::local_date\
Expand All @@ -31,22 +24,3 @@ fn decode_new() {
}
);
}

#[test]
fn decode_old() {
let data = b"\0\0\0\x05\0\0\x0b\x86\
\0\0\0\x10\xb2\xa1\x94\xfb\t\xa4\x11\xeb\x9d\x97\xf9'\
\xee\xfc\xb6\x12\0\0\x0b\x86\0\0\0\x10\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
\x01\x0c\0\0\0\x19\0\0\0\x0fcal::local_date\
\0\0\0\x19\0\0\0\x0estd::anyscalar\0\0\0\x19\0\0\0\x06normal";
let order = (vec![0, 1, 2], ((), (), ()));
let res = ScalarType::decode(&old_decoder(), &order, data);
assert_eq!(
res.unwrap(),
ScalarType {
name: "cal::local_date".into(),
extending: "std::anyscalar".into(),
kind: "normal".into(),
}
);
}
Loading
Loading