Skip to content

Commit 9060ccb

Browse files
committed
New codec
1 parent ff59b79 commit 9060ccb

File tree

22 files changed

+1550
-338
lines changed

22 files changed

+1550
-338
lines changed

gel-db-protocol/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ workspace = true
1414
[dependencies]
1515
gel-protogen = { path = "../gel-protogen", version= "^0.1.2" }
1616
paste = "1"
17-
derive_more = { version = "2", features = ["try_from"] }
17+
derive_more = { version = "2", features = ["try_from", "from", "debug", "deref", "constructor"] }
1818

1919
[dev-dependencies]
2020
pretty_assertions = "1.2.0"

gel-db-protocol/src/codecs.rs

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
use gel_protogen::prelude::*;
2+
3+
protocol!(
4+
/// Scalar Types
5+
struct Int16Value<'a> {
6+
value: i16,
7+
}
8+
9+
struct Int32Value<'a> {
10+
value: i32,
11+
}
12+
13+
struct Int64Value<'a> {
14+
value: i64,
15+
}
16+
17+
struct Float32Value<'a> {
18+
value: f32,
19+
}
20+
21+
struct Float64Value<'a> {
22+
value: f64,
23+
}
24+
25+
struct BoolValue<'a> {
26+
value: u8, // 0 or 1
27+
}
28+
29+
struct StringValue<'a> {
30+
value: RestString<'a>,
31+
}
32+
33+
struct BytesValue<'a> {
34+
value: Rest<'a>,
35+
}
36+
37+
struct UuidValue<'a> {
38+
value: [u8; 16],
39+
}
40+
41+
struct JsonValue<'a> {
42+
format: u8, // Always 1
43+
value: RestString<'a>,
44+
}
45+
46+
// Temporal Types
47+
struct DatetimeValue<'a> {
48+
micros: i64,
49+
}
50+
51+
struct LocalDatetimeValue<'a> {
52+
micros: i64,
53+
}
54+
55+
struct LocalDateValue<'a> {
56+
days: i32,
57+
}
58+
59+
struct LocalTimeValue<'a> {
60+
micros: i64,
61+
}
62+
63+
struct DurationValue<'a> {
64+
micros: i64,
65+
reserved1: u32 = 0,
66+
reserved2: u32 = 0,
67+
}
68+
69+
struct RelativeDurationValue<'a> {
70+
micros: i64,
71+
days: i32,
72+
months: i32,
73+
}
74+
75+
struct DateDurationValue<'a> {
76+
reserved: i64 = 0,
77+
days: i32,
78+
months: i32,
79+
}
80+
81+
struct DecimalValue<'a> {
82+
ndigits: u16,
83+
weight: i16,
84+
sign: u16, // 0x0000 or 0x4000
85+
decimal_digits: u16,
86+
digits: RestArray<'a, u16>,
87+
}
88+
89+
struct BigIntValue<'a> {
90+
ndigits: u16,
91+
weight: i16,
92+
sign: u16, // 0x0000 or 0x4000
93+
reserved: u16 = 0,
94+
digits: RestArray<'a, u16>,
95+
}
96+
97+
struct ArrayValue<'a> {
98+
ndims: u32,
99+
reserved0: u32 = 0,
100+
reserved1: u32 = 0,
101+
length: u32,
102+
lower: u32 = 1,
103+
elements: RestArray<'a, Encoded<'a>>,
104+
}
105+
106+
struct TupleValue<'a> {
107+
nelements: u32,
108+
elements: RestArray<'a, Element<'a>>,
109+
}
110+
111+
struct NamedTupleValue<'a> {
112+
nelements: u32,
113+
fields: RestArray<'a, Encoded<'a>>,
114+
}
115+
116+
struct ObjectValue<'a> {
117+
nelements: u32,
118+
fields: RestArray<'a, ObjectElement<'a>>,
119+
}
120+
121+
struct SetValue<'a> {
122+
ndims: u32,
123+
reserved0: u32 = 0,
124+
reserved1: u32 = 0,
125+
length: u32,
126+
lower: u32 = 1,
127+
elements: RestArray<'a, Encoded<'a>>,
128+
}
129+
130+
/// Sets of arrays are a special case. Each array is wrapped in an Envelope.
131+
struct ArrayEnvelope<'a> {
132+
length: u32,
133+
nelems: u32,
134+
reserved: u32 = 0,
135+
elements: RestArray<'a, ArrayValue<'a>>,
136+
}
137+
138+
/// Elements for tuples, sets, and arrays.
139+
struct Element<'a> {
140+
reserved: u32 = 0,
141+
data: Array<'a, u32, u8>,
142+
}
143+
144+
/// Elements for objects, nullable.
145+
struct ObjectElement<'a> {
146+
index: u32,
147+
data: Encoded<'a>,
148+
}
149+
150+
struct RangeValue<'a> {
151+
flags: u8, // Combination of EMPTY, LB_INC, UB_INC, LB_INF, UB_INF
152+
bounds: RestArray<'a, Encoded<'a>>,
153+
}
154+
155+
struct MultiRangeValue<'a> {
156+
ranges: RestArray<'a, LengthPrefixed<RangeValue<'a>>>,
157+
}
158+
159+
struct EnumValue<'a> {
160+
value: RestString<'a>,
161+
}
162+
163+
struct PostGisGeometryValue<'a> {
164+
value: Rest<'a>,
165+
}
166+
167+
struct PostGisGeographyValue<'a> {
168+
value: Rest<'a>,
169+
}
170+
171+
struct PostGisBox2dValue<'a> {
172+
value: Rest<'a>,
173+
}
174+
175+
struct PostGisBox3dValue<'a> {
176+
value: Rest<'a>,
177+
}
178+
179+
struct VectorValue<'a> {
180+
length: u16,
181+
reserved: u16 = 0,
182+
values: RestArray<'a, f32>,
183+
}
184+
);

0 commit comments

Comments
 (0)