Last active
April 10, 2023 17:33
-
-
Save shugen002/5739d1994083da54ea6e63cec8111bfe to your computer and use it in GitHub Desktop.
imhex pattern for odin serializer (not fully function, but good enough for wall world)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <std/string.pat> | |
#include <std/mem.pat> | |
enum NodeType:u8 { | |
Invalid = 0x0, | |
NamedStartOfReferenceNode = 0x1, | |
UnnamedStartOfReferenceNode = 0x2, | |
NamedStartOfStructNode = 0x3, | |
UnnamedStartOfStructNode = 0x4, | |
EndOfNode = 0x5, | |
StartOfArray = 0x6, | |
EndOfArray = 0x7, | |
PrimitiveArray = 0x8, | |
NamedInternalReference = 0x9, | |
UnnamedInternalReference = 0xA, | |
NamedExternalReferenceByIndex = 0xB, | |
UnnamedExternalReferenceByIndex = 0xC, | |
NamedExternalReferenceByGuid = 0xD, | |
UnnamedExternalReferenceByGuid = 0xE, | |
NamedSByte = 0xF, | |
UnnamedSByte = 0x10, | |
NamedByte = 0x11, | |
UnnamedByte = 0x12, | |
NamedShort = 0x13, | |
UnnamedShort = 0x14, | |
NamedUShort = 0x15, | |
UnnamedUShort = 0x16, | |
NamedInt = 0x17, | |
UnnamedInt = 0x18, | |
NamedUInt = 0x19, | |
UnnamedUInt = 0x1A, | |
NamedLong = 0x1B, | |
UnnamedLong = 0x1C, | |
NamedULong = 0x1D, | |
UnnamedULong = 0x1E, | |
NamedFloat = 0x1F, | |
UnnamedFloat = 0x20, | |
NamedDouble = 0x21, | |
UnnamedDouble = 0x22, | |
NamedDecimal = 0x23, | |
UnnamedDecimal = 0x24, | |
NamedChar = 0x25, | |
UnnamedChar = 0x26, | |
NamedString = 0x27, | |
UnnamedString = 0x28, | |
NamedGuid = 0x29, | |
UnnamedGuid = 0x2A, | |
NamedBoolean = 0x2B, | |
UnnamedBoolean = 0x2C, | |
NamedNull = 0x2D, | |
UnnamedNull = 0x2E, | |
TypeName = 0x2F, | |
TypeID = 0x30, | |
EndOfStream = 0x31, | |
NamedExternalReferenceByString = 0x32, | |
UnnamedExternalReferenceByString = 0x33 | |
}; | |
struct StringFast{ | |
bool u16bit; | |
u32 length; | |
if(u16bit){ | |
char16 value[length]; | |
} else { | |
char value[length]; | |
} | |
}; | |
using Node; | |
struct TypeName{ | |
StringFast name; | |
}; | |
struct Type{ | |
NodeType type; | |
u32 typeID; | |
if(type == NodeType::TypeName){ | |
StringFast name; | |
}else if (type== NodeType::UnnamedNull){ | |
}else{ | |
return; | |
} | |
}; | |
struct UnnamedReferenceNode{ | |
Type type; | |
u32 id; | |
Node nodes[while(true)]; | |
}; | |
struct NamedReferenceNode{ | |
StringFast name; | |
Type type; | |
u32 id; | |
Node nodes[while(true)]; | |
}; | |
struct UnnamedStructNode{ | |
Type type; | |
u32 id; | |
Node nodes[while(true)]; | |
}; | |
struct NamedStructNode{ | |
StringFast name; | |
Type type; | |
u32 id; | |
Node nodes[while(true)]; | |
}; | |
struct UnnamedNull{ | |
}; | |
struct NamedNull{ | |
StringFast name; | |
}; | |
struct NamedString{ | |
StringFast name; | |
StringFast value; | |
}; | |
struct UnnamedString{ | |
StringFast value; | |
}; | |
struct NamedInt{ | |
StringFast name; | |
u32 value; | |
}; | |
struct UnnamedInt{ | |
StringFast name; | |
u32 value; | |
}; | |
struct NamedByte{ | |
StringFast name; | |
u8 value; | |
}; | |
struct UnnamedByte{ | |
u8 value; | |
}; | |
struct NamedSByte{ | |
StringFast name; | |
u8 value; | |
}; | |
struct UnnamedSByte{ | |
u8 value; | |
}; | |
struct NamedBoolean{ | |
StringFast name; | |
bool value; | |
}; | |
struct UnnamedBoolean{ | |
bool value; | |
}; | |
struct Array{ | |
u64 length; | |
Node nodes[while(true)]; | |
}; | |
struct Node{ | |
NodeType type; | |
match(type){ | |
(NodeType::NamedStartOfReferenceNode): NamedReferenceNode NamedReferenceNode; | |
(NodeType::UnnamedStartOfReferenceNode): UnnamedReferenceNode UnnamedReferenceNode; | |
(NodeType::NamedStartOfStructNode): NamedStructNode NamedStructNode; | |
(NodeType::UnnamedStartOfStructNode): UnnamedStructNode UnnamedStructNode; | |
(NodeType::EndOfNode): break; | |
(NodeType::StartOfArray): Array Array; | |
(NodeType::EndOfArray): break; | |
(NodeType::NamedBoolean): NamedBoolean NamedBoolean; | |
(NodeType::UnnamedBoolean): UnnamedBoolean UnnamedBoolean; | |
(NodeType::NamedNull): NamedNull NamedNull; | |
(NodeType::UnnamedNull): UnnamedNull UnnamedNull; | |
(NodeType::NamedString): NamedString NamedString; | |
(NodeType::UnnamedString): UnnamedString UnnamedString; | |
(NodeType::NamedSByte): NamedSByte NamedSByte; | |
(NodeType::UnnamedSByte): UnnamedSByte UnnamedSByte; | |
(NodeType::NamedByte): NamedByte NamedByte; | |
(NodeType::UnnamedByte): UnnamedByte UnnamedByte; | |
(NodeType::NamedInt): NamedInt NamedInt; | |
(NodeType::UnnamedInt): UnnamedInt UnnamedInt; | |
(_): { | |
std::print("Unknown Type Id: {}",type); | |
return; | |
} | |
} | |
}; | |
Node document[] @0x00; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment