multisql/data/value/
big_endian.rs

1use crate::Value;
2
3pub trait BigEndian {
4	fn to_be_bytes(&self) -> Vec<u8>;
5}
6
7const SEP: [u8; 1] = [0x00];
8const NULL: [u8; 1] = [0x01];
9
10impl BigEndian for Value {
11	fn to_be_bytes(&self) -> Vec<u8> {
12		use Value::*;
13		match self {
14			Null => [SEP, NULL].concat(),
15			Bool(v) => [SEP, [if *v { 0x02 } else { 0x01 }]].concat(),
16			I64(v) => [
17				SEP.as_slice(),
18				&[if v.is_positive() { 0x02 } else { 0x01 }],
19				&v.to_be_bytes(),
20			]
21			.concat(),
22			U64(v) => [SEP.as_slice(), &v.to_be_bytes()].concat(),
23			Str(v) => [SEP.as_slice(), v.as_bytes()].concat(),
24			_ => unimplemented!(),
25		}
26	}
27}