mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
Merge pull request #3215 from blob1807/json-better-enum-support
core:encoding/json Add support for writing enum value names
This commit is contained in:
@@ -51,6 +51,11 @@ Marshal_Options :: struct {
|
|||||||
// NOTE: This will temp allocate and sort a list for each map.
|
// NOTE: This will temp allocate and sort a list for each map.
|
||||||
sort_maps_by_key: bool,
|
sort_maps_by_key: bool,
|
||||||
|
|
||||||
|
// Output enum value's name instead of its underlying value.
|
||||||
|
//
|
||||||
|
// NOTE: If a name isn't found it'll use the underlying value.
|
||||||
|
use_enum_names: bool,
|
||||||
|
|
||||||
// Internal state
|
// Internal state
|
||||||
indentation: int,
|
indentation: int,
|
||||||
mjson_skipped_first_braces_start: bool,
|
mjson_skipped_first_braces_start: bool,
|
||||||
@@ -411,7 +416,16 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err:
|
|||||||
}
|
}
|
||||||
|
|
||||||
case runtime.Type_Info_Enum:
|
case runtime.Type_Info_Enum:
|
||||||
return marshal_to_writer(w, any{v.data, info.base.id}, opt)
|
if !opt.use_enum_names || len(info.names) == 0 {
|
||||||
|
return marshal_to_writer(w, any{v.data, info.base.id}, opt)
|
||||||
|
} else {
|
||||||
|
name, found := reflect.enum_name_from_value_any(v)
|
||||||
|
if found {
|
||||||
|
return marshal_to_writer(w, name, opt)
|
||||||
|
} else {
|
||||||
|
return marshal_to_writer(w, any{v.data, info.base.id}, opt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case runtime.Type_Info_Bit_Set:
|
case runtime.Type_Info_Bit_Set:
|
||||||
is_bit_set_different_endian_to_platform :: proc(ti: ^runtime.Type_Info) -> bool {
|
is_bit_set_different_endian_to_platform :: proc(ti: ^runtime.Type_Info) -> bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user