Damien Neil | 99f24c3 | 2019-03-13 17:06:42 -0700 | [diff] [blame^] | 1 | // Copyright 2018 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style. |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // Code generated by generate-types. DO NOT EDIT. |
| 6 | |
| 7 | package proto |
| 8 | |
| 9 | import ( |
| 10 | "math" |
| 11 | |
| 12 | "github.com/golang/protobuf/v2/internal/encoding/wire" |
| 13 | "github.com/golang/protobuf/v2/internal/errors" |
| 14 | "github.com/golang/protobuf/v2/reflect/protoreflect" |
| 15 | ) |
| 16 | |
| 17 | var wireTypes = map[protoreflect.Kind]wire.Type{ |
| 18 | protoreflect.BoolKind: wire.VarintType, |
| 19 | protoreflect.EnumKind: wire.VarintType, |
| 20 | protoreflect.Int32Kind: wire.VarintType, |
| 21 | protoreflect.Sint32Kind: wire.VarintType, |
| 22 | protoreflect.Uint32Kind: wire.VarintType, |
| 23 | protoreflect.Int64Kind: wire.VarintType, |
| 24 | protoreflect.Sint64Kind: wire.VarintType, |
| 25 | protoreflect.Uint64Kind: wire.VarintType, |
| 26 | protoreflect.Sfixed32Kind: wire.Fixed32Type, |
| 27 | protoreflect.Fixed32Kind: wire.Fixed32Type, |
| 28 | protoreflect.FloatKind: wire.Fixed32Type, |
| 29 | protoreflect.Sfixed64Kind: wire.Fixed64Type, |
| 30 | protoreflect.Fixed64Kind: wire.Fixed64Type, |
| 31 | protoreflect.DoubleKind: wire.Fixed64Type, |
| 32 | protoreflect.StringKind: wire.BytesType, |
| 33 | protoreflect.BytesKind: wire.BytesType, |
| 34 | protoreflect.MessageKind: wire.BytesType, |
| 35 | protoreflect.GroupKind: wire.StartGroupType, |
| 36 | } |
| 37 | |
| 38 | func (o MarshalOptions) marshalSingular(b []byte, num wire.Number, kind protoreflect.Kind, v protoreflect.Value) ([]byte, error) { |
| 39 | switch kind { |
| 40 | case protoreflect.BoolKind: |
| 41 | b = wire.AppendVarint(b, wire.EncodeBool(v.Bool())) |
| 42 | case protoreflect.EnumKind: |
| 43 | b = wire.AppendVarint(b, uint64(v.Enum())) |
| 44 | case protoreflect.Int32Kind: |
| 45 | b = wire.AppendVarint(b, uint64(int32(v.Int()))) |
| 46 | case protoreflect.Sint32Kind: |
| 47 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(int32(v.Int())))) |
| 48 | case protoreflect.Uint32Kind: |
| 49 | b = wire.AppendVarint(b, uint64(uint32(v.Uint()))) |
| 50 | case protoreflect.Int64Kind: |
| 51 | b = wire.AppendVarint(b, uint64(v.Int())) |
| 52 | case protoreflect.Sint64Kind: |
| 53 | b = wire.AppendVarint(b, wire.EncodeZigZag(v.Int())) |
| 54 | case protoreflect.Uint64Kind: |
| 55 | b = wire.AppendVarint(b, v.Uint()) |
| 56 | case protoreflect.Sfixed32Kind: |
| 57 | b = wire.AppendFixed32(b, uint32(v.Int())) |
| 58 | case protoreflect.Fixed32Kind: |
| 59 | b = wire.AppendFixed32(b, uint32(v.Uint())) |
| 60 | case protoreflect.FloatKind: |
| 61 | b = wire.AppendFixed32(b, math.Float32bits(float32(v.Float()))) |
| 62 | case protoreflect.Sfixed64Kind: |
| 63 | b = wire.AppendFixed64(b, uint64(v.Int())) |
| 64 | case protoreflect.Fixed64Kind: |
| 65 | b = wire.AppendFixed64(b, v.Uint()) |
| 66 | case protoreflect.DoubleKind: |
| 67 | b = wire.AppendFixed64(b, math.Float64bits(v.Float())) |
| 68 | case protoreflect.StringKind: |
| 69 | b = wire.AppendBytes(b, []byte(v.String())) |
| 70 | case protoreflect.BytesKind: |
| 71 | b = wire.AppendBytes(b, v.Bytes()) |
| 72 | case protoreflect.MessageKind: |
| 73 | var pos int |
| 74 | var err error |
| 75 | b, pos = appendSpeculativeLength(b) |
| 76 | b, err = o.marshalMessage(b, v.Message()) |
| 77 | if err != nil { |
| 78 | return nil, err |
| 79 | } |
| 80 | b = finishSpeculativeLength(b, pos) |
| 81 | case protoreflect.GroupKind: |
| 82 | var err error |
| 83 | b, err = o.marshalMessage(b, v.Message()) |
| 84 | if err != nil { |
| 85 | return nil, err |
| 86 | } |
| 87 | b = wire.AppendVarint(b, wire.EncodeTag(num, wire.EndGroupType)) |
| 88 | default: |
| 89 | return nil, errors.New("invalid kind %v", kind) |
| 90 | } |
| 91 | return b, nil |
| 92 | } |