mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-13 01:21:38 -07:00
Merge tag 'dev-2025-09'
This commit is contained in:
@@ -82,14 +82,16 @@ _tag_implementations_id: map[string]Tag_Implementation
|
||||
_tag_implementations_type: map[typeid]Tag_Implementation
|
||||
|
||||
// Register a custom tag implementation to be used when marshalling that type and unmarshalling that tag number.
|
||||
tag_register_type :: proc(impl: Tag_Implementation, nr: Tag_Number, type: typeid) {
|
||||
tag_register_type :: proc "contextless" (impl: Tag_Implementation, nr: Tag_Number, type: typeid) {
|
||||
context = runtime.default_context()
|
||||
_tag_implementations_nr[nr] = impl
|
||||
_tag_implementations_type[type] = impl
|
||||
}
|
||||
|
||||
// Register a custom tag implementation to be used when marshalling that tag number or marshalling
|
||||
// a field with the struct tag `cbor_tag:"nr"`.
|
||||
tag_register_number :: proc(impl: Tag_Implementation, nr: Tag_Number, id: string) {
|
||||
tag_register_number :: proc "contextless" (impl: Tag_Implementation, nr: Tag_Number, id: string) {
|
||||
context = runtime.default_context()
|
||||
_tag_implementations_nr[nr] = impl
|
||||
_tag_implementations_id[id] = impl
|
||||
}
|
||||
@@ -98,13 +100,13 @@ tag_register_number :: proc(impl: Tag_Implementation, nr: Tag_Number, id: string
|
||||
INITIALIZE_DEFAULT_TAGS :: #config(CBOR_INITIALIZE_DEFAULT_TAGS, !ODIN_DEFAULT_TO_PANIC_ALLOCATOR && !ODIN_DEFAULT_TO_NIL_ALLOCATOR)
|
||||
|
||||
@(private, init, disabled=!INITIALIZE_DEFAULT_TAGS)
|
||||
tags_initialize_defaults :: proc() {
|
||||
tags_initialize_defaults :: proc "contextless" () {
|
||||
tags_register_defaults()
|
||||
}
|
||||
|
||||
// Registers tags that have implementations provided by this package.
|
||||
// This is done by default and can be controlled with the `CBOR_INITIALIZE_DEFAULT_TAGS` define.
|
||||
tags_register_defaults :: proc() {
|
||||
tags_register_defaults :: proc "contextless" () {
|
||||
tag_register_number({nil, tag_time_unmarshal, tag_time_marshal}, TAG_EPOCH_TIME_NR, TAG_EPOCH_TIME_ID)
|
||||
tag_register_number({nil, tag_base64_unmarshal, tag_base64_marshal}, TAG_BASE64_NR, TAG_BASE64_ID)
|
||||
tag_register_number({nil, tag_cbor_unmarshal, tag_cbor_marshal}, TAG_CBOR_NR, TAG_CBOR_ID)
|
||||
@@ -298,7 +300,7 @@ tag_base64_unmarshal :: proc(_: ^Tag_Implementation, d: Decoder, _: Tag_Number,
|
||||
|
||||
#partial switch t in ti.variant {
|
||||
case reflect.Type_Info_String:
|
||||
|
||||
assert(t.encoding == .UTF_8)
|
||||
if t.is_cstring {
|
||||
length := base64.decoded_len(bytes)
|
||||
builder := strings.builder_make(0, length+1)
|
||||
|
||||
@@ -335,6 +335,8 @@ _unmarshal_value :: proc(d: Decoder, v: any, hdr: Header, allocator := context.a
|
||||
_unmarshal_bytes :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header, add: Add, allocator := context.allocator, loc := #caller_location) -> (err: Unmarshal_Error) {
|
||||
#partial switch t in ti.variant {
|
||||
case reflect.Type_Info_String:
|
||||
assert(t.encoding == .UTF_8)
|
||||
|
||||
bytes := err_conv(_decode_bytes(d, add, allocator=allocator, loc=loc)) or_return
|
||||
|
||||
if t.is_cstring {
|
||||
|
||||
@@ -353,10 +353,10 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err:
|
||||
#partial switch info in ti.variant {
|
||||
case runtime.Type_Info_String:
|
||||
switch x in v {
|
||||
case string:
|
||||
return x == ""
|
||||
case cstring:
|
||||
return x == nil || x == ""
|
||||
case string: return x == ""
|
||||
case cstring: return x == nil || x == ""
|
||||
case string16: return x == ""
|
||||
case cstring16: return x == nil || x == ""
|
||||
}
|
||||
case runtime.Type_Info_Any:
|
||||
return v.(any) == nil
|
||||
|
||||
@@ -572,7 +572,9 @@ unmarshal_object :: proc(p: ^Parser, v: any, end_token: Token_Kind) -> (err: Unm
|
||||
key_ptr: rawptr
|
||||
|
||||
#partial switch tk in t.key.variant {
|
||||
case runtime.Type_Info_String:
|
||||
case runtime.Type_Info_String:
|
||||
assert(tk.encoding == .UTF_8)
|
||||
|
||||
key_ptr = rawptr(&key)
|
||||
key_cstr: cstring
|
||||
if reflect.is_cstring(t.key) {
|
||||
|
||||
Reference in New Issue
Block a user