aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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))