blob: 77b65117028e654f3b95969b778ec5d231316657 [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"
Joe Tsaic51e2e02019-07-13 00:44:41 -070015 "google.golang.org/protobuf/internal/strs"
Damien Neile89e6242019-05-13 23:55:40 -070016 "google.golang.org/protobuf/reflect/protoreflect"
Damien Neil99f24c32019-03-13 17:06:42 -070017)
18
19var 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 Tsai378c1322019-04-25 23:48:08 -070040func (o MarshalOptions) marshalSingular(b []byte, fd protoreflect.FieldDescriptor, v protoreflect.Value) ([]byte, error) {
Joe Tsai378c1322019-04-25 23:48:08 -070041 switch fd.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:
Joe Tsaic51e2e02019-07-13 00:44:41 -070071 if strs.EnforceUTF8(fd) && !utf8.ValidString(v.String()) {
Damien Neil8c86fc52019-06-19 09:28:29 -070072 return b, errors.InvalidUTF8(string(fd.FullName()))
Damien Neilbc310b52019-04-11 11:46:55 -070073 }
Damien Neilcedb5952019-06-21 12:04:07 -070074 b = wire.AppendString(b, v.String())
Damien Neil99f24c32019-03-13 17:06:42 -070075 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 Neil8c86fc52019-06-19 09:28:29 -070082 if err != nil {
Damien Neil96c229a2019-04-03 12:17:24 -070083 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 Neil8c86fc52019-06-19 09:28:29 -070089 if err != nil {
Damien Neil96c229a2019-04-03 12:17:24 -070090 return b, err
Damien Neil99f24c32019-03-13 17:06:42 -070091 }
Joe Tsai378c1322019-04-25 23:48:08 -070092 b = wire.AppendVarint(b, wire.EncodeTag(fd.Number(), wire.EndGroupType))
Damien Neil99f24c32019-03-13 17:06:42 -070093 default:
Joe Tsai378c1322019-04-25 23:48:08 -070094 return b, errors.New("invalid kind %v", fd.Kind())
Damien Neil99f24c32019-03-13 17:06:42 -070095 }
Damien Neil8c86fc52019-06-19 09:28:29 -070096 return b, nil
Damien Neil99f24c32019-03-13 17:06:42 -070097}