decoding: parse single-byte boolean streams

This commit is contained in:
Emery Hemingway 2024-05-22 20:50:48 +03:00
parent cd6812ae07
commit 1fee875909
1 changed files with 6 additions and 3 deletions

View File

@ -19,11 +19,14 @@ proc decodePreserves*(s: Stream): Value {.gcsafe.}
proc decodePreserves(s: Stream; tag: uint8): Value =
## Decode a Preserves value from a binary-encoded stream.
if s.atEnd: raise newException(IOError, "End of Preserves stream")
const endMarker = 0x84
case tag
of 0x80: result = Value(kind: pkBoolean, bool: false)
of 0x81: result = Value(kind: pkBoolean, bool: true)
of 0x80: return Value(kind: pkBoolean, bool: false)
of 0x81: return Value(kind: pkBoolean, bool: true)
else: discard
if s.atEnd:
raise newException(IOError, "End of Preserves stream")
case tag
of 0x85:
discard decodePreserves(s)
result = decodePreserves(s)