irc: add Float and URI literal support
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I40c59d94f650e7b9e68f77598492d7ab6a6a6964
This commit is contained in:
parent
3dd2d604ce
commit
95baf44a9c
6 changed files with 126 additions and 9 deletions
|
|
@ -31,6 +31,8 @@ struct Serializer::Impl {
|
|||
NodeType get_node_type(const Node& node) {
|
||||
if (node.holds<ConstIntNode>())
|
||||
return NodeType::CONST_INT;
|
||||
if (node.holds<ConstFloatNode>())
|
||||
return NodeType::CONST_FLOAT;
|
||||
if (node.holds<ConstStringNode>())
|
||||
return NodeType::CONST_STRING;
|
||||
if (node.holds<ConstPathNode>())
|
||||
|
|
@ -39,6 +41,8 @@ struct Serializer::Impl {
|
|||
return NodeType::CONST_BOOL;
|
||||
if (node.holds<ConstNullNode>())
|
||||
return NodeType::CONST_NULL;
|
||||
if (node.holds<ConstURINode>())
|
||||
return NodeType::CONST_URI;
|
||||
if (node.holds<VarNode>())
|
||||
return NodeType::VAR;
|
||||
if (node.holds<LambdaNode>())
|
||||
|
|
@ -78,6 +82,11 @@ struct Serializer::Impl {
|
|||
|
||||
if (auto* n = node.get_if<ConstIntNode>()) {
|
||||
write_u64(static_cast<uint64_t>(n->value));
|
||||
} else if (auto* n = node.get_if<ConstFloatNode>()) {
|
||||
double val = n->value;
|
||||
uint64_t bits = 0;
|
||||
std::memcpy(&bits, &val, sizeof(bits));
|
||||
write_u64(bits);
|
||||
} else if (auto* n = node.get_if<ConstStringNode>()) {
|
||||
write_string(n->value);
|
||||
} else if (auto* n = node.get_if<ConstPathNode>()) {
|
||||
|
|
@ -86,6 +95,8 @@ struct Serializer::Impl {
|
|||
write_u8(n->value ? 1 : 0);
|
||||
} else if (auto* n = node.get_if<ConstNullNode>()) {
|
||||
// No data for null
|
||||
} else if (auto* n = node.get_if<ConstURINode>()) {
|
||||
write_string(n->value);
|
||||
} else if (auto* n = node.get_if<VarNode>()) {
|
||||
write_u32(n->index);
|
||||
} else if (auto* n = node.get_if<LambdaNode>()) {
|
||||
|
|
@ -254,6 +265,12 @@ struct Deserializer::Impl {
|
|||
int64_t val = static_cast<int64_t>(read_u64());
|
||||
return std::make_shared<Node>(ConstIntNode(val, line));
|
||||
}
|
||||
case NodeType::CONST_FLOAT: {
|
||||
uint64_t bits = read_u64();
|
||||
double val = 0.0;
|
||||
std::memcpy(&val, &bits, sizeof(val));
|
||||
return std::make_shared<Node>(ConstFloatNode(val, line));
|
||||
}
|
||||
case NodeType::CONST_STRING: {
|
||||
std::string val = read_string();
|
||||
return std::make_shared<Node>(ConstStringNode(val, line));
|
||||
|
|
@ -268,6 +285,10 @@ struct Deserializer::Impl {
|
|||
}
|
||||
case NodeType::CONST_NULL:
|
||||
return std::make_shared<Node>(ConstNullNode(line));
|
||||
case NodeType::CONST_URI: {
|
||||
std::string val = read_string();
|
||||
return std::make_shared<Node>(ConstURINode(val, line));
|
||||
}
|
||||
case NodeType::VAR: {
|
||||
uint32_t index = read_u32();
|
||||
return std::make_shared<Node>(VarNode(index, "", line));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue