aboutsummaryrefslogtreecommitdiff
path: root/src/protobuf
diff options
context:
space:
mode:
Diffstat (limited to 'src/protobuf')
-rw-r--r--src/protobuf/stream.nim11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/protobuf/stream.nim b/src/protobuf/stream.nim
index a0b650d..d7eeadd 100644
--- a/src/protobuf/stream.nim
+++ b/src/protobuf/stream.nim
@@ -1,5 +1,6 @@
import endians
import streams
+import strutils
import types
@@ -22,6 +23,8 @@ type
InvalidFieldNumberError* = object of ParseError
+ UnexpectedWireTypeError* = object of ParseError
+
proc pbClose(s: Stream) =
close(ProtobufStream(s).stream)
ProtobufStream(s).stream = nil
@@ -336,3 +339,11 @@ proc skipField*(stream: ProtobufStream, wiretype: WireType) =
discard readStr(stream, int(size))
else:
raise newException(Exception, "unsupported wiretype: " & $wiretype)
+
+proc expectWireType*(actual: WireType, expected: varargs[WireType]) =
+ for exp in expected:
+ if actual == exp:
+ return
+ let message = "Got wiretype " & $actual & " but expected: " &
+ join(expected, ", ")
+ raise newException(UnexpectedWireTypeError, message)