1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
|
//! GATS - Generalized Agile Transport System
//!
//! This is a format designed to pack complex data structures into compact and
//! easily transmissible packets that are platform independent. This format
//! supports integers, byte arrays, booleans, lists, dictionaries (with string
//! keys), floats, and null.
//!
//! Integers are stored in a packed format that requires only as many bytes as
//! it takes to represent the value. This generally results in a reduction of
//! space used, and rarely an increase.
//!
//! Floating point numbers are architecture independent and stored in a similar
//! packed format to present them as accurately as possible in the minimal
//! amount of space.
//!
//! In theory, both the integer and floating point formats are unbound and could
//! represent values with any number of bytes, but in reality most
//! implementations limit this to 64 bits.
//!
//! For easy transmission each Gats Value can be serialized as a packet, which
//! contains a version header and a total size which makes it easier to read
//! from a socket or the like. Each packet can only contain one value, but
//! values can be complex types.
use std::collections::HashMap;
use std::io::{Cursor, Error, ErrorKind, Read, Write};
use std::num::FpCategory;
use std::sync::LazyLock;
use std::vec::Vec;
#[cfg(feature = "tokio")]
use tokio::io::{AsyncReadExt,AsyncWriteExt,AsyncRead,AsyncWrite};
/// Represents a value in a Gats structure.
#[derive(PartialEq,Debug)]
pub enum Value {
Integer(i64),
ByteString(Vec<u8>),
Boolean(bool),
List(Vec<Value>),
Dictionary(HashMap<String, Value>),
Float(f64),
Null,
}
/// Used by the Value::bytes_to_read function to communicate with the caller
/// about their buffer so far. If Estimate is returned then you should
/// reallocate, read data, and try again. If final is returned then there is
/// no reason to call the estimate any more, you can just be done once you've
/// resized and filled the buffer.
pub enum BytesToRead {
Estimate(usize),
Final(usize),
}
/// Used by the parser internally to handle values in the format that are not
/// Values but are needed to parse the data.
enum ValueParse {
Value(Value),
EndMarker,
}
impl PartialEq<i64> for Value {
fn eq(&self, other: &i64) -> bool {
if let Value::Integer(x) = self {
x == other
} else {
false
}
}
}
impl PartialEq<Vec<u8>> for Value {
fn eq(&self, other: &Vec<u8>) -> bool {
if let Value::ByteString(x) = self {
x == other
} else {
false
}
}
}
impl PartialEq<[u8]> for Value {
fn eq(&self, other: &[u8]) -> bool {
if let Value::ByteString(x) = self {
x == other
} else {
false
}
}
}
impl PartialEq<bool> for Value {
fn eq(&self, other: &bool) -> bool {
if let Value::Boolean(x) = self {
x == other
} else {
false
}
}
}
impl PartialEq<Vec<Value>> for Value {
fn eq(&self, other: &Vec<Value>) -> bool {
if let Value::List(x) = self {
x == other
} else {
false
}
}
}
impl PartialEq<HashMap<String, Value>> for Value {
fn eq(&self, other: &HashMap<String, Value>) -> bool {
if let Value::Dictionary(x) = self {
x == other
} else {
false
}
}
}
impl PartialEq<f64> for Value {
fn eq(&self, other: &f64) -> bool {
if let Value::Float(x) = self {
x == other
} else {
false
}
}
}
impl std::cmp::Eq for Value {}
/// Used for converting floating point numbers to their packed format,
/// this isn't a number we can store easily as a literal without a hex format.
static FLOAT_DIVISOR: LazyLock<f64> = LazyLock::new(|| (256_f64).ln());
/// Internal helper to convert a number into a packed format.
fn write_packed_int(x: i64) -> Vec<u8> {
let mut w = Vec::<u8>::with_capacity(10);
let mut v = x;
let mut bb = if x < 0 {
v = -v;
0x40_u8
} else {
0x00_u8
} | (v & 0x3F) as u8
| if v > (v & 0x3F) { 0x80_u8 } else { 0x00_u8 };
w.push(bb);
v >>= 6;
while v > 0 {
bb = (v & 0x7F) as u8 | if v > (v & 0x7F) { 0x80_u8 } else { 0x00_u8 };
w.push(bb);
v >>= 7;
}
w
}
/// Internal helper to convert a buffer containing a packed integer back into
/// an integer. Any extra data will be ignored.
fn read_packed_int<R: Read>(r: &mut R) -> Result<i64, Error> {
let mut out: i64;
let mut bb = [0u8];
r.read_exact(&mut bb)?;
let negative = (bb[0] & 0x40_u8) == 0x40_u8;
out = (bb[0] & 0x3F_u8) as i64;
let mut c = 0;
while (bb[0] & 0x80_u8) != 0 {
r.read_exact(&mut bb)?;
out |= ((bb[0] & 0x7F_u8) as i64) << (6 + 7 * c);
c += 1;
}
if negative { Ok(-out) } else { Ok(out) }
}
impl Value {
pub fn new_int( value: i64 ) -> Value {
Value::Integer( value )
}
pub fn new_byte_string( data: &[u8] ) -> Value {
Value::ByteString( data.to_vec() )
}
pub fn new_bool( value: bool ) -> Value {
Value::Boolean( value )
}
pub fn new_list() -> Value {
Value::List( Vec::new() )
}
pub fn new_dict() -> Value {
Value::Dictionary(HashMap::new())
}
pub fn dict_from<const N: usize>( data: [(String,Value); N] ) -> Value {
Value::Dictionary(HashMap::from( data ))
}
pub fn new_float( value: f64 ) -> Value {
Value::Float( value )
}
pub fn new_null() -> Value {
Value::Null
}
pub fn is_null(&self) -> bool {
matches!(self, Value::Null)
}
pub fn get(&self, key: &str) -> Option<&Value> {
if let Value::Dictionary(d) = self {
d.get( key )
} else {
None
}
}
pub fn as_bool( &self ) -> Result<bool,Error> {
if let Value::Boolean(d) = self {
Ok(*d)
} else {
Err(Error::new(
ErrorKind::InvalidData,
"as_bool called on non boolean value.",
))
}
}
pub fn as_byte_string( &self ) -> Result<&Vec<u8>,Error> {
if let Value::ByteString(d) = self {
Ok(&d)
} else {
Err(Error::new(
ErrorKind::InvalidData,
"as_byte_string called on non ByteString value.",
))
}
}
pub fn write<W: Write>(&self, w: &mut W) -> Result<(), Error> {
match self {
Self::Integer(x) => {
let bb = [b'i'];
w.write_all(&bb)?;
w.write_all(&write_packed_int(*x))?;
}
Self::ByteString(s) => {
let bb = [b's'];
w.write_all(&bb)?;
w.write_all(&write_packed_int(s.len() as i64))?;
w.write_all(s)?;
}
Self::Boolean(b) => {
let mut bb = [0u8];
bb[0] = if *b { b'1' } else { b'0' };
w.write_all(&bb)?;
}
Self::List(l) => {
let mut bb = [b'l'];
w.write_all(&bb)?;
for v in l {
v.write(w)?;
}
bb[0] = b'e';
w.write_all(&bb)?;
}
Self::Dictionary(d) => {
let mut bb = [b'd'];
w.write_all(&bb)?;
for (k, v) in d {
(Value::ByteString(k.clone().into_bytes())).write(w)?;
v.write(w)?;
}
bb[0] = b'e';
w.write_all(&bb)?;
}
Self::Float(f) => {
match f.classify() {
FpCategory::Nan => {
let mut bb = [b'F', 0u8];
bb[1] = if f.is_sign_negative() { 'N' } else { 'n' } as u8;
w.write_all(&bb)?;
}
FpCategory::Infinite => {
let mut bb = [b'F', 0u8];
bb[1] = if f.is_sign_negative() { 'I' } else { 'i' } as u8;
w.write_all(&bb)?;
}
FpCategory::Zero => {
let mut bb = [b'F', 0u8];
bb[1] = if f.is_sign_negative() { 'Z' } else { 'z' } as u8;
w.write_all(&bb)?;
}
FpCategory::Subnormal => {
let mut bb = [b'F', 0u8];
// The format doesn't account for these...uh...make them zero?
bb[1] = if f.is_sign_negative() { 'Z' } else { 'z' } as u8;
w.write_all(&bb)?;
}
FpCategory::Normal => {
let bb = [b'f'];
w.write_all(&bb)?;
let mut bin = Vec::<u8>::with_capacity(10);
let (negative, d) = if f.is_sign_negative() {
(true, -*f)
} else {
(false, *f)
};
let scale: i64 = (d.ln() / *FLOAT_DIVISOR) as i64;
let scale = if scale < 0 { -1 } else { scale };
let mut d = d / 256.0_f64.powf(scale as f64);
bin.push(d as u8);
d = d.fract();
for _ in 0..15 {
d *= 256.0;
bin.push(d as u8);
d = d.fract();
if d == 0.0 {
break;
}
}
if negative {
w.write_all(&write_packed_int(-(bin.len() as i64)))?;
} else {
w.write_all(&write_packed_int(bin.len() as i64))?;
}
w.write_all(&bin)?;
w.write_all(&write_packed_int(scale))?;
}
}
}
Self::Null => {
let bb = [b'n'];
w.write_all(&bb)?;
}
}
Ok(())
}
fn read_parse<R: Read>(r: &mut R) -> Result<ValueParse, Error> {
let it = {
let mut it = [0u8];
r.read_exact(&mut it)?;
it[0]
};
match it as char {
'0' => Ok(ValueParse::Value(Value::Boolean(false))),
'1' => Ok(ValueParse::Value(Value::Boolean(true))),
'n' => Ok(ValueParse::Value(Value::Null)),
'e' => Ok(ValueParse::EndMarker),
'i' => Ok(ValueParse::Value(Value::Integer(read_packed_int(r)?))),
's' => {
let len = read_packed_int(r)?;
let mut body = vec![0; len as usize];
r.read_exact(&mut body)?;
Ok(ValueParse::Value(Value::ByteString(body)))
}
'l' => {
let mut body = Vec::<Value>::new();
while let ValueParse::Value(v) = Value::read_parse(r)? {
body.push(v);
}
Ok(ValueParse::Value(Value::List(body)))
}
'f' => {
let (lng, neg) = {
let lng = read_packed_int(r)?;
if lng < 0 { (-lng, true) } else { (lng, false) }
};
let mut value = 0.0f64;
let mut buf = vec![0u8; lng as usize];
r.read_exact(&mut buf)?;
for b in buf[1..].iter().rev() {
value = (value + (*b as f64)) * (1.0 / 256.0);
}
value += buf[0] as f64;
let scale = read_packed_int(r)?;
value *= 256.0f64.powi(scale as i32);
if neg {
Ok(ValueParse::Value(Value::Float(-value)))
} else {
Ok(ValueParse::Value(Value::Float(value)))
}
}
'F' => {
let st = {
let mut st = [0u8];
r.read_exact(&mut st)?;
st[0]
};
match st as char {
'N' => Ok(ValueParse::Value(Value::Float(f64::NAN))),
'n' => Ok(ValueParse::Value(Value::Float(f64::NAN))),
'I' => Ok(ValueParse::Value(Value::Float(f64::NEG_INFINITY))),
'i' => Ok(ValueParse::Value(Value::Float(f64::INFINITY))),
'Z' => Ok(ValueParse::Value(Value::Float(-0.0f64))),
'z' => Ok(ValueParse::Value(Value::Float(0.0f64))),
_ => Err(Error::new(
ErrorKind::InvalidData,
"Unknown exceptional float subtype found.",
)),
}
}
'd' => {
let mut body = HashMap::new();
while let ValueParse::Value(k) = Value::read_parse(r)? {
let k = if let Value::ByteString(s) = k {
if let Ok(s) = String::from_utf8(s) {
s
} else {
return Err(Error::new(
ErrorKind::InvalidData,
"Keys must be utf8 compatible strings.",
));
}
} else {
return Err(Error::new(
ErrorKind::InvalidData,
"Non-string cannot be dictionary key.",
));
};
let v = match Value::read_parse(r)? {
ValueParse::Value(v) => v,
ValueParse::EndMarker => {
return Err(Error::new(
ErrorKind::InvalidData,
"Premature end marker in dictionary.",
));
}
};
body.insert(k, v);
}
Ok(ValueParse::Value(Value::Dictionary(body)))
}
_ => Err(Error::new(
ErrorKind::InvalidData,
"Invalid data type specified.",
)),
}
}
pub fn read<R: Read>(r: &mut R) -> Result<Value, Error> {
match Value::read_parse(r) {
Ok(ValueParse::Value(v)) => Ok(v),
Ok(ValueParse::EndMarker) => Err(Error::new(
ErrorKind::InvalidData,
"Unexpected EndMarker while parsing structure.",
)),
Err(e) => Err(e),
}
}
pub fn to_packet(&self) -> Result<Vec<u8>, Error> {
let mut body: Vec<u8> = vec![1u8, 0u8, 0u8, 0u8, 0u8];
self.write(&mut body)?;
let len = body.len() as u32;
body[1..5].copy_from_slice(&len.to_be_bytes());
Ok(body)
}
pub fn write_packet<W: Write>(&self, w: &mut W) -> Result<(), Error> {
match self.to_packet() {
Ok(body) => w.write_all(&body),
Err(e) => Err(e),
}
}
#[cfg(feature = "tokio")]
pub async fn write_packet_async<W>(&self, w: &mut W) -> Result<(), Error>
where
W: AsyncWrite + Unpin
{
match self.to_packet() {
Ok(body) => w.write_all(&body).await,
Err(e) => Err(e),
}
}
pub fn bytes_to_read(r: &[u8]) -> Result<BytesToRead, Error> {
if r.len() < 5 {
Ok(BytesToRead::Estimate(5))
} else {
if r[0] != 1 {
return Err(Error::new(
ErrorKind::InvalidData,
"Invalid Gats packet version.",
));
}
if let Ok(ar) = r[1..5].try_into() {
Ok(BytesToRead::Final(i32::from_be_bytes(ar) as usize))
} else {
Err(Error::new(
ErrorKind::UnexpectedEof,
"Insufficient data presented to decode packet header.",
))
}
}
}
pub fn from_packet(r: &[u8]) -> Result<Value, Error> {
if r.len() < 5 {
return Err(Error::new(
ErrorKind::UnexpectedEof,
"Insufficient data presented to decode packet header.",
));
}
if r[0] != 1 {
return Err(Error::new(
ErrorKind::InvalidData,
"Invalid Gats packet version.",
));
}
let size = if let Ok(ar) = r[1..5].try_into() {
i32::from_be_bytes(ar)
} else {
return Err(Error::new(
ErrorKind::UnexpectedEof,
"Insufficient data presented to decode packet header.",
));
};
if r.len() != size as usize {
return Err(Error::new(
ErrorKind::InvalidData,
"Packet buffer is the wrong length.",
));
}
Value::read(&mut Cursor::new(&r[5..]))
}
pub fn read_packet<R: Read>(r: &mut R) -> Result<Value, Error> {
let mut buf = Vec::<u8>::new();
let mut fill = 0usize;
loop {
match Value::bytes_to_read(&buf) {
Ok(BytesToRead::Estimate(size)) => {
buf.resize(size, 0u8);
r.read_exact(&mut buf[fill..])?;
fill = buf.len();
}
Ok(BytesToRead::Final(size)) => {
buf.resize(size, 0u8);
r.read_exact(&mut buf[fill..])?;
return Value::from_packet(&buf);
}
Err(e) => {
return Err(e);
}
}
}
}
#[cfg(feature = "tokio")]
pub async fn read_packet_async<R>(r: &mut R) -> Result<Value, Error>
where
R: AsyncRead + Unpin
{
let mut buf = Vec::<u8>::new();
let mut fill = 0usize;
loop {
match Value::bytes_to_read(&buf) {
Ok(BytesToRead::Estimate(size)) => {
buf.resize(size, 0u8);
let amount = r.read(&mut buf[fill..]).await?;
fill += amount;
}
Ok(BytesToRead::Final(size)) => {
buf.resize(size, 0u8);
let amount = r.read(&mut buf[fill..]).await?;
fill += amount;
if fill == size {
return Value::from_packet(&buf);
}
}
Err(e) => {
return Err(e);
}
}
}
}
}
impl From<i64> for Value {
fn from(v: i64) -> Self {
Value::Integer(v)
}
}
impl From<f64> for Value {
fn from(v: f64) -> Self {
Value::Float(v)
}
}
impl From<bool> for Value {
fn from(v: bool) -> Self {
Value::Boolean(v)
}
}
impl From<Vec<u8>> for Value {
fn from(v: Vec<u8>) -> Self {
Value::ByteString( v )
}
}
impl From<&[u8]> for Value {
fn from(v: &[u8]) -> Self {
Value::ByteString( Vec::from(v) )
}
}
#[cfg(test)]
mod tests {
use super::*;
use core::error::Error;
use std::io::Cursor;
#[test]
fn froms() {
let v = Value::from(55);
assert!(v == 55);
let v = Value::from(987.654);
assert!(v == 987.654);
let v = Value::from(true);
assert!(v == true);
let v = Value::from(b"hello".to_vec());
assert!(v == b"hello".to_vec());
}
#[test]
fn round_int() -> Result<(), Box<dyn Error>> {
let v = Value::Integer(555666);
let mut buf = Vec::<u8>::new();
v.write(&mut buf)?;
let v2 = Value::read(&mut Cursor::new(buf))?;
assert!(v == v2);
assert!(v == 555666);
Ok(())
}
#[test]
fn round_str() -> Result<(), Box<dyn Error>> {
let v = Value::ByteString(vec![1, 1, 2, 3, 5, 8, 13, 21, 34]);
let mut buf = Vec::<u8>::new();
v.write(&mut buf)?;
let v2 = Value::read(&mut Cursor::new(buf))?;
let v3 = Value::ByteString(vec![1, 1, 2, 3, 5, 8, 13, 21, 35]);
assert!(v == v2);
assert!(v != v3);
assert!(v == vec![1, 1, 2, 3, 5, 8, 13, 21, 34]);
Ok(())
}
#[test]
fn round_bool_true() -> Result<(), Box<dyn Error>> {
let v = Value::Boolean(true);
let mut buf = Vec::<u8>::new();
v.write(&mut buf)?;
let v2 = Value::read(&mut Cursor::new(buf))?;
let v3 = Value::Boolean(false);
assert!(v == v2);
assert!(v != v3);
assert!(v == true);
Ok(())
}
#[test]
fn round_bool_false() -> Result<(), Box<dyn Error>> {
let v = Value::Boolean(false);
let mut buf = Vec::<u8>::new();
v.write(&mut buf)?;
let v2 = Value::read(&mut Cursor::new(buf))?;
let v3 = Value::Boolean(true);
assert!(v == v2);
assert!(v != v3);
assert!(v == false);
Ok(())
}
#[test]
fn round_list() -> Result<(), Box<dyn Error>> {
let v = Value::List(vec![
Value::Integer(1),
Value::Integer(1),
Value::Integer(2),
Value::Integer(3),
Value::Integer(5),
Value::Integer(8),
Value::Integer(13),
Value::Integer(21),
Value::Integer(34),
]);
let mut buf = Vec::<u8>::new();
v.write(&mut buf)?;
let v2 = Value::read(&mut Cursor::new(buf))?;
assert!(v == v2);
Ok(())
}
#[test]
fn round_dictionary() -> Result<(), Box<dyn Error>> {
let v = Value::Dictionary(HashMap::from([
("bigger-int".to_string(), Value::Integer(98765)),
("neg-int".to_string(), Value::Integer(-98765)),
("integer".to_string(), Value::Integer(44)),
("boolean".to_string(), Value::Boolean(true)),
(
"list".to_string(),
Value::List(vec![
Value::Integer(1),
Value::Integer(1),
Value::Integer(2),
Value::Integer(3),
Value::Integer(5),
Value::Integer(8),
]),
),
("null".to_string(), Value::Null),
("float".to_string(), Value::Float(123.456)),
]));
let mut buf = Vec::<u8>::new();
v.write(&mut buf)?;
let v2 = Value::read(&mut Cursor::new(buf))?;
assert!(v == v2);
Ok(())
}
#[test]
fn round_null() -> Result<(), Box<dyn Error>> {
let v = Value::Null;
let mut buf = Vec::<u8>::new();
v.write(&mut buf)?;
let v2 = Value::read(&mut Cursor::new(buf))?;
assert!(v == v2);
Ok(())
}
#[test]
fn round_float() -> Result<(), Box<dyn Error>> {
let v = Value::Float(123.456);
let mut buf = Vec::<u8>::new();
v.write(&mut buf)?;
let v2 = Value::read(&mut Cursor::new(buf))?;
assert!(v == v2);
Ok(())
}
#[test]
fn packet_1() -> Result<(), Box<dyn Error>> {
let v = Value::Dictionary(HashMap::from([
("bigger-int".to_string(), Value::Integer(98765)),
("neg-int".to_string(), Value::Integer(-98765)),
("integer".to_string(), Value::Integer(44)),
("boolean".to_string(), Value::Boolean(true)),
(
"list".to_string(),
Value::List(vec![
Value::Integer(1),
Value::Integer(1),
Value::Integer(2),
Value::Integer(3),
Value::Integer(5),
Value::Integer(8),
]),
),
("null".to_string(), Value::Null),
("float".to_string(), Value::Float(123.456)),
]));
let buf = v.to_packet()?;
let v2 = Value::from_packet(&buf)?;
assert!(v == v2);
Ok(())
}
#[cfg(feature = "tokio")]
#[test]
fn async_test() -> Result<(), Box<dyn Error>> {
Ok(())
}
}
|