diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2021-08-29 12:22:51 +0300 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2021-08-29 12:22:51 +0300 |
| commit | 67e38c9fb76e45423078f8cfc89df743b0518367 (patch) | |
| tree | 41a56215dd7a5d01f6c75cfa5b127f0c7849f0d9 | |
| parent | cbec4c5f4ecd0e6523a106502e3babb5726a3436 (diff) | |
| download | nimpb-master.tar.gz nimpb-master.zip | |
| -rw-r--r-- | nimpb/json.nim | 7 |
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)) |
