aboutsummaryrefslogtreecommitdiff
path: root/core/encoding
diff options
context:
space:
mode:
authorblob1807 <12388588+blob1807@users.noreply.github.com>2024-03-04 15:06:30 +1000
committerblob1807 <12388588+blob1807@users.noreply.github.com>2024-03-04 15:06:30 +1000
commit9070e613a44059f5bd1b77277de74a1f549f7369 (patch)
tree0b09cc060c88e4375a2477af77f2c15dc1239c43 /core/encoding
parent41fbaaf1d3caf341f556fdf24fa63471f1a6d3c0 (diff)
Return underlining value instead of panicing
when no name it found. Renamed use_enum_value_names to use_enum_names it get the same point across & inline with the reflect procs
Diffstat (limited to 'core/encoding')
-rw-r--r--core/encoding/json/marshal.odin10
1 files changed, 6 insertions, 4 deletions
diff --git a/core/encoding/json/marshal.odin b/core/encoding/json/marshal.odin
index 95ca038f3..2a052dbd9 100644
--- a/core/encoding/json/marshal.odin
+++ b/core/encoding/json/marshal.odin
@@ -51,8 +51,10 @@ Marshal_Options :: struct {
// NOTE: This will temp allocate and sort a list for each map.
sort_maps_by_key: bool,
- // Output enum value's name instead of its underlineing value
- use_enum_value_names: bool,
+ // Output enum value's name instead of its underlineing value.
+ //
+ // NOTE: If a name isn't found it'll use the underlineing value.
+ use_enum_names: bool,
// Internal state
indentation: int,
@@ -407,14 +409,14 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err:
}
case runtime.Type_Info_Enum:
- if !opt.use_enum_value_names || len(info.names) == 0 {
+ 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 {
- panic("Unable to find value in enum's values")
+ return marshal_to_writer(w, any{v.data, info.base.id}, opt)
}
}