Update CBOR tags (#3312)
This commit is contained in:
parent
c27a555bc6
commit
0431d38602
1 changed files with 14 additions and 14 deletions
|
@ -8,12 +8,12 @@ use surrealdb::sql::Thing;
|
||||||
use surrealdb::sql::Uuid;
|
use surrealdb::sql::Uuid;
|
||||||
use surrealdb::sql::Value;
|
use surrealdb::sql::Value;
|
||||||
|
|
||||||
const TAG_NONE: u64 = 78_773_250;
|
const TAG_DATETIME: u64 = 0;
|
||||||
const TAG_UUID: u64 = 78_773_251;
|
const TAG_NONE: u64 = 6;
|
||||||
const TAG_DECIMAL: u64 = 78_773_252;
|
const TAG_UUID: u64 = 7;
|
||||||
const TAG_DURATION: u64 = 78_773_253;
|
const TAG_DECIMAL: u64 = 8;
|
||||||
const TAG_DATETIME: u64 = 78_773_254;
|
const TAG_DURATION: u64 = 9;
|
||||||
const TAG_RECORDID: u64 = 78_773_255;
|
const TAG_RECORDID: u64 = 10;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Cbor(pub Data);
|
pub struct Cbor(pub Data);
|
||||||
|
@ -41,6 +41,14 @@ impl TryFrom<Cbor> for Value {
|
||||||
.collect::<Result<Value, &str>>(),
|
.collect::<Result<Value, &str>>(),
|
||||||
Data::Tag(t, v) => {
|
Data::Tag(t, v) => {
|
||||||
match t {
|
match t {
|
||||||
|
// A literal datetime
|
||||||
|
TAG_DATETIME => match *v {
|
||||||
|
Data::Text(v) => match Datetime::try_from(v) {
|
||||||
|
Ok(v) => Ok(v.into()),
|
||||||
|
_ => Err("Expected a valid Datetime value"),
|
||||||
|
},
|
||||||
|
_ => Err("Expected a CBOR text data type"),
|
||||||
|
},
|
||||||
// A literal NONE
|
// A literal NONE
|
||||||
TAG_NONE => Ok(Value::None),
|
TAG_NONE => Ok(Value::None),
|
||||||
// A literal uuid
|
// A literal uuid
|
||||||
|
@ -67,14 +75,6 @@ impl TryFrom<Cbor> for Value {
|
||||||
},
|
},
|
||||||
_ => Err("Expected a CBOR text data type"),
|
_ => Err("Expected a CBOR text data type"),
|
||||||
},
|
},
|
||||||
// A literal datetime
|
|
||||||
TAG_DATETIME => match *v {
|
|
||||||
Data::Text(v) => match Datetime::try_from(v) {
|
|
||||||
Ok(v) => Ok(v.into()),
|
|
||||||
_ => Err("Expected a valid Datetime value"),
|
|
||||||
},
|
|
||||||
_ => Err("Expected a CBOR text data type"),
|
|
||||||
},
|
|
||||||
// A literal recordid
|
// A literal recordid
|
||||||
TAG_RECORDID => match *v {
|
TAG_RECORDID => match *v {
|
||||||
Data::Text(v) => match Thing::try_from(v) {
|
Data::Text(v) => match Thing::try_from(v) {
|
||||||
|
|
Loading…
Reference in a new issue