blob: 6198c385609d87629d996a63843b773a2618ade1 [file] [log] [blame]
Damien Neil99f24c32019-03-13 17:06:42 -07001// 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
7package proto
8
9import (
10 "math"
Damien Neilbc310b52019-04-11 11:46:55 -070011 "unicode/utf8"
Damien Neil99f24c32019-03-13 17:06:42 -070012
Damien Neile89e6242019-05-13 23:55:40 -070013 "google.golang.org/protobuf/internal/encoding/wire"
14 "google.golang.org/protobuf/internal/errors"
15 "google.golang.org/protobuf/reflect/protoreflect"
Damien Neil99f24c32019-03-13 17:06:42 -070016)
17
18var wireTypes = map[protoreflect.Kind]wire.Type{
19 protoreflect.BoolKind: wire.VarintType,
20 protoreflect.EnumKind: wire.VarintType,
21 protoreflect.Int32Kind: wire.VarintType,
22 protoreflect.Sint32Kind: wire.VarintType,
23 protoreflect.Uint32Kind: wire.VarintType,
24 protoreflect.Int64Kind: wire.VarintType,
25 protoreflect.Sint64Kind: wire.VarintType,
26 protoreflect.Uint64Kind: wire.VarintType,
27 protoreflect.Sfixed32Kind: wire.Fixed32Type,
28 protoreflect.Fixed32Kind: wire.Fixed32Type,
29 protoreflect.FloatKind: wire.Fixed32Type,
30 protoreflect.Sfixed64Kind: wire.Fixed64Type,
31 protoreflect.Fixed64Kind: wire.Fixed64Type,
32 protoreflect.DoubleKind: wire.Fixed64Type,
33 protoreflect.StringKind: wire.BytesType,
34 protoreflect.BytesKind: wire.BytesType,
35 protoreflect.MessageKind: wire.BytesType,
36 protoreflect.GroupKind: wire.StartGroupType,
37}
38
Damien Neilbc310b52019-04-11 11:46:55 -070039func (o MarshalOptions) marshalSingular(b []byte, num wire.Number, field protoreflect.FieldDescriptor, v protoreflect.Value) ([]byte, error) {
Damien Neil96c229a2019-04-03 12:17:24 -070040 var nerr errors.NonFatal
Damien Neilbc310b52019-04-11 11:46:55 -070041 switch field.Kind() {
Damien Neil99f24c32019-03-13 17:06:42 -070042 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:
Damien Neilbc310b52019-04-11 11:46:55 -070071 if field.Syntax() == protoreflect.Proto3 && !utf8.ValidString(v.String()) {
72 nerr.AppendInvalidUTF8(string(field.FullName()))
73 }
Damien Neil99f24c32019-03-13 17:06:42 -070074 b = wire.AppendBytes(b, []byte(v.String()))
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 Neil96c229a2019-04-03 12:17:24 -070082 if !nerr.Merge(err) {
83 return b, err
Damien Neil99f24c32019-03-13 17:06:42 -070084 }
85 b = finishSpeculativeLength(b, pos)
86 case protoreflect.GroupKind:
87 var err error
88 b, err = o.marshalMessage(b, v.Message())
Damien Neil96c229a2019-04-03 12:17:24 -070089 if !nerr.Merge(err) {
90 return b, err
Damien Neil99f24c32019-03-13 17:06:42 -070091 }
92 b = wire.AppendVarint(b, wire.EncodeTag(num, wire.EndGroupType))
93 default:
Damien Neilbc310b52019-04-11 11:46:55 -070094 return b, errors.New("invalid kind %v", field.Kind())
Damien Neil99f24c32019-03-13 17:06:42 -070095 }
Damien Neil96c229a2019-04-03 12:17:24 -070096 return b, nerr.E
Damien Neil99f24c32019-03-13 17:06:42 -070097}