github.com/cosmos/cosmos-proto@v1.0.0-beta.3/generator/helpers.go (about) 1 // Copyright (c) 2021 PlanetScale Inc. 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 package generator 6 7 import ( 8 "google.golang.org/protobuf/encoding/protowire" 9 "google.golang.org/protobuf/reflect/protoreflect" 10 ) 11 12 const ProtoPkg = "google.golang.org/protobuf/proto" 13 14 func KeySize(fieldNumber protoreflect.FieldNumber, wireType protowire.Type) int { 15 x := uint32(fieldNumber)<<3 | uint32(wireType) 16 size := 0 17 for size = 0; x > 127; size++ { 18 x >>= 7 19 } 20 size++ 21 return size 22 } 23 24 var wireTypes = map[protoreflect.Kind]protowire.Type{ 25 protoreflect.BoolKind: protowire.VarintType, 26 protoreflect.EnumKind: protowire.VarintType, 27 protoreflect.Int32Kind: protowire.VarintType, 28 protoreflect.Sint32Kind: protowire.VarintType, 29 protoreflect.Uint32Kind: protowire.VarintType, 30 protoreflect.Int64Kind: protowire.VarintType, 31 protoreflect.Sint64Kind: protowire.VarintType, 32 protoreflect.Uint64Kind: protowire.VarintType, 33 protoreflect.Sfixed32Kind: protowire.Fixed32Type, 34 protoreflect.Fixed32Kind: protowire.Fixed32Type, 35 protoreflect.FloatKind: protowire.Fixed32Type, 36 protoreflect.Sfixed64Kind: protowire.Fixed64Type, 37 protoreflect.Fixed64Kind: protowire.Fixed64Type, 38 protoreflect.DoubleKind: protowire.Fixed64Type, 39 protoreflect.StringKind: protowire.BytesType, 40 protoreflect.BytesKind: protowire.BytesType, 41 protoreflect.MessageKind: protowire.BytesType, 42 protoreflect.GroupKind: protowire.StartGroupType, 43 } 44 45 func ProtoWireType(k protoreflect.Kind) protowire.Type { 46 return wireTypes[k] 47 }