From 5ee92cb5760d6d5db40e65df48514aa7ed3b85ae Mon Sep 17 00:00:00 2001 From: Oskari Timperi Date: Sat, 7 Apr 2018 11:31:10 +0300 Subject: Update WKTs --- src/nimpb/wkt/any_pb.nim | 8 ++- src/nimpb/wkt/api_pb.nim | 67 ++++++++++---------- src/nimpb/wkt/duration_pb.nim | 8 ++- src/nimpb/wkt/empty_pb.nim | 16 ++++- src/nimpb/wkt/field_mask_pb.nim | 8 ++- src/nimpb/wkt/source_context_pb.nim | 8 ++- src/nimpb/wkt/struct_pb.nim | 53 +++++++++------- src/nimpb/wkt/timestamp_pb.nim | 8 ++- src/nimpb/wkt/type_pb.nim | 119 ++++++++++++++++++------------------ src/nimpb/wkt/wrappers_pb.nim | 72 +++++++++++++++++++--- 10 files changed, 239 insertions(+), 128 deletions(-) diff --git a/src/nimpb/wkt/any_pb.nim b/src/nimpb/wkt/any_pb.nim index 0dbc21c..a452870 100644 --- a/src/nimpb/wkt/any_pb.nim +++ b/src/nimpb/wkt/any_pb.nim @@ -8,10 +8,12 @@ type google_protobuf_Any* = ref google_protobuf_AnyObj google_protobuf_AnyObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] type_url: string value: bytes proc newgoogle_protobuf_Any*(): google_protobuf_Any +proc newgoogle_protobuf_Any*(data: string): google_protobuf_Any proc writegoogle_protobuf_Any*(stream: ProtobufStream, message: google_protobuf_Any) proc readgoogle_protobuf_Any*(stream: ProtobufStream): google_protobuf_Any proc sizeOfgoogle_protobuf_Any*(message: google_protobuf_Any): uint64 @@ -19,6 +21,7 @@ proc sizeOfgoogle_protobuf_Any*(message: google_protobuf_Any): uint64 proc newgoogle_protobuf_Any*(): google_protobuf_Any = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.type_url = "" result.value = bytes("") @@ -63,12 +66,15 @@ proc sizeOfgoogle_protobuf_Any*(message: google_protobuf_Any): uint64 = if hasvalue(message): result = result + sizeOfTag(2, WireType.LengthDelimited) result = result + sizeOfBytes(message.value) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_Any*(stream: ProtobufStream, message: google_protobuf_Any) = if hastype_url(message): writeString(stream, message.type_url, 1) if hasvalue(message): writeBytes(stream, message.value, 2) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_Any*(stream: ProtobufStream): google_protobuf_Any = result = newgoogle_protobuf_Any() @@ -85,7 +91,7 @@ proc readgoogle_protobuf_Any*(stream: ProtobufStream): google_protobuf_Any = of 2: expectWireType(wireType, WireType.LengthDelimited) setvalue(result, readBytes(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_Any): string = let diff --git a/src/nimpb/wkt/api_pb.nim b/src/nimpb/wkt/api_pb.nim index a8a39cf..21b4a6d 100644 --- a/src/nimpb/wkt/api_pb.nim +++ b/src/nimpb/wkt/api_pb.nim @@ -11,6 +11,7 @@ type google_protobuf_Api* = ref google_protobuf_ApiObj google_protobuf_ApiObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] name: string methods: seq[google_protobuf_Method] options: seq[google_protobuf_Option] @@ -21,6 +22,7 @@ type google_protobuf_Method* = ref google_protobuf_MethodObj google_protobuf_MethodObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] name: string request_type_url: string request_streaming: bool @@ -31,20 +33,24 @@ type google_protobuf_Mixin* = ref google_protobuf_MixinObj google_protobuf_MixinObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] name: string root: string proc newgoogle_protobuf_Method*(): google_protobuf_Method +proc newgoogle_protobuf_Method*(data: string): google_protobuf_Method proc writegoogle_protobuf_Method*(stream: ProtobufStream, message: google_protobuf_Method) proc readgoogle_protobuf_Method*(stream: ProtobufStream): google_protobuf_Method proc sizeOfgoogle_protobuf_Method*(message: google_protobuf_Method): uint64 proc newgoogle_protobuf_Mixin*(): google_protobuf_Mixin +proc newgoogle_protobuf_Mixin*(data: string): google_protobuf_Mixin proc writegoogle_protobuf_Mixin*(stream: ProtobufStream, message: google_protobuf_Mixin) proc readgoogle_protobuf_Mixin*(stream: ProtobufStream): google_protobuf_Mixin proc sizeOfgoogle_protobuf_Mixin*(message: google_protobuf_Mixin): uint64 proc newgoogle_protobuf_Api*(): google_protobuf_Api +proc newgoogle_protobuf_Api*(data: string): google_protobuf_Api proc writegoogle_protobuf_Api*(stream: ProtobufStream, message: google_protobuf_Api) proc readgoogle_protobuf_Api*(stream: ProtobufStream): google_protobuf_Api proc sizeOfgoogle_protobuf_Api*(message: google_protobuf_Api): uint64 @@ -52,13 +58,14 @@ proc sizeOfgoogle_protobuf_Api*(message: google_protobuf_Api): uint64 proc newgoogle_protobuf_Method*(): google_protobuf_Method = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.name = "" result.request_type_url = "" result.request_streaming = false result.response_type_url = "" result.response_streaming = false result.options = @[] - result.syntax = google_protobuf_Syntax(0) + result.syntax = google_protobuf_Syntax.SYNTAX_PROTO2 proc clearname*(message: google_protobuf_Method) = message.name = "" @@ -167,7 +174,7 @@ proc `options=`*(message: google_protobuf_Method, value: seq[google_protobuf_Opt setoptions(message, value) proc clearsyntax*(message: google_protobuf_Method) = - message.syntax = google_protobuf_Syntax(0) + message.syntax = google_protobuf_Syntax.SYNTAX_PROTO2 excl(message.hasField, [7]) proc hassyntax*(message: google_protobuf_Method): bool = @@ -205,6 +212,8 @@ proc sizeOfgoogle_protobuf_Method*(message: google_protobuf_Method): uint64 = if hassyntax(message): result = result + sizeOfTag(7, WireType.Varint) result = result + sizeOfEnum[google_protobuf_Syntax](message.syntax) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_Method*(stream: ProtobufStream, message: google_protobuf_Method) = if hasname(message): @@ -221,6 +230,7 @@ proc writegoogle_protobuf_Method*(stream: ProtobufStream, message: google_protob writeMessage(stream, value, 6) if hassyntax(message): writeEnum(stream, message.syntax, 7) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_Method*(stream: ProtobufStream): google_protobuf_Method = result = newgoogle_protobuf_Method() @@ -248,15 +258,12 @@ proc readgoogle_protobuf_Method*(stream: ProtobufStream): google_protobuf_Method setresponse_streaming(result, readBool(stream)) of 6: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - addoptions(result, readgoogle_protobuf_Option(pbs)) + let data = readLengthDelimited(stream) + addoptions(result, newgoogle_protobuf_Option(data)) of 7: expectWireType(wireType, WireType.Varint) setsyntax(result, readEnum[google_protobuf_Syntax](stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_Method): string = let @@ -275,6 +282,7 @@ proc newgoogle_protobuf_Method*(data: string): google_protobuf_Method = proc newgoogle_protobuf_Mixin*(): google_protobuf_Mixin = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.name = "" result.root = "" @@ -319,12 +327,15 @@ proc sizeOfgoogle_protobuf_Mixin*(message: google_protobuf_Mixin): uint64 = if hasroot(message): result = result + sizeOfTag(2, WireType.LengthDelimited) result = result + sizeOfString(message.root) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_Mixin*(stream: ProtobufStream, message: google_protobuf_Mixin) = if hasname(message): writeString(stream, message.name, 1) if hasroot(message): writeString(stream, message.root, 2) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_Mixin*(stream: ProtobufStream): google_protobuf_Mixin = result = newgoogle_protobuf_Mixin() @@ -341,7 +352,7 @@ proc readgoogle_protobuf_Mixin*(stream: ProtobufStream): google_protobuf_Mixin = of 2: expectWireType(wireType, WireType.LengthDelimited) setroot(result, readString(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_Mixin): string = let @@ -360,13 +371,14 @@ proc newgoogle_protobuf_Mixin*(data: string): google_protobuf_Mixin = proc newgoogle_protobuf_Api*(): google_protobuf_Api = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.name = "" result.methods = @[] result.options = @[] result.version = "" result.source_context = nil result.mixins = @[] - result.syntax = google_protobuf_Syntax(0) + result.syntax = google_protobuf_Syntax.SYNTAX_PROTO2 proc clearname*(message: google_protobuf_Api) = message.name = "" @@ -483,7 +495,7 @@ proc `mixins=`*(message: google_protobuf_Api, value: seq[google_protobuf_Mixin]) setmixins(message, value) proc clearsyntax*(message: google_protobuf_Api) = - message.syntax = google_protobuf_Syntax(0) + message.syntax = google_protobuf_Syntax.SYNTAX_PROTO2 excl(message.hasField, [7]) proc hassyntax*(message: google_protobuf_Api): bool = @@ -521,6 +533,8 @@ proc sizeOfgoogle_protobuf_Api*(message: google_protobuf_Api): uint64 = if hassyntax(message): result = result + sizeOfTag(7, WireType.Varint) result = result + sizeOfEnum[google_protobuf_Syntax](message.syntax) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_Api*(stream: ProtobufStream, message: google_protobuf_Api) = if hasname(message): @@ -537,6 +551,7 @@ proc writegoogle_protobuf_Api*(stream: ProtobufStream, message: google_protobuf_ writeMessage(stream, value, 6) if hassyntax(message): writeEnum(stream, message.syntax, 7) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_Api*(stream: ProtobufStream): google_protobuf_Api = result = newgoogle_protobuf_Api() @@ -552,39 +567,27 @@ proc readgoogle_protobuf_Api*(stream: ProtobufStream): google_protobuf_Api = setname(result, readString(stream)) of 2: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - addmethods(result, readgoogle_protobuf_Method(pbs)) + let data = readLengthDelimited(stream) + addmethods(result, newgoogle_protobuf_Method(data)) of 3: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - addoptions(result, readgoogle_protobuf_Option(pbs)) + let data = readLengthDelimited(stream) + addoptions(result, newgoogle_protobuf_Option(data)) of 4: expectWireType(wireType, WireType.LengthDelimited) setversion(result, readString(stream)) of 5: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - setsource_context(result, readgoogle_protobuf_SourceContext(pbs)) + let data = readLengthDelimited(stream) + setsource_context(result, newgoogle_protobuf_SourceContext(data)) of 6: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - addmixins(result, readgoogle_protobuf_Mixin(pbs)) + let data = readLengthDelimited(stream) + addmixins(result, newgoogle_protobuf_Mixin(data)) of 7: expectWireType(wireType, WireType.Varint) setsyntax(result, readEnum[google_protobuf_Syntax](stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_Api): string = let diff --git a/src/nimpb/wkt/duration_pb.nim b/src/nimpb/wkt/duration_pb.nim index a44389f..f2b5360 100644 --- a/src/nimpb/wkt/duration_pb.nim +++ b/src/nimpb/wkt/duration_pb.nim @@ -8,10 +8,12 @@ type google_protobuf_Duration* = ref google_protobuf_DurationObj google_protobuf_DurationObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] seconds: int64 nanos: int32 proc newgoogle_protobuf_Duration*(): google_protobuf_Duration +proc newgoogle_protobuf_Duration*(data: string): google_protobuf_Duration proc writegoogle_protobuf_Duration*(stream: ProtobufStream, message: google_protobuf_Duration) proc readgoogle_protobuf_Duration*(stream: ProtobufStream): google_protobuf_Duration proc sizeOfgoogle_protobuf_Duration*(message: google_protobuf_Duration): uint64 @@ -19,6 +21,7 @@ proc sizeOfgoogle_protobuf_Duration*(message: google_protobuf_Duration): uint64 proc newgoogle_protobuf_Duration*(): google_protobuf_Duration = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.seconds = 0 result.nanos = 0 @@ -63,12 +66,15 @@ proc sizeOfgoogle_protobuf_Duration*(message: google_protobuf_Duration): uint64 if hasnanos(message): result = result + sizeOfTag(2, WireType.Varint) result = result + sizeOfInt32(message.nanos) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_Duration*(stream: ProtobufStream, message: google_protobuf_Duration) = if hasseconds(message): writeInt64(stream, message.seconds, 1) if hasnanos(message): writeInt32(stream, message.nanos, 2) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_Duration*(stream: ProtobufStream): google_protobuf_Duration = result = newgoogle_protobuf_Duration() @@ -85,7 +91,7 @@ proc readgoogle_protobuf_Duration*(stream: ProtobufStream): google_protobuf_Dura of 2: expectWireType(wireType, WireType.Varint) setnanos(result, readInt32(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_Duration): string = let diff --git a/src/nimpb/wkt/empty_pb.nim b/src/nimpb/wkt/empty_pb.nim index 3e97d0c..e36260f 100644 --- a/src/nimpb/wkt/empty_pb.nim +++ b/src/nimpb/wkt/empty_pb.nim @@ -8,8 +8,10 @@ type google_protobuf_Empty* = ref google_protobuf_EmptyObj google_protobuf_EmptyObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] proc newgoogle_protobuf_Empty*(): google_protobuf_Empty +proc newgoogle_protobuf_Empty*(data: string): google_protobuf_Empty proc writegoogle_protobuf_Empty*(stream: ProtobufStream, message: google_protobuf_Empty) proc readgoogle_protobuf_Empty*(stream: ProtobufStream): google_protobuf_Empty proc sizeOfgoogle_protobuf_Empty*(message: google_protobuf_Empty): uint64 @@ -17,15 +19,25 @@ proc sizeOfgoogle_protobuf_Empty*(message: google_protobuf_Empty): uint64 proc newgoogle_protobuf_Empty*(): google_protobuf_Empty = new(result) result.hasField = initIntSet() + result.unknownFields = @[] proc sizeOfgoogle_protobuf_Empty*(message: google_protobuf_Empty): uint64 = - result = 0 + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_Empty*(stream: ProtobufStream, message: google_protobuf_Empty) = - discard + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_Empty*(stream: ProtobufStream): google_protobuf_Empty = result = newgoogle_protobuf_Empty() + while not atEnd(stream): + let + tag = readTag(stream) + wireType = wireType(tag) + case fieldNumber(tag) + of 0: + raise newException(InvalidFieldNumberError, "Invalid field number: 0") + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_Empty): string = let diff --git a/src/nimpb/wkt/field_mask_pb.nim b/src/nimpb/wkt/field_mask_pb.nim index 1218253..23e125e 100644 --- a/src/nimpb/wkt/field_mask_pb.nim +++ b/src/nimpb/wkt/field_mask_pb.nim @@ -8,9 +8,11 @@ type google_protobuf_FieldMask* = ref google_protobuf_FieldMaskObj google_protobuf_FieldMaskObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] paths: seq[string] proc newgoogle_protobuf_FieldMask*(): google_protobuf_FieldMask +proc newgoogle_protobuf_FieldMask*(data: string): google_protobuf_FieldMask proc writegoogle_protobuf_FieldMask*(stream: ProtobufStream, message: google_protobuf_FieldMask) proc readgoogle_protobuf_FieldMask*(stream: ProtobufStream): google_protobuf_FieldMask proc sizeOfgoogle_protobuf_FieldMask*(message: google_protobuf_FieldMask): uint64 @@ -18,6 +20,7 @@ proc sizeOfgoogle_protobuf_FieldMask*(message: google_protobuf_FieldMask): uint6 proc newgoogle_protobuf_FieldMask*(): google_protobuf_FieldMask = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.paths = @[] proc clearpaths*(message: google_protobuf_FieldMask) = @@ -45,10 +48,13 @@ proc sizeOfgoogle_protobuf_FieldMask*(message: google_protobuf_FieldMask): uint6 for value in message.paths: result = result + sizeOfTag(1, WireType.LengthDelimited) result = result + sizeOfString(value) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_FieldMask*(stream: ProtobufStream, message: google_protobuf_FieldMask) = for value in message.paths: writeString(stream, value, 1) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_FieldMask*(stream: ProtobufStream): google_protobuf_FieldMask = result = newgoogle_protobuf_FieldMask() @@ -62,7 +68,7 @@ proc readgoogle_protobuf_FieldMask*(stream: ProtobufStream): google_protobuf_Fie of 1: expectWireType(wireType, WireType.LengthDelimited) addpaths(result, readString(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_FieldMask): string = let diff --git a/src/nimpb/wkt/source_context_pb.nim b/src/nimpb/wkt/source_context_pb.nim index 36c7316..6cc19af 100644 --- a/src/nimpb/wkt/source_context_pb.nim +++ b/src/nimpb/wkt/source_context_pb.nim @@ -8,9 +8,11 @@ type google_protobuf_SourceContext* = ref google_protobuf_SourceContextObj google_protobuf_SourceContextObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] file_name: string proc newgoogle_protobuf_SourceContext*(): google_protobuf_SourceContext +proc newgoogle_protobuf_SourceContext*(data: string): google_protobuf_SourceContext proc writegoogle_protobuf_SourceContext*(stream: ProtobufStream, message: google_protobuf_SourceContext) proc readgoogle_protobuf_SourceContext*(stream: ProtobufStream): google_protobuf_SourceContext proc sizeOfgoogle_protobuf_SourceContext*(message: google_protobuf_SourceContext): uint64 @@ -18,6 +20,7 @@ proc sizeOfgoogle_protobuf_SourceContext*(message: google_protobuf_SourceContext proc newgoogle_protobuf_SourceContext*(): google_protobuf_SourceContext = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.file_name = "" proc clearfile_name*(message: google_protobuf_SourceContext) = @@ -41,10 +44,13 @@ proc sizeOfgoogle_protobuf_SourceContext*(message: google_protobuf_SourceContext if hasfile_name(message): result = result + sizeOfTag(1, WireType.LengthDelimited) result = result + sizeOfString(message.file_name) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_SourceContext*(stream: ProtobufStream, message: google_protobuf_SourceContext) = if hasfile_name(message): writeString(stream, message.file_name, 1) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_SourceContext*(stream: ProtobufStream): google_protobuf_SourceContext = result = newgoogle_protobuf_SourceContext() @@ -58,7 +64,7 @@ proc readgoogle_protobuf_SourceContext*(stream: ProtobufStream): google_protobuf of 1: expectWireType(wireType, WireType.LengthDelimited) setfile_name(result, readString(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_SourceContext): string = let diff --git a/src/nimpb/wkt/struct_pb.nim b/src/nimpb/wkt/struct_pb.nim index b4c0c76..73db617 100644 --- a/src/nimpb/wkt/struct_pb.nim +++ b/src/nimpb/wkt/struct_pb.nim @@ -12,10 +12,12 @@ type google_protobuf_Struct* = ref google_protobuf_StructObj google_protobuf_StructObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] fields: TableRef[string, google_protobuf_Value] google_protobuf_Value* = ref google_protobuf_ValueObj google_protobuf_ValueObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] kind: google_protobuf_Value_kind_OneOf google_protobuf_Value_kind_OneOf* {.union.} = object @@ -28,6 +30,7 @@ type google_protobuf_ListValue* = ref google_protobuf_ListValueObj google_protobuf_ListValueObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] values: seq[google_protobuf_Value] proc writegoogle_protobuf_Struct_FieldsEntryKV(stream: ProtobufStream, key: string, value: google_protobuf_Value) @@ -35,16 +38,19 @@ proc readgoogle_protobuf_Struct_FieldsEntryKV(stream: ProtobufStream, tbl: Table proc sizeOfgoogle_protobuf_Struct_FieldsEntryKV(key: string, value: google_protobuf_Value): uint64 proc newgoogle_protobuf_Struct*(): google_protobuf_Struct +proc newgoogle_protobuf_Struct*(data: string): google_protobuf_Struct proc writegoogle_protobuf_Struct*(stream: ProtobufStream, message: google_protobuf_Struct) proc readgoogle_protobuf_Struct*(stream: ProtobufStream): google_protobuf_Struct proc sizeOfgoogle_protobuf_Struct*(message: google_protobuf_Struct): uint64 proc newgoogle_protobuf_ListValue*(): google_protobuf_ListValue +proc newgoogle_protobuf_ListValue*(data: string): google_protobuf_ListValue proc writegoogle_protobuf_ListValue*(stream: ProtobufStream, message: google_protobuf_ListValue) proc readgoogle_protobuf_ListValue*(stream: ProtobufStream): google_protobuf_ListValue proc sizeOfgoogle_protobuf_ListValue*(message: google_protobuf_ListValue): uint64 proc newgoogle_protobuf_Value*(): google_protobuf_Value +proc newgoogle_protobuf_Value*(data: string): google_protobuf_Value proc writegoogle_protobuf_Value*(stream: ProtobufStream, message: google_protobuf_Value) proc readgoogle_protobuf_Value*(stream: ProtobufStream): google_protobuf_Value proc sizeOfgoogle_protobuf_Value*(message: google_protobuf_Value): uint64 @@ -82,15 +88,16 @@ proc readgoogle_protobuf_Struct_FieldsEntryKV(stream: ProtobufStream, tbl: Table gotValue = true else: skipField(stream, wireType) if not gotKey: - raise newException(Exception, "missing key (google_protobuf_Struct_FieldsEntry)") + raise newException(Exception, "missing key") if not gotValue: - raise newException(Exception, "missing value (google_protobuf_Struct_FieldsEntry)") + raise newException(Exception, "missing value") tbl[key] = value proc newgoogle_protobuf_Struct*(): google_protobuf_Struct = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.fields = newTable[string, google_protobuf_Value]() proc clearfields*(message: google_protobuf_Struct) = @@ -117,12 +124,15 @@ proc sizeOfgoogle_protobuf_Struct*(message: google_protobuf_Struct): uint64 = sizeOfKV = sizeOfKV + sizeOfgoogle_protobuf_Struct_FieldsEntryKV(key, value) result = result + sizeOfTag(1, WireType.LengthDelimited) result = result + sizeOfLengthDelimited(sizeOfKV) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_Struct*(stream: ProtobufStream, message: google_protobuf_Struct) = for key, value in message.fields: writeTag(stream, 1, WireType.LengthDelimited) writeVarint(stream, sizeOfgoogle_protobuf_Struct_FieldsEntryKV(key, value)) writegoogle_protobuf_Struct_FieldsEntryKV(stream, key, value) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_Struct*(stream: ProtobufStream): google_protobuf_Struct = result = newgoogle_protobuf_Struct() @@ -140,7 +150,7 @@ proc readgoogle_protobuf_Struct*(stream: ProtobufStream): google_protobuf_Struct data = safeReadStr(stream, int(size)) pbs = newProtobufStream(newStringStream(data)) readgoogle_protobuf_Struct_FieldsEntryKV(pbs, result.fields) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_Struct): string = let @@ -159,6 +169,7 @@ proc newgoogle_protobuf_Struct*(data: string): google_protobuf_Struct = proc newgoogle_protobuf_ListValue*(): google_protobuf_ListValue = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.values = @[] proc clearvalues*(message: google_protobuf_ListValue) = @@ -186,10 +197,13 @@ proc sizeOfgoogle_protobuf_ListValue*(message: google_protobuf_ListValue): uint6 for value in message.values: result = result + sizeOfTag(1, WireType.LengthDelimited) result = result + sizeOfLengthDelimited(sizeOfgoogle_protobuf_Value(value)) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_ListValue*(stream: ProtobufStream, message: google_protobuf_ListValue) = for value in message.values: writeMessage(stream, value, 1) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_ListValue*(stream: ProtobufStream): google_protobuf_ListValue = result = newgoogle_protobuf_ListValue() @@ -202,12 +216,9 @@ proc readgoogle_protobuf_ListValue*(stream: ProtobufStream): google_protobuf_Lis raise newException(InvalidFieldNumberError, "Invalid field number: 0") of 1: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - addvalues(result, readgoogle_protobuf_Value(pbs)) - else: skipField(stream, wireType) + let data = readLengthDelimited(stream) + addvalues(result, newgoogle_protobuf_Value(data)) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_ListValue): string = let @@ -226,7 +237,8 @@ proc newgoogle_protobuf_ListValue*(data: string): google_protobuf_ListValue = proc newgoogle_protobuf_Value*(): google_protobuf_Value = new(result) result.hasField = initIntSet() - result.kind.null_value = google_protobuf_NullValue(0) + result.unknownFields = @[] + result.kind.null_value = google_protobuf_NullValue.NULL_VALUE result.kind.number_value = 0 result.kind.string_value = "" result.kind.bool_value = false @@ -234,7 +246,7 @@ proc newgoogle_protobuf_Value*(): google_protobuf_Value = result.kind.list_value = nil proc clearnull_value*(message: google_protobuf_Value) = - message.kind.null_value = google_protobuf_NullValue(0) + message.kind.null_value = google_protobuf_NullValue.NULL_VALUE excl(message.hasField, [1, 2, 3, 4, 5, 6]) proc hasnull_value*(message: google_protobuf_Value): bool = @@ -360,6 +372,8 @@ proc sizeOfgoogle_protobuf_Value*(message: google_protobuf_Value): uint64 = if haslist_value(message): result = result + sizeOfTag(6, WireType.LengthDelimited) result = result + sizeOfLengthDelimited(sizeOfgoogle_protobuf_ListValue(message.kind.list_value)) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_Value*(stream: ProtobufStream, message: google_protobuf_Value) = if hasnull_value(message): @@ -374,6 +388,7 @@ proc writegoogle_protobuf_Value*(stream: ProtobufStream, message: google_protobu writeMessage(stream, message.kind.struct_value, 5) if haslist_value(message): writeMessage(stream, message.kind.list_value, 6) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_Value*(stream: ProtobufStream): google_protobuf_Value = result = newgoogle_protobuf_Value() @@ -398,19 +413,13 @@ proc readgoogle_protobuf_Value*(stream: ProtobufStream): google_protobuf_Value = setbool_value(result, readBool(stream)) of 5: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - setstruct_value(result, readgoogle_protobuf_Struct(pbs)) + let data = readLengthDelimited(stream) + setstruct_value(result, newgoogle_protobuf_Struct(data)) of 6: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - setlist_value(result, readgoogle_protobuf_ListValue(pbs)) - else: skipField(stream, wireType) + let data = readLengthDelimited(stream) + setlist_value(result, newgoogle_protobuf_ListValue(data)) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_Value): string = let diff --git a/src/nimpb/wkt/timestamp_pb.nim b/src/nimpb/wkt/timestamp_pb.nim index 3e7d4e7..bddbd55 100644 --- a/src/nimpb/wkt/timestamp_pb.nim +++ b/src/nimpb/wkt/timestamp_pb.nim @@ -8,10 +8,12 @@ type google_protobuf_Timestamp* = ref google_protobuf_TimestampObj google_protobuf_TimestampObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] seconds: int64 nanos: int32 proc newgoogle_protobuf_Timestamp*(): google_protobuf_Timestamp +proc newgoogle_protobuf_Timestamp*(data: string): google_protobuf_Timestamp proc writegoogle_protobuf_Timestamp*(stream: ProtobufStream, message: google_protobuf_Timestamp) proc readgoogle_protobuf_Timestamp*(stream: ProtobufStream): google_protobuf_Timestamp proc sizeOfgoogle_protobuf_Timestamp*(message: google_protobuf_Timestamp): uint64 @@ -19,6 +21,7 @@ proc sizeOfgoogle_protobuf_Timestamp*(message: google_protobuf_Timestamp): uint6 proc newgoogle_protobuf_Timestamp*(): google_protobuf_Timestamp = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.seconds = 0 result.nanos = 0 @@ -63,12 +66,15 @@ proc sizeOfgoogle_protobuf_Timestamp*(message: google_protobuf_Timestamp): uint6 if hasnanos(message): result = result + sizeOfTag(2, WireType.Varint) result = result + sizeOfInt32(message.nanos) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_Timestamp*(stream: ProtobufStream, message: google_protobuf_Timestamp) = if hasseconds(message): writeInt64(stream, message.seconds, 1) if hasnanos(message): writeInt32(stream, message.nanos, 2) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_Timestamp*(stream: ProtobufStream): google_protobuf_Timestamp = result = newgoogle_protobuf_Timestamp() @@ -85,7 +91,7 @@ proc readgoogle_protobuf_Timestamp*(stream: ProtobufStream): google_protobuf_Tim of 2: expectWireType(wireType, WireType.Varint) setnanos(result, readInt32(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_Timestamp): string = let diff --git a/src/nimpb/wkt/type_pb.nim b/src/nimpb/wkt/type_pb.nim index 00889e3..153f257 100644 --- a/src/nimpb/wkt/type_pb.nim +++ b/src/nimpb/wkt/type_pb.nim @@ -39,6 +39,7 @@ type google_protobuf_Type* = ref google_protobuf_TypeObj google_protobuf_TypeObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] name: string fields: seq[google_protobuf_Field] oneofs: seq[string] @@ -48,6 +49,7 @@ type google_protobuf_Field* = ref google_protobuf_FieldObj google_protobuf_FieldObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] kind: google_protobuf_Field_Kind cardinality: google_protobuf_Field_Cardinality number: int32 @@ -61,6 +63,7 @@ type google_protobuf_Enum* = ref google_protobuf_EnumObj google_protobuf_EnumObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] name: string enumvalue: seq[google_protobuf_EnumValue] options: seq[google_protobuf_Option] @@ -69,36 +72,43 @@ type google_protobuf_EnumValue* = ref google_protobuf_EnumValueObj google_protobuf_EnumValueObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] name: string number: int32 options: seq[google_protobuf_Option] google_protobuf_Option* = ref google_protobuf_OptionObj google_protobuf_OptionObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] name: string value: google_protobuf_Any proc newgoogle_protobuf_Option*(): google_protobuf_Option +proc newgoogle_protobuf_Option*(data: string): google_protobuf_Option proc writegoogle_protobuf_Option*(stream: ProtobufStream, message: google_protobuf_Option) proc readgoogle_protobuf_Option*(stream: ProtobufStream): google_protobuf_Option proc sizeOfgoogle_protobuf_Option*(message: google_protobuf_Option): uint64 proc newgoogle_protobuf_Field*(): google_protobuf_Field +proc newgoogle_protobuf_Field*(data: string): google_protobuf_Field proc writegoogle_protobuf_Field*(stream: ProtobufStream, message: google_protobuf_Field) proc readgoogle_protobuf_Field*(stream: ProtobufStream): google_protobuf_Field proc sizeOfgoogle_protobuf_Field*(message: google_protobuf_Field): uint64 proc newgoogle_protobuf_Type*(): google_protobuf_Type +proc newgoogle_protobuf_Type*(data: string): google_protobuf_Type proc writegoogle_protobuf_Type*(stream: ProtobufStream, message: google_protobuf_Type) proc readgoogle_protobuf_Type*(stream: ProtobufStream): google_protobuf_Type proc sizeOfgoogle_protobuf_Type*(message: google_protobuf_Type): uint64 proc newgoogle_protobuf_EnumValue*(): google_protobuf_EnumValue +proc newgoogle_protobuf_EnumValue*(data: string): google_protobuf_EnumValue proc writegoogle_protobuf_EnumValue*(stream: ProtobufStream, message: google_protobuf_EnumValue) proc readgoogle_protobuf_EnumValue*(stream: ProtobufStream): google_protobuf_EnumValue proc sizeOfgoogle_protobuf_EnumValue*(message: google_protobuf_EnumValue): uint64 proc newgoogle_protobuf_Enum*(): google_protobuf_Enum +proc newgoogle_protobuf_Enum*(data: string): google_protobuf_Enum proc writegoogle_protobuf_Enum*(stream: ProtobufStream, message: google_protobuf_Enum) proc readgoogle_protobuf_Enum*(stream: ProtobufStream): google_protobuf_Enum proc sizeOfgoogle_protobuf_Enum*(message: google_protobuf_Enum): uint64 @@ -106,6 +116,7 @@ proc sizeOfgoogle_protobuf_Enum*(message: google_protobuf_Enum): uint64 proc newgoogle_protobuf_Option*(): google_protobuf_Option = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.name = "" result.value = nil @@ -150,12 +161,15 @@ proc sizeOfgoogle_protobuf_Option*(message: google_protobuf_Option): uint64 = if hasvalue(message): result = result + sizeOfTag(2, WireType.LengthDelimited) result = result + sizeOfLengthDelimited(sizeOfgoogle_protobuf_Any(message.value)) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_Option*(stream: ProtobufStream, message: google_protobuf_Option) = if hasname(message): writeString(stream, message.name, 1) if hasvalue(message): writeMessage(stream, message.value, 2) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_Option*(stream: ProtobufStream): google_protobuf_Option = result = newgoogle_protobuf_Option() @@ -171,12 +185,9 @@ proc readgoogle_protobuf_Option*(stream: ProtobufStream): google_protobuf_Option setname(result, readString(stream)) of 2: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - setvalue(result, readgoogle_protobuf_Any(pbs)) - else: skipField(stream, wireType) + let data = readLengthDelimited(stream) + setvalue(result, newgoogle_protobuf_Any(data)) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_Option): string = let @@ -195,8 +206,9 @@ proc newgoogle_protobuf_Option*(data: string): google_protobuf_Option = proc newgoogle_protobuf_Field*(): google_protobuf_Field = new(result) result.hasField = initIntSet() - result.kind = google_protobuf_Field_Kind(0) - result.cardinality = google_protobuf_Field_Cardinality(0) + result.unknownFields = @[] + result.kind = google_protobuf_Field_Kind.TYPE_UNKNOWN + result.cardinality = google_protobuf_Field_Cardinality.CARDINALITY_UNKNOWN result.number = 0 result.name = "" result.type_url = "" @@ -207,7 +219,7 @@ proc newgoogle_protobuf_Field*(): google_protobuf_Field = result.default_value = "" proc clearkind*(message: google_protobuf_Field) = - message.kind = google_protobuf_Field_Kind(0) + message.kind = google_protobuf_Field_Kind.TYPE_UNKNOWN excl(message.hasField, [1]) proc haskind*(message: google_protobuf_Field): bool = @@ -224,7 +236,7 @@ proc `kind=`*(message: google_protobuf_Field, value: google_protobuf_Field_Kind) setkind(message, value) proc clearcardinality*(message: google_protobuf_Field) = - message.cardinality = google_protobuf_Field_Cardinality(0) + message.cardinality = google_protobuf_Field_Cardinality.CARDINALITY_UNKNOWN excl(message.hasField, [2]) proc hascardinality*(message: google_protobuf_Field): bool = @@ -411,6 +423,8 @@ proc sizeOfgoogle_protobuf_Field*(message: google_protobuf_Field): uint64 = if hasdefault_value(message): result = result + sizeOfTag(11, WireType.LengthDelimited) result = result + sizeOfString(message.default_value) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_Field*(stream: ProtobufStream, message: google_protobuf_Field) = if haskind(message): @@ -433,6 +447,7 @@ proc writegoogle_protobuf_Field*(stream: ProtobufStream, message: google_protobu writeString(stream, message.json_name, 10) if hasdefault_value(message): writeString(stream, message.default_value, 11) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_Field*(stream: ProtobufStream): google_protobuf_Field = result = newgoogle_protobuf_Field() @@ -466,18 +481,15 @@ proc readgoogle_protobuf_Field*(stream: ProtobufStream): google_protobuf_Field = setpacked(result, readBool(stream)) of 9: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - addoptions(result, readgoogle_protobuf_Option(pbs)) + let data = readLengthDelimited(stream) + addoptions(result, newgoogle_protobuf_Option(data)) of 10: expectWireType(wireType, WireType.LengthDelimited) setjson_name(result, readString(stream)) of 11: expectWireType(wireType, WireType.LengthDelimited) setdefault_value(result, readString(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_Field): string = let @@ -496,12 +508,13 @@ proc newgoogle_protobuf_Field*(data: string): google_protobuf_Field = proc newgoogle_protobuf_Type*(): google_protobuf_Type = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.name = "" result.fields = @[] result.oneofs = @[] result.options = @[] result.source_context = nil - result.syntax = google_protobuf_Syntax(0) + result.syntax = google_protobuf_Syntax.SYNTAX_PROTO2 proc clearname*(message: google_protobuf_Type) = message.name = "" @@ -601,7 +614,7 @@ proc `source_context=`*(message: google_protobuf_Type, value: google_protobuf_So setsource_context(message, value) proc clearsyntax*(message: google_protobuf_Type) = - message.syntax = google_protobuf_Syntax(0) + message.syntax = google_protobuf_Syntax.SYNTAX_PROTO2 excl(message.hasField, [6]) proc hassyntax*(message: google_protobuf_Type): bool = @@ -636,6 +649,8 @@ proc sizeOfgoogle_protobuf_Type*(message: google_protobuf_Type): uint64 = if hassyntax(message): result = result + sizeOfTag(6, WireType.Varint) result = result + sizeOfEnum[google_protobuf_Syntax](message.syntax) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_Type*(stream: ProtobufStream, message: google_protobuf_Type) = if hasname(message): @@ -650,6 +665,7 @@ proc writegoogle_protobuf_Type*(stream: ProtobufStream, message: google_protobuf writeMessage(stream, message.source_context, 5) if hassyntax(message): writeEnum(stream, message.syntax, 6) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_Type*(stream: ProtobufStream): google_protobuf_Type = result = newgoogle_protobuf_Type() @@ -665,32 +681,23 @@ proc readgoogle_protobuf_Type*(stream: ProtobufStream): google_protobuf_Type = setname(result, readString(stream)) of 2: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - addfields(result, readgoogle_protobuf_Field(pbs)) + let data = readLengthDelimited(stream) + addfields(result, newgoogle_protobuf_Field(data)) of 3: expectWireType(wireType, WireType.LengthDelimited) addoneofs(result, readString(stream)) of 4: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - addoptions(result, readgoogle_protobuf_Option(pbs)) + let data = readLengthDelimited(stream) + addoptions(result, newgoogle_protobuf_Option(data)) of 5: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - setsource_context(result, readgoogle_protobuf_SourceContext(pbs)) + let data = readLengthDelimited(stream) + setsource_context(result, newgoogle_protobuf_SourceContext(data)) of 6: expectWireType(wireType, WireType.Varint) setsyntax(result, readEnum[google_protobuf_Syntax](stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_Type): string = let @@ -709,6 +716,7 @@ proc newgoogle_protobuf_Type*(data: string): google_protobuf_Type = proc newgoogle_protobuf_EnumValue*(): google_protobuf_EnumValue = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.name = "" result.number = 0 result.options = @[] @@ -778,6 +786,8 @@ proc sizeOfgoogle_protobuf_EnumValue*(message: google_protobuf_EnumValue): uint6 for value in message.options: result = result + sizeOfTag(3, WireType.LengthDelimited) result = result + sizeOfLengthDelimited(sizeOfgoogle_protobuf_Option(value)) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_EnumValue*(stream: ProtobufStream, message: google_protobuf_EnumValue) = if hasname(message): @@ -786,6 +796,7 @@ proc writegoogle_protobuf_EnumValue*(stream: ProtobufStream, message: google_pro writeInt32(stream, message.number, 2) for value in message.options: writeMessage(stream, value, 3) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_EnumValue*(stream: ProtobufStream): google_protobuf_EnumValue = result = newgoogle_protobuf_EnumValue() @@ -804,12 +815,9 @@ proc readgoogle_protobuf_EnumValue*(stream: ProtobufStream): google_protobuf_Enu setnumber(result, readInt32(stream)) of 3: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - addoptions(result, readgoogle_protobuf_Option(pbs)) - else: skipField(stream, wireType) + let data = readLengthDelimited(stream) + addoptions(result, newgoogle_protobuf_Option(data)) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_EnumValue): string = let @@ -828,11 +836,12 @@ proc newgoogle_protobuf_EnumValue*(data: string): google_protobuf_EnumValue = proc newgoogle_protobuf_Enum*(): google_protobuf_Enum = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.name = "" result.enumvalue = @[] result.options = @[] result.source_context = nil - result.syntax = google_protobuf_Syntax(0) + result.syntax = google_protobuf_Syntax.SYNTAX_PROTO2 proc clearname*(message: google_protobuf_Enum) = message.name = "" @@ -911,7 +920,7 @@ proc `source_context=`*(message: google_protobuf_Enum, value: google_protobuf_So setsource_context(message, value) proc clearsyntax*(message: google_protobuf_Enum) = - message.syntax = google_protobuf_Syntax(0) + message.syntax = google_protobuf_Syntax.SYNTAX_PROTO2 excl(message.hasField, [5]) proc hassyntax*(message: google_protobuf_Enum): bool = @@ -943,6 +952,8 @@ proc sizeOfgoogle_protobuf_Enum*(message: google_protobuf_Enum): uint64 = if hassyntax(message): result = result + sizeOfTag(5, WireType.Varint) result = result + sizeOfEnum[google_protobuf_Syntax](message.syntax) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_Enum*(stream: ProtobufStream, message: google_protobuf_Enum) = if hasname(message): @@ -955,6 +966,7 @@ proc writegoogle_protobuf_Enum*(stream: ProtobufStream, message: google_protobuf writeMessage(stream, message.source_context, 4) if hassyntax(message): writeEnum(stream, message.syntax, 5) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_Enum*(stream: ProtobufStream): google_protobuf_Enum = result = newgoogle_protobuf_Enum() @@ -970,29 +982,20 @@ proc readgoogle_protobuf_Enum*(stream: ProtobufStream): google_protobuf_Enum = setname(result, readString(stream)) of 2: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - addenumvalue(result, readgoogle_protobuf_EnumValue(pbs)) + let data = readLengthDelimited(stream) + addenumvalue(result, newgoogle_protobuf_EnumValue(data)) of 3: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - addoptions(result, readgoogle_protobuf_Option(pbs)) + let data = readLengthDelimited(stream) + addoptions(result, newgoogle_protobuf_Option(data)) of 4: expectWireType(wireType, WireType.LengthDelimited) - let - size = readVarint(stream) - data = safeReadStr(stream, int(size)) - pbs = newProtobufStream(newStringStream(data)) - setsource_context(result, readgoogle_protobuf_SourceContext(pbs)) + let data = readLengthDelimited(stream) + setsource_context(result, newgoogle_protobuf_SourceContext(data)) of 5: expectWireType(wireType, WireType.Varint) setsyntax(result, readEnum[google_protobuf_Syntax](stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_Enum): string = let diff --git a/src/nimpb/wkt/wrappers_pb.nim b/src/nimpb/wkt/wrappers_pb.nim index 80e6160..296f5f4 100644 --- a/src/nimpb/wkt/wrappers_pb.nim +++ b/src/nimpb/wkt/wrappers_pb.nim @@ -8,81 +8,99 @@ type google_protobuf_DoubleValue* = ref google_protobuf_DoubleValueObj google_protobuf_DoubleValueObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] value: float64 google_protobuf_FloatValue* = ref google_protobuf_FloatValueObj google_protobuf_FloatValueObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] value: float32 google_protobuf_Int64Value* = ref google_protobuf_Int64ValueObj google_protobuf_Int64ValueObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] value: int64 google_protobuf_UInt64Value* = ref google_protobuf_UInt64ValueObj google_protobuf_UInt64ValueObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] value: uint64 google_protobuf_Int32Value* = ref google_protobuf_Int32ValueObj google_protobuf_Int32ValueObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] value: int32 google_protobuf_UInt32Value* = ref google_protobuf_UInt32ValueObj google_protobuf_UInt32ValueObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] value: uint32 google_protobuf_BoolValue* = ref google_protobuf_BoolValueObj google_protobuf_BoolValueObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] value: bool google_protobuf_StringValue* = ref google_protobuf_StringValueObj google_protobuf_StringValueObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] value: string google_protobuf_BytesValue* = ref google_protobuf_BytesValueObj google_protobuf_BytesValueObj* = object of RootObj hasField: IntSet + unknownFields: seq[UnknownField] value: bytes proc newgoogle_protobuf_Int32Value*(): google_protobuf_Int32Value +proc newgoogle_protobuf_Int32Value*(data: string): google_protobuf_Int32Value proc writegoogle_protobuf_Int32Value*(stream: ProtobufStream, message: google_protobuf_Int32Value) proc readgoogle_protobuf_Int32Value*(stream: ProtobufStream): google_protobuf_Int32Value proc sizeOfgoogle_protobuf_Int32Value*(message: google_protobuf_Int32Value): uint64 proc newgoogle_protobuf_Int64Value*(): google_protobuf_Int64Value +proc newgoogle_protobuf_Int64Value*(data: string): google_protobuf_Int64Value proc writegoogle_protobuf_Int64Value*(stream: ProtobufStream, message: google_protobuf_Int64Value) proc readgoogle_protobuf_Int64Value*(stream: ProtobufStream): google_protobuf_Int64Value proc sizeOfgoogle_protobuf_Int64Value*(message: google_protobuf_Int64Value): uint64 proc newgoogle_protobuf_DoubleValue*(): google_protobuf_DoubleValue +proc newgoogle_protobuf_DoubleValue*(data: string): google_protobuf_DoubleValue proc writegoogle_protobuf_DoubleValue*(stream: ProtobufStream, message: google_protobuf_DoubleValue) proc readgoogle_protobuf_DoubleValue*(stream: ProtobufStream): google_protobuf_DoubleValue proc sizeOfgoogle_protobuf_DoubleValue*(message: google_protobuf_DoubleValue): uint64 proc newgoogle_protobuf_StringValue*(): google_protobuf_StringValue +proc newgoogle_protobuf_StringValue*(data: string): google_protobuf_StringValue proc writegoogle_protobuf_StringValue*(stream: ProtobufStream, message: google_protobuf_StringValue) proc readgoogle_protobuf_StringValue*(stream: ProtobufStream): google_protobuf_StringValue proc sizeOfgoogle_protobuf_StringValue*(message: google_protobuf_StringValue): uint64 proc newgoogle_protobuf_BoolValue*(): google_protobuf_BoolValue +proc newgoogle_protobuf_BoolValue*(data: string): google_protobuf_BoolValue proc writegoogle_protobuf_BoolValue*(stream: ProtobufStream, message: google_protobuf_BoolValue) proc readgoogle_protobuf_BoolValue*(stream: ProtobufStream): google_protobuf_BoolValue proc sizeOfgoogle_protobuf_BoolValue*(message: google_protobuf_BoolValue): uint64 proc newgoogle_protobuf_BytesValue*(): google_protobuf_BytesValue +proc newgoogle_protobuf_BytesValue*(data: string): google_protobuf_BytesValue proc writegoogle_protobuf_BytesValue*(stream: ProtobufStream, message: google_protobuf_BytesValue) proc readgoogle_protobuf_BytesValue*(stream: ProtobufStream): google_protobuf_BytesValue proc sizeOfgoogle_protobuf_BytesValue*(message: google_protobuf_BytesValue): uint64 proc newgoogle_protobuf_FloatValue*(): google_protobuf_FloatValue +proc newgoogle_protobuf_FloatValue*(data: string): google_protobuf_FloatValue proc writegoogle_protobuf_FloatValue*(stream: ProtobufStream, message: google_protobuf_FloatValue) proc readgoogle_protobuf_FloatValue*(stream: ProtobufStream): google_protobuf_FloatValue proc sizeOfgoogle_protobuf_FloatValue*(message: google_protobuf_FloatValue): uint64 proc newgoogle_protobuf_UInt64Value*(): google_protobuf_UInt64Value +proc newgoogle_protobuf_UInt64Value*(data: string): google_protobuf_UInt64Value proc writegoogle_protobuf_UInt64Value*(stream: ProtobufStream, message: google_protobuf_UInt64Value) proc readgoogle_protobuf_UInt64Value*(stream: ProtobufStream): google_protobuf_UInt64Value proc sizeOfgoogle_protobuf_UInt64Value*(message: google_protobuf_UInt64Value): uint64 proc newgoogle_protobuf_UInt32Value*(): google_protobuf_UInt32Value +proc newgoogle_protobuf_UInt32Value*(data: string): google_protobuf_UInt32Value proc writegoogle_protobuf_UInt32Value*(stream: ProtobufStream, message: google_protobuf_UInt32Value) proc readgoogle_protobuf_UInt32Value*(stream: ProtobufStream): google_protobuf_UInt32Value proc sizeOfgoogle_protobuf_UInt32Value*(message: google_protobuf_UInt32Value): uint64 @@ -90,6 +108,7 @@ proc sizeOfgoogle_protobuf_UInt32Value*(message: google_protobuf_UInt32Value): u proc newgoogle_protobuf_Int32Value*(): google_protobuf_Int32Value = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.value = 0 proc clearvalue*(message: google_protobuf_Int32Value) = @@ -113,10 +132,13 @@ proc sizeOfgoogle_protobuf_Int32Value*(message: google_protobuf_Int32Value): uin if hasvalue(message): result = result + sizeOfTag(1, WireType.Varint) result = result + sizeOfInt32(message.value) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_Int32Value*(stream: ProtobufStream, message: google_protobuf_Int32Value) = if hasvalue(message): writeInt32(stream, message.value, 1) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_Int32Value*(stream: ProtobufStream): google_protobuf_Int32Value = result = newgoogle_protobuf_Int32Value() @@ -130,7 +152,7 @@ proc readgoogle_protobuf_Int32Value*(stream: ProtobufStream): google_protobuf_In of 1: expectWireType(wireType, WireType.Varint) setvalue(result, readInt32(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_Int32Value): string = let @@ -149,6 +171,7 @@ proc newgoogle_protobuf_Int32Value*(data: string): google_protobuf_Int32Value = proc newgoogle_protobuf_Int64Value*(): google_protobuf_Int64Value = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.value = 0 proc clearvalue*(message: google_protobuf_Int64Value) = @@ -172,10 +195,13 @@ proc sizeOfgoogle_protobuf_Int64Value*(message: google_protobuf_Int64Value): uin if hasvalue(message): result = result + sizeOfTag(1, WireType.Varint) result = result + sizeOfInt64(message.value) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_Int64Value*(stream: ProtobufStream, message: google_protobuf_Int64Value) = if hasvalue(message): writeInt64(stream, message.value, 1) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_Int64Value*(stream: ProtobufStream): google_protobuf_Int64Value = result = newgoogle_protobuf_Int64Value() @@ -189,7 +215,7 @@ proc readgoogle_protobuf_Int64Value*(stream: ProtobufStream): google_protobuf_In of 1: expectWireType(wireType, WireType.Varint) setvalue(result, readInt64(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_Int64Value): string = let @@ -208,6 +234,7 @@ proc newgoogle_protobuf_Int64Value*(data: string): google_protobuf_Int64Value = proc newgoogle_protobuf_DoubleValue*(): google_protobuf_DoubleValue = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.value = 0 proc clearvalue*(message: google_protobuf_DoubleValue) = @@ -231,10 +258,13 @@ proc sizeOfgoogle_protobuf_DoubleValue*(message: google_protobuf_DoubleValue): u if hasvalue(message): result = result + sizeOfTag(1, WireType.Fixed64) result = result + sizeOfDouble(message.value) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_DoubleValue*(stream: ProtobufStream, message: google_protobuf_DoubleValue) = if hasvalue(message): writeDouble(stream, message.value, 1) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_DoubleValue*(stream: ProtobufStream): google_protobuf_DoubleValue = result = newgoogle_protobuf_DoubleValue() @@ -248,7 +278,7 @@ proc readgoogle_protobuf_DoubleValue*(stream: ProtobufStream): google_protobuf_D of 1: expectWireType(wireType, WireType.Fixed64) setvalue(result, readDouble(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_DoubleValue): string = let @@ -267,6 +297,7 @@ proc newgoogle_protobuf_DoubleValue*(data: string): google_protobuf_DoubleValue proc newgoogle_protobuf_StringValue*(): google_protobuf_StringValue = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.value = "" proc clearvalue*(message: google_protobuf_StringValue) = @@ -290,10 +321,13 @@ proc sizeOfgoogle_protobuf_StringValue*(message: google_protobuf_StringValue): u if hasvalue(message): result = result + sizeOfTag(1, WireType.LengthDelimited) result = result + sizeOfString(message.value) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_StringValue*(stream: ProtobufStream, message: google_protobuf_StringValue) = if hasvalue(message): writeString(stream, message.value, 1) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_StringValue*(stream: ProtobufStream): google_protobuf_StringValue = result = newgoogle_protobuf_StringValue() @@ -307,7 +341,7 @@ proc readgoogle_protobuf_StringValue*(stream: ProtobufStream): google_protobuf_S of 1: expectWireType(wireType, WireType.LengthDelimited) setvalue(result, readString(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_StringValue): string = let @@ -326,6 +360,7 @@ proc newgoogle_protobuf_StringValue*(data: string): google_protobuf_StringValue proc newgoogle_protobuf_BoolValue*(): google_protobuf_BoolValue = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.value = false proc clearvalue*(message: google_protobuf_BoolValue) = @@ -349,10 +384,13 @@ proc sizeOfgoogle_protobuf_BoolValue*(message: google_protobuf_BoolValue): uint6 if hasvalue(message): result = result + sizeOfTag(1, WireType.Varint) result = result + sizeOfBool(message.value) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_BoolValue*(stream: ProtobufStream, message: google_protobuf_BoolValue) = if hasvalue(message): writeBool(stream, message.value, 1) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_BoolValue*(stream: ProtobufStream): google_protobuf_BoolValue = result = newgoogle_protobuf_BoolValue() @@ -366,7 +404,7 @@ proc readgoogle_protobuf_BoolValue*(stream: ProtobufStream): google_protobuf_Boo of 1: expectWireType(wireType, WireType.Varint) setvalue(result, readBool(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_BoolValue): string = let @@ -385,6 +423,7 @@ proc newgoogle_protobuf_BoolValue*(data: string): google_protobuf_BoolValue = proc newgoogle_protobuf_BytesValue*(): google_protobuf_BytesValue = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.value = bytes("") proc clearvalue*(message: google_protobuf_BytesValue) = @@ -408,10 +447,13 @@ proc sizeOfgoogle_protobuf_BytesValue*(message: google_protobuf_BytesValue): uin if hasvalue(message): result = result + sizeOfTag(1, WireType.LengthDelimited) result = result + sizeOfBytes(message.value) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_BytesValue*(stream: ProtobufStream, message: google_protobuf_BytesValue) = if hasvalue(message): writeBytes(stream, message.value, 1) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_BytesValue*(stream: ProtobufStream): google_protobuf_BytesValue = result = newgoogle_protobuf_BytesValue() @@ -425,7 +467,7 @@ proc readgoogle_protobuf_BytesValue*(stream: ProtobufStream): google_protobuf_By of 1: expectWireType(wireType, WireType.LengthDelimited) setvalue(result, readBytes(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_BytesValue): string = let @@ -444,6 +486,7 @@ proc newgoogle_protobuf_BytesValue*(data: string): google_protobuf_BytesValue = proc newgoogle_protobuf_FloatValue*(): google_protobuf_FloatValue = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.value = 0 proc clearvalue*(message: google_protobuf_FloatValue) = @@ -467,10 +510,13 @@ proc sizeOfgoogle_protobuf_FloatValue*(message: google_protobuf_FloatValue): uin if hasvalue(message): result = result + sizeOfTag(1, WireType.Fixed32) result = result + sizeOfFloat(message.value) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_FloatValue*(stream: ProtobufStream, message: google_protobuf_FloatValue) = if hasvalue(message): writeFloat(stream, message.value, 1) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_FloatValue*(stream: ProtobufStream): google_protobuf_FloatValue = result = newgoogle_protobuf_FloatValue() @@ -484,7 +530,7 @@ proc readgoogle_protobuf_FloatValue*(stream: ProtobufStream): google_protobuf_Fl of 1: expectWireType(wireType, WireType.Fixed32) setvalue(result, readFloat(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_FloatValue): string = let @@ -503,6 +549,7 @@ proc newgoogle_protobuf_FloatValue*(data: string): google_protobuf_FloatValue = proc newgoogle_protobuf_UInt64Value*(): google_protobuf_UInt64Value = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.value = 0 proc clearvalue*(message: google_protobuf_UInt64Value) = @@ -526,10 +573,13 @@ proc sizeOfgoogle_protobuf_UInt64Value*(message: google_protobuf_UInt64Value): u if hasvalue(message): result = result + sizeOfTag(1, WireType.Varint) result = result + sizeOfUInt64(message.value) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_UInt64Value*(stream: ProtobufStream, message: google_protobuf_UInt64Value) = if hasvalue(message): writeUInt64(stream, message.value, 1) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_UInt64Value*(stream: ProtobufStream): google_protobuf_UInt64Value = result = newgoogle_protobuf_UInt64Value() @@ -543,7 +593,7 @@ proc readgoogle_protobuf_UInt64Value*(stream: ProtobufStream): google_protobuf_U of 1: expectWireType(wireType, WireType.Varint) setvalue(result, readUInt64(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_UInt64Value): string = let @@ -562,6 +612,7 @@ proc newgoogle_protobuf_UInt64Value*(data: string): google_protobuf_UInt64Value proc newgoogle_protobuf_UInt32Value*(): google_protobuf_UInt32Value = new(result) result.hasField = initIntSet() + result.unknownFields = @[] result.value = 0 proc clearvalue*(message: google_protobuf_UInt32Value) = @@ -585,10 +636,13 @@ proc sizeOfgoogle_protobuf_UInt32Value*(message: google_protobuf_UInt32Value): u if hasvalue(message): result = result + sizeOfTag(1, WireType.Varint) result = result + sizeOfUInt32(message.value) + for field in message.unknownFields: + result = result + sizeOfUnknownField(field) proc writegoogle_protobuf_UInt32Value*(stream: ProtobufStream, message: google_protobuf_UInt32Value) = if hasvalue(message): writeUInt32(stream, message.value, 1) + writeUnknownFields(stream, message.unknownFields) proc readgoogle_protobuf_UInt32Value*(stream: ProtobufStream): google_protobuf_UInt32Value = result = newgoogle_protobuf_UInt32Value() @@ -602,7 +656,7 @@ proc readgoogle_protobuf_UInt32Value*(stream: ProtobufStream): google_protobuf_U of 1: expectWireType(wireType, WireType.Varint) setvalue(result, readUInt32(stream)) - else: skipField(stream, wireType) + else: readUnknownField(stream, tag, result.unknownFields) proc serialize*(message: google_protobuf_UInt32Value): string = let -- cgit v1.2.3