aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nimpb/nimpb.nim4
-rw-r--r--src/nimpb/wkt/api_pb.nim12
-rw-r--r--src/nimpb/wkt/struct_pb.nim18
-rw-r--r--src/nimpb/wkt/type_pb.nim60
4 files changed, 25 insertions, 69 deletions
diff --git a/src/nimpb/nimpb.nim b/src/nimpb/nimpb.nim
index 02e70f1..909486d 100644
--- a/src/nimpb/nimpb.nim
+++ b/src/nimpb/nimpb.nim
@@ -397,6 +397,10 @@ proc readEnum*[T](stream: ProtobufStream): T =
proc writeEnum*[T](stream: ProtobufStream, value: T) =
writeUInt32(stream, uint32(value))
+proc writeEnum*[T](stream: ProtobufStream, value: T, fieldNumber: int) =
+ writeTag(stream, fieldNumber, WireType.Varint)
+ writeUInt32(stream, uint32(value))
+
proc sizeOfVarint[T](value: T): uint64 =
var tmp = uint64(value)
while tmp >= 0x80'u64:
diff --git a/src/nimpb/wkt/api_pb.nim b/src/nimpb/wkt/api_pb.nim
index d050d41..a8a39cf 100644
--- a/src/nimpb/wkt/api_pb.nim
+++ b/src/nimpb/wkt/api_pb.nim
@@ -204,7 +204,7 @@ proc sizeOfgoogle_protobuf_Method*(message: google_protobuf_Method): uint64 =
result = result + sizeOfLengthDelimited(sizeOfgoogle_protobuf_Option(value))
if hassyntax(message):
result = result + sizeOfTag(7, WireType.Varint)
- result = result + sizeOfgoogle_protobuf_Syntax(message.syntax)
+ result = result + sizeOfEnum[google_protobuf_Syntax](message.syntax)
proc writegoogle_protobuf_Method*(stream: ProtobufStream, message: google_protobuf_Method) =
if hasname(message):
@@ -220,7 +220,7 @@ proc writegoogle_protobuf_Method*(stream: ProtobufStream, message: google_protob
for value in message.options:
writeMessage(stream, value, 6)
if hassyntax(message):
- writegoogle_protobuf_Syntax(stream, message.syntax, 7)
+ writeEnum(stream, message.syntax, 7)
proc readgoogle_protobuf_Method*(stream: ProtobufStream): google_protobuf_Method =
result = newgoogle_protobuf_Method()
@@ -255,7 +255,7 @@ proc readgoogle_protobuf_Method*(stream: ProtobufStream): google_protobuf_Method
addoptions(result, readgoogle_protobuf_Option(pbs))
of 7:
expectWireType(wireType, WireType.Varint)
- setsyntax(result, readgoogle_protobuf_Syntax(stream))
+ setsyntax(result, readEnum[google_protobuf_Syntax](stream))
else: skipField(stream, wireType)
proc serialize*(message: google_protobuf_Method): string =
@@ -520,7 +520,7 @@ proc sizeOfgoogle_protobuf_Api*(message: google_protobuf_Api): uint64 =
result = result + sizeOfLengthDelimited(sizeOfgoogle_protobuf_Mixin(value))
if hassyntax(message):
result = result + sizeOfTag(7, WireType.Varint)
- result = result + sizeOfgoogle_protobuf_Syntax(message.syntax)
+ result = result + sizeOfEnum[google_protobuf_Syntax](message.syntax)
proc writegoogle_protobuf_Api*(stream: ProtobufStream, message: google_protobuf_Api) =
if hasname(message):
@@ -536,7 +536,7 @@ proc writegoogle_protobuf_Api*(stream: ProtobufStream, message: google_protobuf_
for value in message.mixins:
writeMessage(stream, value, 6)
if hassyntax(message):
- writegoogle_protobuf_Syntax(stream, message.syntax, 7)
+ writeEnum(stream, message.syntax, 7)
proc readgoogle_protobuf_Api*(stream: ProtobufStream): google_protobuf_Api =
result = newgoogle_protobuf_Api()
@@ -583,7 +583,7 @@ proc readgoogle_protobuf_Api*(stream: ProtobufStream): google_protobuf_Api =
addmixins(result, readgoogle_protobuf_Mixin(pbs))
of 7:
expectWireType(wireType, WireType.Varint)
- setsyntax(result, readgoogle_protobuf_Syntax(stream))
+ setsyntax(result, readEnum[google_protobuf_Syntax](stream))
else: skipField(stream, wireType)
proc serialize*(message: google_protobuf_Api): string =
diff --git a/src/nimpb/wkt/struct_pb.nim b/src/nimpb/wkt/struct_pb.nim
index 7a03ae7..9b87501 100644
--- a/src/nimpb/wkt/struct_pb.nim
+++ b/src/nimpb/wkt/struct_pb.nim
@@ -35,18 +35,6 @@ type
hasField: IntSet
values: seq[google_protobuf_Value]
-proc readgoogle_protobuf_NullValue*(stream: ProtobufStream): google_protobuf_NullValue =
- google_protobuf_NullValue(readUInt32(stream))
-
-proc writegoogle_protobuf_NullValue*(stream: ProtobufStream, value: google_protobuf_NullValue) =
- writeUInt32(stream, uint32(value))
-
-proc writegoogle_protobuf_NullValue*(stream: ProtobufStream, value: google_protobuf_NullValue, fieldNumber: int) =
- writeUInt32(stream, uint32(value), fieldNumber)
-
-proc sizeOfgoogle_protobuf_NullValue*(value: google_protobuf_NullValue): uint64 =
- sizeOfUInt32(uint32(value))
-
proc writegoogle_protobuf_Struct_FieldsEntryKV(stream: ProtobufStream, key: string, value: google_protobuf_Value)
proc readgoogle_protobuf_Struct_FieldsEntryKV(stream: ProtobufStream, tbl: TableRef[string, google_protobuf_Value])
proc sizeOfgoogle_protobuf_Struct_FieldsEntryKV(key: string, value: google_protobuf_Value): uint64
@@ -361,7 +349,7 @@ proc `list_value=`*(message: google_protobuf_Value, value: google_protobuf_ListV
proc sizeOfgoogle_protobuf_Value*(message: google_protobuf_Value): uint64 =
if hasnull_value(message):
result = result + sizeOfTag(1, WireType.Varint)
- result = result + sizeOfgoogle_protobuf_NullValue(message.kind.null_value)
+ result = result + sizeOfEnum[google_protobuf_NullValue](message.kind.null_value)
if hasnumber_value(message):
result = result + sizeOfTag(2, WireType.Fixed64)
result = result + sizeOfDouble(message.kind.number_value)
@@ -380,7 +368,7 @@ proc sizeOfgoogle_protobuf_Value*(message: google_protobuf_Value): uint64 =
proc writegoogle_protobuf_Value*(stream: ProtobufStream, message: google_protobuf_Value) =
if hasnull_value(message):
- writegoogle_protobuf_NullValue(stream, message.kind.null_value, 1)
+ writeEnum(stream, message.kind.null_value, 1)
if hasnumber_value(message):
writeDouble(stream, message.kind.number_value, 2)
if hasstring_value(message):
@@ -403,7 +391,7 @@ proc readgoogle_protobuf_Value*(stream: ProtobufStream): google_protobuf_Value =
raise newException(InvalidFieldNumberError, "Invalid field number: 0")
of 1:
expectWireType(wireType, WireType.Varint)
- setnull_value(result, readgoogle_protobuf_NullValue(stream))
+ setnull_value(result, readEnum[google_protobuf_NullValue](stream))
of 2:
expectWireType(wireType, WireType.Fixed64)
setnumber_value(result, readDouble(stream))
diff --git a/src/nimpb/wkt/type_pb.nim b/src/nimpb/wkt/type_pb.nim
index ac737af..00889e3 100644
--- a/src/nimpb/wkt/type_pb.nim
+++ b/src/nimpb/wkt/type_pb.nim
@@ -78,42 +78,6 @@ type
name: string
value: google_protobuf_Any
-proc readgoogle_protobuf_Syntax*(stream: ProtobufStream): google_protobuf_Syntax =
- google_protobuf_Syntax(readUInt32(stream))
-
-proc writegoogle_protobuf_Syntax*(stream: ProtobufStream, value: google_protobuf_Syntax) =
- writeUInt32(stream, uint32(value))
-
-proc writegoogle_protobuf_Syntax*(stream: ProtobufStream, value: google_protobuf_Syntax, fieldNumber: int) =
- writeUInt32(stream, uint32(value), fieldNumber)
-
-proc sizeOfgoogle_protobuf_Syntax*(value: google_protobuf_Syntax): uint64 =
- sizeOfUInt32(uint32(value))
-
-proc readgoogle_protobuf_Field_Kind*(stream: ProtobufStream): google_protobuf_Field_Kind =
- google_protobuf_Field_Kind(readUInt32(stream))
-
-proc writegoogle_protobuf_Field_Kind*(stream: ProtobufStream, value: google_protobuf_Field_Kind) =
- writeUInt32(stream, uint32(value))
-
-proc writegoogle_protobuf_Field_Kind*(stream: ProtobufStream, value: google_protobuf_Field_Kind, fieldNumber: int) =
- writeUInt32(stream, uint32(value), fieldNumber)
-
-proc sizeOfgoogle_protobuf_Field_Kind*(value: google_protobuf_Field_Kind): uint64 =
- sizeOfUInt32(uint32(value))
-
-proc readgoogle_protobuf_Field_Cardinality*(stream: ProtobufStream): google_protobuf_Field_Cardinality =
- google_protobuf_Field_Cardinality(readUInt32(stream))
-
-proc writegoogle_protobuf_Field_Cardinality*(stream: ProtobufStream, value: google_protobuf_Field_Cardinality) =
- writeUInt32(stream, uint32(value))
-
-proc writegoogle_protobuf_Field_Cardinality*(stream: ProtobufStream, value: google_protobuf_Field_Cardinality, fieldNumber: int) =
- writeUInt32(stream, uint32(value), fieldNumber)
-
-proc sizeOfgoogle_protobuf_Field_Cardinality*(value: google_protobuf_Field_Cardinality): uint64 =
- sizeOfUInt32(uint32(value))
-
proc newgoogle_protobuf_Option*(): google_protobuf_Option
proc writegoogle_protobuf_Option*(stream: ProtobufStream, message: google_protobuf_Option)
proc readgoogle_protobuf_Option*(stream: ProtobufStream): google_protobuf_Option
@@ -419,10 +383,10 @@ proc `default_value=`*(message: google_protobuf_Field, value: string) {.inline.}
proc sizeOfgoogle_protobuf_Field*(message: google_protobuf_Field): uint64 =
if haskind(message):
result = result + sizeOfTag(1, WireType.Varint)
- result = result + sizeOfgoogle_protobuf_Field_Kind(message.kind)
+ result = result + sizeOfEnum[google_protobuf_Field_Kind](message.kind)
if hascardinality(message):
result = result + sizeOfTag(2, WireType.Varint)
- result = result + sizeOfgoogle_protobuf_Field_Cardinality(message.cardinality)
+ result = result + sizeOfEnum[google_protobuf_Field_Cardinality](message.cardinality)
if hasnumber(message):
result = result + sizeOfTag(3, WireType.Varint)
result = result + sizeOfInt32(message.number)
@@ -450,9 +414,9 @@ proc sizeOfgoogle_protobuf_Field*(message: google_protobuf_Field): uint64 =
proc writegoogle_protobuf_Field*(stream: ProtobufStream, message: google_protobuf_Field) =
if haskind(message):
- writegoogle_protobuf_Field_Kind(stream, message.kind, 1)
+ writeEnum(stream, message.kind, 1)
if hascardinality(message):
- writegoogle_protobuf_Field_Cardinality(stream, message.cardinality, 2)
+ writeEnum(stream, message.cardinality, 2)
if hasnumber(message):
writeInt32(stream, message.number, 3)
if hasname(message):
@@ -481,10 +445,10 @@ proc readgoogle_protobuf_Field*(stream: ProtobufStream): google_protobuf_Field =
raise newException(InvalidFieldNumberError, "Invalid field number: 0")
of 1:
expectWireType(wireType, WireType.Varint)
- setkind(result, readgoogle_protobuf_Field_Kind(stream))
+ setkind(result, readEnum[google_protobuf_Field_Kind](stream))
of 2:
expectWireType(wireType, WireType.Varint)
- setcardinality(result, readgoogle_protobuf_Field_Cardinality(stream))
+ setcardinality(result, readEnum[google_protobuf_Field_Cardinality](stream))
of 3:
expectWireType(wireType, WireType.Varint)
setnumber(result, readInt32(stream))
@@ -671,7 +635,7 @@ proc sizeOfgoogle_protobuf_Type*(message: google_protobuf_Type): uint64 =
result = result + sizeOfLengthDelimited(sizeOfgoogle_protobuf_SourceContext(message.source_context))
if hassyntax(message):
result = result + sizeOfTag(6, WireType.Varint)
- result = result + sizeOfgoogle_protobuf_Syntax(message.syntax)
+ result = result + sizeOfEnum[google_protobuf_Syntax](message.syntax)
proc writegoogle_protobuf_Type*(stream: ProtobufStream, message: google_protobuf_Type) =
if hasname(message):
@@ -685,7 +649,7 @@ proc writegoogle_protobuf_Type*(stream: ProtobufStream, message: google_protobuf
if hassource_context(message):
writeMessage(stream, message.source_context, 5)
if hassyntax(message):
- writegoogle_protobuf_Syntax(stream, message.syntax, 6)
+ writeEnum(stream, message.syntax, 6)
proc readgoogle_protobuf_Type*(stream: ProtobufStream): google_protobuf_Type =
result = newgoogle_protobuf_Type()
@@ -725,7 +689,7 @@ proc readgoogle_protobuf_Type*(stream: ProtobufStream): google_protobuf_Type =
setsource_context(result, readgoogle_protobuf_SourceContext(pbs))
of 6:
expectWireType(wireType, WireType.Varint)
- setsyntax(result, readgoogle_protobuf_Syntax(stream))
+ setsyntax(result, readEnum[google_protobuf_Syntax](stream))
else: skipField(stream, wireType)
proc serialize*(message: google_protobuf_Type): string =
@@ -978,7 +942,7 @@ proc sizeOfgoogle_protobuf_Enum*(message: google_protobuf_Enum): uint64 =
result = result + sizeOfLengthDelimited(sizeOfgoogle_protobuf_SourceContext(message.source_context))
if hassyntax(message):
result = result + sizeOfTag(5, WireType.Varint)
- result = result + sizeOfgoogle_protobuf_Syntax(message.syntax)
+ result = result + sizeOfEnum[google_protobuf_Syntax](message.syntax)
proc writegoogle_protobuf_Enum*(stream: ProtobufStream, message: google_protobuf_Enum) =
if hasname(message):
@@ -990,7 +954,7 @@ proc writegoogle_protobuf_Enum*(stream: ProtobufStream, message: google_protobuf
if hassource_context(message):
writeMessage(stream, message.source_context, 4)
if hassyntax(message):
- writegoogle_protobuf_Syntax(stream, message.syntax, 5)
+ writeEnum(stream, message.syntax, 5)
proc readgoogle_protobuf_Enum*(stream: ProtobufStream): google_protobuf_Enum =
result = newgoogle_protobuf_Enum()
@@ -1027,7 +991,7 @@ proc readgoogle_protobuf_Enum*(stream: ProtobufStream): google_protobuf_Enum =
setsource_context(result, readgoogle_protobuf_SourceContext(pbs))
of 5:
expectWireType(wireType, WireType.Varint)
- setsyntax(result, readgoogle_protobuf_Syntax(stream))
+ setsyntax(result, readEnum[google_protobuf_Syntax](stream))
else: skipField(stream, wireType)
proc serialize*(message: google_protobuf_Enum): string =