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" |
Damien Neil | bc310b5 | 2019-04-11 11:46:55 -0700 | [diff] [blame] | 11 | "unicode/utf8" |
Damien Neil | 99f24c3 | 2019-03-13 17:06:42 -0700 | [diff] [blame] | 12 | |
Damien Neil | e89e624 | 2019-05-13 23:55:40 -0700 | [diff] [blame] | 13 | "google.golang.org/protobuf/internal/encoding/wire" |
| 14 | "google.golang.org/protobuf/internal/errors" |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 15 | "google.golang.org/protobuf/internal/strs" |
Damien Neil | e89e624 | 2019-05-13 23:55:40 -0700 | [diff] [blame] | 16 | "google.golang.org/protobuf/reflect/protoreflect" |
Damien Neil | 99f24c3 | 2019-03-13 17:06:42 -0700 | [diff] [blame] | 17 | ) |
| 18 | |
| 19 | var wireTypes = map[protoreflect.Kind]wire.Type{ |
| 20 | protoreflect.BoolKind: wire.VarintType, |
| 21 | protoreflect.EnumKind: wire.VarintType, |
| 22 | protoreflect.Int32Kind: wire.VarintType, |
| 23 | protoreflect.Sint32Kind: wire.VarintType, |
| 24 | protoreflect.Uint32Kind: wire.VarintType, |
| 25 | protoreflect.Int64Kind: wire.VarintType, |
| 26 | protoreflect.Sint64Kind: wire.VarintType, |
| 27 | protoreflect.Uint64Kind: wire.VarintType, |
| 28 | protoreflect.Sfixed32Kind: wire.Fixed32Type, |
| 29 | protoreflect.Fixed32Kind: wire.Fixed32Type, |
| 30 | protoreflect.FloatKind: wire.Fixed32Type, |
| 31 | protoreflect.Sfixed64Kind: wire.Fixed64Type, |
| 32 | protoreflect.Fixed64Kind: wire.Fixed64Type, |
| 33 | protoreflect.DoubleKind: wire.Fixed64Type, |
| 34 | protoreflect.StringKind: wire.BytesType, |
| 35 | protoreflect.BytesKind: wire.BytesType, |
| 36 | protoreflect.MessageKind: wire.BytesType, |
| 37 | protoreflect.GroupKind: wire.StartGroupType, |
| 38 | } |
| 39 | |
Joe Tsai | 378c132 | 2019-04-25 23:48:08 -0700 | [diff] [blame] | 40 | func (o MarshalOptions) marshalSingular(b []byte, fd protoreflect.FieldDescriptor, v protoreflect.Value) ([]byte, error) { |
Joe Tsai | 378c132 | 2019-04-25 23:48:08 -0700 | [diff] [blame] | 41 | switch fd.Kind() { |
Damien Neil | 99f24c3 | 2019-03-13 17:06:42 -0700 | [diff] [blame] | 42 | case protoreflect.BoolKind: |
| 43 | b = wire.AppendVarint(b, wire.EncodeBool(v.Bool())) |
| 44 | case protoreflect.EnumKind: |
| 45 | b = wire.AppendVarint(b, uint64(v.Enum())) |
| 46 | case protoreflect.Int32Kind: |
| 47 | b = wire.AppendVarint(b, uint64(int32(v.Int()))) |
| 48 | case protoreflect.Sint32Kind: |
| 49 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(int32(v.Int())))) |
| 50 | case protoreflect.Uint32Kind: |
| 51 | b = wire.AppendVarint(b, uint64(uint32(v.Uint()))) |
| 52 | case protoreflect.Int64Kind: |
| 53 | b = wire.AppendVarint(b, uint64(v.Int())) |
| 54 | case protoreflect.Sint64Kind: |
| 55 | b = wire.AppendVarint(b, wire.EncodeZigZag(v.Int())) |
| 56 | case protoreflect.Uint64Kind: |
| 57 | b = wire.AppendVarint(b, v.Uint()) |
| 58 | case protoreflect.Sfixed32Kind: |
| 59 | b = wire.AppendFixed32(b, uint32(v.Int())) |
| 60 | case protoreflect.Fixed32Kind: |
| 61 | b = wire.AppendFixed32(b, uint32(v.Uint())) |
| 62 | case protoreflect.FloatKind: |
| 63 | b = wire.AppendFixed32(b, math.Float32bits(float32(v.Float()))) |
| 64 | case protoreflect.Sfixed64Kind: |
| 65 | b = wire.AppendFixed64(b, uint64(v.Int())) |
| 66 | case protoreflect.Fixed64Kind: |
| 67 | b = wire.AppendFixed64(b, v.Uint()) |
| 68 | case protoreflect.DoubleKind: |
| 69 | b = wire.AppendFixed64(b, math.Float64bits(v.Float())) |
| 70 | case protoreflect.StringKind: |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 71 | if strs.EnforceUTF8(fd) && !utf8.ValidString(v.String()) { |
Damien Neil | 8c86fc5 | 2019-06-19 09:28:29 -0700 | [diff] [blame] | 72 | return b, errors.InvalidUTF8(string(fd.FullName())) |
Damien Neil | bc310b5 | 2019-04-11 11:46:55 -0700 | [diff] [blame] | 73 | } |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 74 | b = wire.AppendString(b, v.String()) |
Damien Neil | 99f24c3 | 2019-03-13 17:06:42 -0700 | [diff] [blame] | 75 | case protoreflect.BytesKind: |
| 76 | b = wire.AppendBytes(b, v.Bytes()) |
| 77 | case protoreflect.MessageKind: |
| 78 | var pos int |
| 79 | var err error |
| 80 | b, pos = appendSpeculativeLength(b) |
| 81 | b, err = o.marshalMessage(b, v.Message()) |
Damien Neil | 8c86fc5 | 2019-06-19 09:28:29 -0700 | [diff] [blame] | 82 | if err != nil { |
Damien Neil | 96c229a | 2019-04-03 12:17:24 -0700 | [diff] [blame] | 83 | return b, err |
Damien Neil | 99f24c3 | 2019-03-13 17:06:42 -0700 | [diff] [blame] | 84 | } |
| 85 | b = finishSpeculativeLength(b, pos) |
| 86 | case protoreflect.GroupKind: |
| 87 | var err error |
| 88 | b, err = o.marshalMessage(b, v.Message()) |
Damien Neil | 8c86fc5 | 2019-06-19 09:28:29 -0700 | [diff] [blame] | 89 | if err != nil { |
Damien Neil | 96c229a | 2019-04-03 12:17:24 -0700 | [diff] [blame] | 90 | return b, err |
Damien Neil | 99f24c3 | 2019-03-13 17:06:42 -0700 | [diff] [blame] | 91 | } |
Joe Tsai | 378c132 | 2019-04-25 23:48:08 -0700 | [diff] [blame] | 92 | b = wire.AppendVarint(b, wire.EncodeTag(fd.Number(), wire.EndGroupType)) |
Damien Neil | 99f24c3 | 2019-03-13 17:06:42 -0700 | [diff] [blame] | 93 | default: |
Joe Tsai | 378c132 | 2019-04-25 23:48:08 -0700 | [diff] [blame] | 94 | return b, errors.New("invalid kind %v", fd.Kind()) |
Damien Neil | 99f24c3 | 2019-03-13 17:06:42 -0700 | [diff] [blame] | 95 | } |
Damien Neil | 8c86fc5 | 2019-06-19 09:28:29 -0700 | [diff] [blame] | 96 | return b, nil |
Damien Neil | 99f24c3 | 2019-03-13 17:06:42 -0700 | [diff] [blame] | 97 | } |