diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/protobuf/stream.nim | 9 |
1 files changed, 9 insertions, 0 deletions
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 |
