xref: /aosp_15_r20/external/golang-protobuf/proto/size_gen.go (revision 1c12ee1efe575feb122dbf939ff15148a3b3e8f2)
1*1c12ee1eSDan Willemsen// Copyright 2018 The Go Authors. All rights reserved.
2*1c12ee1eSDan Willemsen// Use of this source code is governed by a BSD-style
3*1c12ee1eSDan Willemsen// license that can be found in the LICENSE file.
4*1c12ee1eSDan Willemsen
5*1c12ee1eSDan Willemsen// Code generated by generate-types. DO NOT EDIT.
6*1c12ee1eSDan Willemsen
7*1c12ee1eSDan Willemsenpackage proto
8*1c12ee1eSDan Willemsen
9*1c12ee1eSDan Willemsenimport (
10*1c12ee1eSDan Willemsen	"google.golang.org/protobuf/encoding/protowire"
11*1c12ee1eSDan Willemsen	"google.golang.org/protobuf/reflect/protoreflect"
12*1c12ee1eSDan Willemsen)
13*1c12ee1eSDan Willemsen
14*1c12ee1eSDan Willemsenfunc (o MarshalOptions) sizeSingular(num protowire.Number, kind protoreflect.Kind, v protoreflect.Value) int {
15*1c12ee1eSDan Willemsen	switch kind {
16*1c12ee1eSDan Willemsen	case protoreflect.BoolKind:
17*1c12ee1eSDan Willemsen		return protowire.SizeVarint(protowire.EncodeBool(v.Bool()))
18*1c12ee1eSDan Willemsen	case protoreflect.EnumKind:
19*1c12ee1eSDan Willemsen		return protowire.SizeVarint(uint64(v.Enum()))
20*1c12ee1eSDan Willemsen	case protoreflect.Int32Kind:
21*1c12ee1eSDan Willemsen		return protowire.SizeVarint(uint64(int32(v.Int())))
22*1c12ee1eSDan Willemsen	case protoreflect.Sint32Kind:
23*1c12ee1eSDan Willemsen		return protowire.SizeVarint(protowire.EncodeZigZag(int64(int32(v.Int()))))
24*1c12ee1eSDan Willemsen	case protoreflect.Uint32Kind:
25*1c12ee1eSDan Willemsen		return protowire.SizeVarint(uint64(uint32(v.Uint())))
26*1c12ee1eSDan Willemsen	case protoreflect.Int64Kind:
27*1c12ee1eSDan Willemsen		return protowire.SizeVarint(uint64(v.Int()))
28*1c12ee1eSDan Willemsen	case protoreflect.Sint64Kind:
29*1c12ee1eSDan Willemsen		return protowire.SizeVarint(protowire.EncodeZigZag(v.Int()))
30*1c12ee1eSDan Willemsen	case protoreflect.Uint64Kind:
31*1c12ee1eSDan Willemsen		return protowire.SizeVarint(v.Uint())
32*1c12ee1eSDan Willemsen	case protoreflect.Sfixed32Kind:
33*1c12ee1eSDan Willemsen		return protowire.SizeFixed32()
34*1c12ee1eSDan Willemsen	case protoreflect.Fixed32Kind:
35*1c12ee1eSDan Willemsen		return protowire.SizeFixed32()
36*1c12ee1eSDan Willemsen	case protoreflect.FloatKind:
37*1c12ee1eSDan Willemsen		return protowire.SizeFixed32()
38*1c12ee1eSDan Willemsen	case protoreflect.Sfixed64Kind:
39*1c12ee1eSDan Willemsen		return protowire.SizeFixed64()
40*1c12ee1eSDan Willemsen	case protoreflect.Fixed64Kind:
41*1c12ee1eSDan Willemsen		return protowire.SizeFixed64()
42*1c12ee1eSDan Willemsen	case protoreflect.DoubleKind:
43*1c12ee1eSDan Willemsen		return protowire.SizeFixed64()
44*1c12ee1eSDan Willemsen	case protoreflect.StringKind:
45*1c12ee1eSDan Willemsen		return protowire.SizeBytes(len(v.String()))
46*1c12ee1eSDan Willemsen	case protoreflect.BytesKind:
47*1c12ee1eSDan Willemsen		return protowire.SizeBytes(len(v.Bytes()))
48*1c12ee1eSDan Willemsen	case protoreflect.MessageKind:
49*1c12ee1eSDan Willemsen		return protowire.SizeBytes(o.size(v.Message()))
50*1c12ee1eSDan Willemsen	case protoreflect.GroupKind:
51*1c12ee1eSDan Willemsen		return protowire.SizeGroup(num, o.size(v.Message()))
52*1c12ee1eSDan Willemsen	default:
53*1c12ee1eSDan Willemsen		return 0
54*1c12ee1eSDan Willemsen	}
55*1c12ee1eSDan Willemsen}
56