diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2018-04-03 18:48:59 +0300 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2018-04-03 18:57:11 +0300 |
| commit | e2cfc6717ae8acd9c47a132fa2cbc8446b5920c5 (patch) | |
| tree | 98a6b22dab932f1f008b00b891b8b4a061a1bc9a /src/protobuf | |
| parent | 3c9ba205af26ed8d48e68a30932d18d8b64382e0 (diff) | |
| download | nimpb-e2cfc6717ae8acd9c47a132fa2cbc8446b5920c5.tar.gz nimpb-e2cfc6717ae8acd9c47a132fa2cbc8446b5920c5.zip | |
Rename stream.nim to protobuf.nim and merge with types.nim
Diffstat (limited to 'src/protobuf')
| -rw-r--r-- | src/protobuf/gen.nim | 2 | ||||
| -rw-r--r-- | src/protobuf/protobuf.nim (renamed from src/protobuf/stream.nim) | 63 | ||||
| -rw-r--r-- | src/protobuf/types.nim | 74 | ||||
| -rw-r--r-- | src/protobuf/wkt/any_pb.nim | 3 | ||||
| -rw-r--r-- | src/protobuf/wkt/api_pb.nim | 3 | ||||
| -rw-r--r-- | src/protobuf/wkt/duration_pb.nim | 3 | ||||
| -rw-r--r-- | src/protobuf/wkt/empty_pb.nim | 3 | ||||
| -rw-r--r-- | src/protobuf/wkt/field_mask_pb.nim | 3 | ||||
| -rw-r--r-- | src/protobuf/wkt/source_context_pb.nim | 3 | ||||
| -rw-r--r-- | src/protobuf/wkt/struct_pb.nim | 3 | ||||
| -rw-r--r-- | src/protobuf/wkt/timestamp_pb.nim | 3 | ||||
| -rw-r--r-- | src/protobuf/wkt/type_pb.nim | 3 | ||||
| -rw-r--r-- | src/protobuf/wkt/wrappers_pb.nim | 3 |
13 files changed, 72 insertions, 97 deletions
diff --git a/src/protobuf/gen.nim b/src/protobuf/gen.nim index ed6ee5a..039b6f7 100644 --- a/src/protobuf/gen.nim +++ b/src/protobuf/gen.nim @@ -1,7 +1,7 @@ import macros import strutils -import types +import protobuf type MessageDesc* = object diff --git a/src/protobuf/stream.nim b/src/protobuf/protobuf.nim index 824ad60..98bb7a4 100644 --- a/src/protobuf/stream.nim +++ b/src/protobuf/protobuf.nim @@ -2,8 +2,6 @@ import endians import streams import strutils -import types - export streams const @@ -25,6 +23,67 @@ type UnexpectedWireTypeError* = object of ParseError + bytes* = distinct string + + WireType* {.pure.} = enum + Varint = 0 + Fixed64 = 1 + LengthDelimited = 2 + StartGroup = 3 + EndGroup = 4 + Fixed32 = 5 + + FieldType* {.pure.} = enum + Double = 1 + Float + Int64 + UInt64 + Int32 + Fixed64 + Fixed32 + Bool + String + Group + Message + Bytes + UInt32 + Enum + SFixed32 + SFixed64 + SInt32 + SInt64 + +proc wiretype*(ft: FieldType): WireType = + case ft + of FieldType.Double: result = WireType.Fixed64 + of FieldType.Float: result = WireType.Fixed32 + of FieldType.Int64: result = WireType.Varint + of FieldType.UInt64: result = WireType.Varint + of FieldType.Int32: result = WireType.Varint + of FieldType.Fixed64: result = WireType.Fixed64 + of FieldType.Fixed32: result = WireType.Fixed32 + of FieldType.Bool: result = WireType.Varint + of FieldType.String: result = WireType.LengthDelimited + of FieldType.Group: result = WireType.LengthDelimited # ??? + of FieldType.Message: result = WireType.LengthDelimited + of FieldType.Bytes: result = WireType.LengthDelimited + of FieldType.UInt32: result = WireType.Varint + of FieldType.Enum: result = WireType.Varint + of FieldType.SFixed32: result = WireType.Fixed32 + of FieldType.SFixed64: result = WireType.Fixed64 + of FieldType.SInt32: result = WireType.Varint + of FieldType.SInt64: result = WireType.Varint + +proc isNumeric*(wiretype: WireType): bool = + case wiretype + of WireType.Varint: result = true + of WireType.Fixed64: result = true + of WireType.Fixed32: result = true + else: result = false + +proc isNumeric*(ft: FieldType): bool = + result = isNumeric(wiretype(ft)) + proc pbClose(s: Stream) = close(ProtobufStream(s).stream) ProtobufStream(s).stream = nil diff --git a/src/protobuf/types.nim b/src/protobuf/types.nim deleted file mode 100644 index c87524d..0000000 --- a/src/protobuf/types.nim +++ /dev/null @@ -1,74 +0,0 @@ -type - bytes* = distinct string - - # int32 # varint, no zigzag - # int64 # varint, no zigzag - # uint32 # varint, no zigzag - # uint64 # varint, no zigzag - # fixed32 # 32-bit uint - # fixed64 # 64-bit uint - # sfixed32 # 32-bit int - # sfixed64 # 64-bit int - # sint32 # varint, zigzag - # sint64 # varint, zigzag - # float32 # fixed32 - # float64 # fixed64 - - WireType* {.pure.} = enum - Varint = 0 - Fixed64 = 1 - LengthDelimited = 2 - StartGroup = 3 - EndGroup = 4 - Fixed32 = 5 - - FieldType* {.pure.} = enum - Double = 1 - Float - Int64 - UInt64 - Int32 - Fixed64 - Fixed32 - Bool - String - Group - Message - Bytes - UInt32 - Enum - SFixed32 - SFixed64 - SInt32 - SInt64 - -proc wiretype*(ft: FieldType): WireType = - case ft - of FieldType.Double: result = WireType.Fixed64 - of FieldType.Float: result = WireType.Fixed32 - of FieldType.Int64: result = WireType.Varint - of FieldType.UInt64: result = WireType.Varint - of FieldType.Int32: result = WireType.Varint - of FieldType.Fixed64: result = WireType.Fixed64 - of FieldType.Fixed32: result = WireType.Fixed32 - of FieldType.Bool: result = WireType.Varint - of FieldType.String: result = WireType.LengthDelimited - of FieldType.Group: result = WireType.LengthDelimited # ??? - of FieldType.Message: result = WireType.LengthDelimited - of FieldType.Bytes: result = WireType.LengthDelimited - of FieldType.UInt32: result = WireType.Varint - of FieldType.Enum: result = WireType.Varint - of FieldType.SFixed32: result = WireType.Fixed32 - of FieldType.SFixed64: result = WireType.Fixed64 - of FieldType.SInt32: result = WireType.Varint - of FieldType.SInt64: result = WireType.Varint - -proc isNumeric*(wiretype: WireType): bool = - case wiretype - of WireType.Varint: result = true - of WireType.Fixed64: result = true - of WireType.Fixed32: result = true - else: result = false - -proc isNumeric*(ft: FieldType): bool = - result = isNumeric(wiretype(ft)) diff --git a/src/protobuf/wkt/any_pb.nim b/src/protobuf/wkt/any_pb.nim index f7ef421..9704ae9 100644 --- a/src/protobuf/wkt/any_pb.nim +++ b/src/protobuf/wkt/any_pb.nim @@ -2,8 +2,7 @@ import intsets -import protobuf/stream -import protobuf/types +import protobuf/protobuf type google_protobuf_Any* = ref google_protobuf_AnyObj diff --git a/src/protobuf/wkt/api_pb.nim b/src/protobuf/wkt/api_pb.nim index 52a3e63..c6ca312 100644 --- a/src/protobuf/wkt/api_pb.nim +++ b/src/protobuf/wkt/api_pb.nim @@ -2,8 +2,7 @@ import intsets -import protobuf/stream -import protobuf/types +import protobuf/protobuf import protobuf/wkt/source_context_pb import protobuf/wkt/type_pb diff --git a/src/protobuf/wkt/duration_pb.nim b/src/protobuf/wkt/duration_pb.nim index c8f7926..1c72ec4 100644 --- a/src/protobuf/wkt/duration_pb.nim +++ b/src/protobuf/wkt/duration_pb.nim @@ -2,8 +2,7 @@ import intsets -import protobuf/stream -import protobuf/types +import protobuf/protobuf type google_protobuf_Duration* = ref google_protobuf_DurationObj diff --git a/src/protobuf/wkt/empty_pb.nim b/src/protobuf/wkt/empty_pb.nim index 862cb05..83885f4 100644 --- a/src/protobuf/wkt/empty_pb.nim +++ b/src/protobuf/wkt/empty_pb.nim @@ -2,8 +2,7 @@ import intsets -import protobuf/stream -import protobuf/types +import protobuf/protobuf type google_protobuf_Empty* = ref google_protobuf_EmptyObj diff --git a/src/protobuf/wkt/field_mask_pb.nim b/src/protobuf/wkt/field_mask_pb.nim index 4ca76f3..cb38f30 100644 --- a/src/protobuf/wkt/field_mask_pb.nim +++ b/src/protobuf/wkt/field_mask_pb.nim @@ -2,8 +2,7 @@ import intsets -import protobuf/stream -import protobuf/types +import protobuf/protobuf type google_protobuf_FieldMask* = ref google_protobuf_FieldMaskObj diff --git a/src/protobuf/wkt/source_context_pb.nim b/src/protobuf/wkt/source_context_pb.nim index 382927c..1fa135b 100644 --- a/src/protobuf/wkt/source_context_pb.nim +++ b/src/protobuf/wkt/source_context_pb.nim @@ -2,8 +2,7 @@ import intsets -import protobuf/stream -import protobuf/types +import protobuf/protobuf type google_protobuf_SourceContext* = ref google_protobuf_SourceContextObj diff --git a/src/protobuf/wkt/struct_pb.nim b/src/protobuf/wkt/struct_pb.nim index 9b272d2..bf3f07d 100644 --- a/src/protobuf/wkt/struct_pb.nim +++ b/src/protobuf/wkt/struct_pb.nim @@ -4,8 +4,7 @@ import intsets import tables export tables -import protobuf/stream -import protobuf/types +import protobuf/protobuf type google_protobuf_NullValue* {.pure.} = enum diff --git a/src/protobuf/wkt/timestamp_pb.nim b/src/protobuf/wkt/timestamp_pb.nim index 77fa52b..958a894 100644 --- a/src/protobuf/wkt/timestamp_pb.nim +++ b/src/protobuf/wkt/timestamp_pb.nim @@ -2,8 +2,7 @@ import intsets -import protobuf/stream -import protobuf/types +import protobuf/protobuf type google_protobuf_Timestamp* = ref google_protobuf_TimestampObj diff --git a/src/protobuf/wkt/type_pb.nim b/src/protobuf/wkt/type_pb.nim index b1b685c..ca25cd0 100644 --- a/src/protobuf/wkt/type_pb.nim +++ b/src/protobuf/wkt/type_pb.nim @@ -2,8 +2,7 @@ import intsets -import protobuf/stream -import protobuf/types +import protobuf/protobuf import protobuf/wkt/any_pb import protobuf/wkt/source_context_pb diff --git a/src/protobuf/wkt/wrappers_pb.nim b/src/protobuf/wkt/wrappers_pb.nim index 8cf1c69..873fcb7 100644 --- a/src/protobuf/wkt/wrappers_pb.nim +++ b/src/protobuf/wkt/wrappers_pb.nim @@ -2,8 +2,7 @@ import intsets -import protobuf/stream -import protobuf/types +import protobuf/protobuf type google_protobuf_DoubleValue* = ref google_protobuf_DoubleValueObj |
