Add checkType for object
This commit is contained in:
parent
5b49b86b23
commit
86c8143567
1 changed files with 6 additions and 2 deletions
|
|
@ -223,6 +223,11 @@ proc checkType[T: SomeLengthDelimited](tyByte: byte, ty: typedesc[T], offset: in
|
|||
if wireTy != LengthDelimited:
|
||||
raise newException(UnexpectedTypeError, fmt"Not a length delimited value at offset {offset}! Received a {wireTy}")
|
||||
|
||||
proc checkType[T: object](tyByte: byte, ty: typedesc[T], offset: int) {.inline.} =
|
||||
let wireTy = wireType(tyByte)
|
||||
if wireTy != LengthDelimited:
|
||||
raise newException(UnexpectedTypeError, fmt"Not an object value at offset {offset}! Received a {wireTy}")
|
||||
|
||||
proc get*[T: SomeLengthDelimited](
|
||||
bytes: var seq[byte],
|
||||
ty: typedesc[T],
|
||||
|
|
@ -312,8 +317,7 @@ proc decodeField*[T: object](
|
|||
): ProtoField[T] {.inline.} =
|
||||
var bytesRead = 0
|
||||
|
||||
let wireTy = wireType(bytes[outOffset])
|
||||
assert wireTy == LengthDelimited
|
||||
checkType(bytes[outOffset], ty, outOffset)
|
||||
|
||||
result.index = fieldNumber(bytes[outOffset])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue