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:
|
if wireTy != LengthDelimited:
|
||||||
raise newException(UnexpectedTypeError, fmt"Not a length delimited value at offset {offset}! Received a {wireTy}")
|
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](
|
proc get*[T: SomeLengthDelimited](
|
||||||
bytes: var seq[byte],
|
bytes: var seq[byte],
|
||||||
ty: typedesc[T],
|
ty: typedesc[T],
|
||||||
|
|
@ -312,8 +317,7 @@ proc decodeField*[T: object](
|
||||||
): ProtoField[T] {.inline.} =
|
): ProtoField[T] {.inline.} =
|
||||||
var bytesRead = 0
|
var bytesRead = 0
|
||||||
|
|
||||||
let wireTy = wireType(bytes[outOffset])
|
checkType(bytes[outOffset], ty, outOffset)
|
||||||
assert wireTy == LengthDelimited
|
|
||||||
|
|
||||||
result.index = fieldNumber(bytes[outOffset])
|
result.index = fieldNumber(bytes[outOffset])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue