blob: 46621c8487a7654b91c88e9f8cb878a74b15532b [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"
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
17var 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
38func (o MarshalOptions) marshalSingular(b []byte, num wire.Number, kind protoreflect.Kind, v protoreflect.Value) ([]byte, error) {
Damien Neil96c229a2019-04-03 12:17:24 -070039 var nerr errors.NonFatal
Damien Neil99f24c32019-03-13 17:06:42 -070040 switch kind {
41 case protoreflect.BoolKind:
42 b = wire.AppendVarint(b, wire.EncodeBool(v.Bool()))
43 case protoreflect.EnumKind:
44 b = wire.AppendVarint(b, uint64(v.Enum()))
45 case protoreflect.Int32Kind:
46 b = wire.AppendVarint(b, uint64(int32(v.Int())))
47 case protoreflect.Sint32Kind:
48 b = wire.AppendVarint(b, wire.EncodeZigZag(int64(int32(v.Int()))))
49 case protoreflect.Uint32Kind:
50 b = wire.AppendVarint(b, uint64(uint32(v.Uint())))
51 case protoreflect.Int64Kind:
52 b = wire.AppendVarint(b, uint64(v.Int()))
53 case protoreflect.Sint64Kind:
54 b = wire.AppendVarint(b, wire.EncodeZigZag(v.Int()))
55 case protoreflect.Uint64Kind:
56 b = wire.AppendVarint(b, v.Uint())
57 case protoreflect.Sfixed32Kind:
58 b = wire.AppendFixed32(b, uint32(v.Int()))
59 case protoreflect.Fixed32Kind:
60 b = wire.AppendFixed32(b, uint32(v.Uint()))
61 case protoreflect.FloatKind:
62 b = wire.AppendFixed32(b, math.Float32bits(float32(v.Float())))
63 case protoreflect.Sfixed64Kind:
64 b = wire.AppendFixed64(b, uint64(v.Int()))
65 case protoreflect.Fixed64Kind:
66 b = wire.AppendFixed64(b, v.Uint())
67 case protoreflect.DoubleKind:
68 b = wire.AppendFixed64(b, math.Float64bits(v.Float()))
69 case protoreflect.StringKind:
70 b = wire.AppendBytes(b, []byte(v.String()))
71 case protoreflect.BytesKind:
72 b = wire.AppendBytes(b, v.Bytes())
73 case protoreflect.MessageKind:
74 var pos int
75 var err error
76 b, pos = appendSpeculativeLength(b)
77 b, err = o.marshalMessage(b, v.Message())
Damien Neil96c229a2019-04-03 12:17:24 -070078 if !nerr.Merge(err) {
79 return b, err
Damien Neil99f24c32019-03-13 17:06:42 -070080 }
81 b = finishSpeculativeLength(b, pos)
82 case protoreflect.GroupKind:
83 var err error
84 b, err = o.marshalMessage(b, v.Message())
Damien Neil96c229a2019-04-03 12:17:24 -070085 if !nerr.Merge(err) {
86 return b, err
Damien Neil99f24c32019-03-13 17:06:42 -070087 }
88 b = wire.AppendVarint(b, wire.EncodeTag(num, wire.EndGroupType))
89 default:
Damien Neil96c229a2019-04-03 12:17:24 -070090 return b, errors.New("invalid kind %v", kind)
Damien Neil99f24c32019-03-13 17:06:42 -070091 }
Damien Neil96c229a2019-04-03 12:17:24 -070092 return b, nerr.E
Damien Neil99f24c32019-03-13 17:06:42 -070093}