diff --git a/protobuf_serialization.nim b/protobuf_serialization.nim index 2b9fbdd..2bfd54c 100644 --- a/protobuf_serialization.nim +++ b/protobuf_serialization.nim @@ -173,7 +173,7 @@ proc decodeField*[T: SomeVarint]( numBytesToRead = none(int) ): ProtoField[T] {.inline.} = # Only up to 128 bits supported by the spec - assert (bytes.len - 1) <= 16 + assert sizeof(T) <= 16 var bytesRead = 0 diff --git a/tests/test_serialization.nim b/tests/test_serialization.nim index b6b2051..16278d4 100644 --- a/tests/test_serialization.nim +++ b/tests/test_serialization.nim @@ -8,11 +8,13 @@ type type Test1 = object a: uint + b: string Test3 = object g {.sfixed32.}: int h: int i: Test1 + j: string suite "Test Varint Encoding": test "Can encode/decode enum field": @@ -83,7 +85,7 @@ suite "Test Varint Encoding": test "Can encode/decode object field": 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) var offset, bytesProcessed: int @@ -96,7 +98,7 @@ suite "Test Varint Encoding": test "Can encode/decode object": 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) var output = proto.output