2025-05-22 16:39:37 +05:30
|
|
|
|
# This file is a modified version of Emery Hemingway’s CBOR library for Nim,
|
|
|
|
|
|
# originally available at https://github.com/ehmry/cbor-nim and released under The Unlicense.
|
|
|
|
|
|
|
2025-05-21 03:22:35 +05:30
|
|
|
|
import ../utils/types
|
|
|
|
|
|
import ./types
|
|
|
|
|
|
import std/sets
|
|
|
|
|
|
|
|
|
|
|
|
proc newUnexpectedKindError*(
|
|
|
|
|
|
expectedType: type, expectedKinds: string, cbor: CborNode
|
|
|
|
|
|
): ref UnexpectedKindError =
|
|
|
|
|
|
newException(
|
|
|
|
|
|
UnexpectedKindError,
|
2025-05-31 17:38:35 +05:30
|
|
|
|
"deserialization to " & $expectedType & " failed: expected " & expectedKinds &
|
2025-05-21 03:22:35 +05:30
|
|
|
|
" but got " & $cbor.kind,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
proc newUnexpectedKindError*(
|
|
|
|
|
|
expectedType: type, expectedKinds: set[CborEventKind], cbor: CborNode
|
|
|
|
|
|
): ref UnexpectedKindError =
|
|
|
|
|
|
newUnexpectedKindError(expectedType, $expectedKinds, cbor)
|
|
|
|
|
|
|
|
|
|
|
|
proc newUnexpectedKindError*(
|
|
|
|
|
|
expectedType: type, expectedKind: CborEventKind, cbor: CborNode
|
|
|
|
|
|
): ref UnexpectedKindError =
|
|
|
|
|
|
newUnexpectedKindError(expectedType, {expectedKind}, cbor)
|
|
|
|
|
|
|
|
|
|
|
|
proc newUnexpectedKindError*(
|
|
|
|
|
|
expectedType: type, expectedKinds: set[CborNodeKind], cbor: CborNode
|
|
|
|
|
|
): ref UnexpectedKindError =
|
|
|
|
|
|
newUnexpectedKindError(expectedType, $expectedKinds, cbor)
|
|
|
|
|
|
|
|
|
|
|
|
proc newUnexpectedKindError*(
|
|
|
|
|
|
expectedType: type, expectedKind: CborNodeKind, cbor: CborNode
|
|
|
|
|
|
): ref UnexpectedKindError =
|
|
|
|
|
|
newUnexpectedKindError(expectedType, {expectedKind}, cbor)
|
|
|
|
|
|
|
|
|
|
|
|
proc newCborError*(msg: string): ref CborParseError =
|
|
|
|
|
|
newException(CborParseError, msg)
|
2025-05-31 17:38:35 +05:30
|
|
|
|
|
|
|
|
|
|
proc parseAssert*(check: bool, msg = "") {.inline.} =
|
|
|
|
|
|
if not check:
|
|
|
|
|
|
raise newException(CborParseError, msg)
|