aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskari Timperi <oskari.timperi@iki.fi>2021-08-29 12:22:51 +0300
committerOskari Timperi <oskari.timperi@iki.fi>2021-08-29 12:22:51 +0300
commit67e38c9fb76e45423078f8cfc89df743b0518367 (patch)
tree41a56215dd7a5d01f6c75cfa5b127f0c7849f0d9
parentcbec4c5f4ecd0e6523a106502e3babb5726a3436 (diff)
downloadnimpb-master.tar.gz
nimpb-master.zip
Fix #19HEADmaster
-rw-r--r--nimpb/json.nim7
1 files changed, 5 insertions, 2 deletions
diff --git a/nimpb/json.nim b/nimpb/json.nim
index 619554a..17a66ef 100644
--- a/nimpb/json.nim
+++ b/nimpb/json.nim
@@ -39,8 +39,11 @@ proc toJson*(value: uint64): JsonNode =
newJString($value)
proc toJson*[Enum: enum](value: Enum): JsonNode =
- for v in Enum:
- if value == v:
+ # TODO: If the enum has holes, this will go through some unnecessary iterations.
+ # It should be possible to create a macro to get all the possible values of the
+ # enum and only check those.
+ for v in Enum.low.int..Enum.high.int:
+ if ord(value) == v:
return %($v)
# The enum has a value that is not defined in the enum type
result = %(cast[int](value))