Fix bug with size detection. Add string to test objects

This commit is contained in:
Joey Yakimowich-Payne 2020-04-03 19:23:08 -06:00
commit 307cb7f9f3
2 changed files with 5 additions and 3 deletions

View file

@ -173,7 +173,7 @@ proc decodeField*[T: SomeVarint](
numBytesToRead = none(int) numBytesToRead = none(int)
): ProtoField[T] {.inline.} = ): ProtoField[T] {.inline.} =
# Only up to 128 bits supported by the spec # Only up to 128 bits supported by the spec
assert (bytes.len - 1) <= 16 assert sizeof(T) <= 16
var bytesRead = 0 var bytesRead = 0

View file

@ -8,11 +8,13 @@ type
type type
Test1 = object Test1 = object
a: uint a: uint
b: string
Test3 = object Test3 = object
g {.sfixed32.}: int g {.sfixed32.}: int
h: int h: int
i: Test1 i: Test1
j: string
suite "Test Varint Encoding": suite "Test Varint Encoding":
test "Can encode/decode enum field": test "Can encode/decode enum field":
@ -83,7 +85,7 @@ suite "Test Varint Encoding":
test "Can encode/decode object field": test "Can encode/decode object field":
var proto = newProtoBuffer() var proto = newProtoBuffer()
let obj = Test3(g: 300, h: 200, i: Test1(a: 100)) let obj = Test3(g: 300, h: 200, i: Test1(a: 100, b: "this is a test"), j: "testing")
proto.encodeField(obj) proto.encodeField(obj)
var offset, bytesProcessed: int var offset, bytesProcessed: int
@ -96,7 +98,7 @@ suite "Test Varint Encoding":
test "Can encode/decode object": test "Can encode/decode object":
var proto = newProtoBuffer() var proto = newProtoBuffer()
let obj = Test3(g: 300, h: 200, i: Test1(a: 100)) let obj = Test3(g: 300, h: 200, i: Test1(a: 100, b: "this is a test"), j: "testing")
proto.encode(obj) proto.encode(obj)
var output = proto.output var output = proto.output