From 4e9cecf0202a20b329f4846c923cf67a3dd622aa Mon Sep 17 00:00:00 2001 From: Oskari Timperi Date: Sun, 1 Apr 2018 11:36:57 +0300 Subject: Add procs for bytes to stream.nim --- src/protobuf/stream.nim | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/protobuf/stream.nim b/src/protobuf/stream.nim index 74f57dd..6f3b503 100644 --- a/src/protobuf/stream.nim +++ b/src/protobuf/stream.nim @@ -235,11 +235,17 @@ proc writeString*(stream: ProtobufStream, s: string) = writeUInt64(stream, len(s).uint64) write(stream, s) +proc writeBytes*(stream: ProtobufStream, s: bytes) = + writeString(stream, string(s)) + proc readString*(stream: ProtobufStream): string = # TODO: use something else than readStr to get rid of int cast? let size = readUInt64(stream).int result = readStr(stream, size) +proc readBytes*(stream: ProtobufStream): bytes = + bytes(readString(stream)) + proc readEnum*[T](stream: ProtobufStream): T = result = T(readUInt32(stream)) @@ -268,6 +274,9 @@ proc packedFieldSize*[T](values: seq[T], wiretype: WireType): uint64 = proc sizeOfString*(s: string): uint64 = result = sizeOfVarint(len(s).uint64) + len(s).uint64 +proc sizeOfBytes*(s: bytes): uint64 = + result = sizeOfString(string(s)) + proc sizeOfDouble*(value: float64): uint64 = result = 8 -- cgit v1.2.3