How to use GetType method of proto Package

Best Rod code snippet using proto.GetType

decoder.go

Source:decoder.go Github

copy

Full Screen

...96 if !exists {97 return98 }99 var val interface{}100 switch f.GetType() {101 case descriptor.FieldDescriptorProto_TYPE_BOOL:102 val = wire.DecodeBool(v)103 case descriptor.FieldDescriptorProto_TYPE_INT32,104 descriptor.FieldDescriptorProto_TYPE_INT64,105 descriptor.FieldDescriptorProto_TYPE_UINT32,106 descriptor.FieldDescriptorProto_TYPE_UINT64:107 val = int64(v)108 case descriptor.FieldDescriptorProto_TYPE_SINT32,109 descriptor.FieldDescriptorProto_TYPE_SINT64:110 val = wire.DecodeZigZag(v)111 case descriptor.FieldDescriptorProto_TYPE_ENUM:112 val = int64(v)113 default:114 dv.err = multierror.Append(dv.err, fmt.Errorf("unexpected field type %q for varint encoding", f.GetType()))115 return116 }117 dv.setValue(f, val)118}119func (dv *decodeVisitor) Fixed32(n wire.Number, v uint32) {120 f, exists := dv.decoder.fields[n]121 if !exists {122 return123 }124 var val interface{}125 switch f.GetType() {126 case descriptor.FieldDescriptorProto_TYPE_FIXED32:127 val = int64(v)128 case descriptor.FieldDescriptorProto_TYPE_SFIXED32:129 val = int64(v)130 case descriptor.FieldDescriptorProto_TYPE_FLOAT:131 val = float64(math.Float32frombits(v))132 default:133 dv.err = multierror.Append(dv.err, fmt.Errorf("unexpected field type %q for fixed32 encoding", f.GetType()))134 return135 }136 dv.setValue(f, val)137}138func (dv *decodeVisitor) Fixed64(n wire.Number, v uint64) {139 f, exists := dv.decoder.fields[n]140 if !exists {141 return142 }143 var val interface{}144 switch f.GetType() {145 case descriptor.FieldDescriptorProto_TYPE_FIXED64:146 val = int64(v)147 case descriptor.FieldDescriptorProto_TYPE_SFIXED64:148 val = int64(v)149 case descriptor.FieldDescriptorProto_TYPE_DOUBLE:150 val = math.Float64frombits(v)151 default:152 dv.err = multierror.Append(dv.err, fmt.Errorf("unexpected field type %q for fixed64 encoding", f.GetType()))153 return154 }155 dv.setValue(f, val)156}157type mapVisitor struct {158 desc *descriptor.DescriptorProto159 key, value string160}161// TODO: only string maps are supported since mixer's IL only supports string maps162func (mv *mapVisitor) Varint(wire.Number, uint64) {}163func (mv *mapVisitor) Fixed32(wire.Number, uint32) {}164func (mv *mapVisitor) Fixed64(wire.Number, uint64) {}165func (mv *mapVisitor) Bytes(n wire.Number, v []byte) {166 switch n {167 case mv.desc.Field[0].GetNumber():168 mv.key = string(v)169 case mv.desc.Field[1].GetNumber():170 mv.value = string(v)171 }172}173func (dv *decodeVisitor) Bytes(n wire.Number, v []byte) {174 f, exists := dv.decoder.fields[n]175 if !exists {176 return177 }178 switch f.GetType() {179 case descriptor.FieldDescriptorProto_TYPE_STRING:180 dv.setValue(f, string(v))181 return182 case descriptor.FieldDescriptorProto_TYPE_BYTES:183 dv.setValue(f, v)184 return185 case descriptor.FieldDescriptorProto_TYPE_MESSAGE:186 name := dv.attrPrefix + f.GetName()187 if isMap(dv.decoder.resolver, f) {188 // validate proto type to be map<string, string>189 mapType := dv.decoder.resolver.ResolveMessage(f.GetTypeName())190 if mapType == nil || len(mapType.Field) < 2 {191 dv.err = multierror.Append(dv.err, fmt.Errorf("unresolved or incorrect map field type %q", f.GetName()))192 return193 }194 if mapType.Field[0].GetType() != descriptor.FieldDescriptorProto_TYPE_STRING ||195 mapType.Field[1].GetType() != descriptor.FieldDescriptorProto_TYPE_STRING {196 dv.err = multierror.Append(dv.err, errors.New("only map<string, string> is supported in expressions"))197 return198 }199 // translate map<X, Y> proto3 field type to record Mixer type (map[string]string)200 var m attribute.StringMap201 val, ok := dv.out.Get(name)202 if !ok {203 m = attribute.NewStringMap(name)204 } else {205 m = val.(attribute.StringMap)206 }207 visitor := &mapVisitor{desc: mapType}208 for len(v) > 0 {209 _, _, m := wire.ConsumeField(visitor, v)210 if m < 0 {211 dv.err = multierror.Append(dv.err, fmt.Errorf("failed to parse map field %q: %v", f.GetName(), wire.ParseError(m)))212 return213 }214 v = v[m:]215 }216 m.Set(visitor.key, visitor.value)217 dv.out.Set(name, m)218 return219 }220 // parse the entirety of the message recursively for value types221 if _, ok := valueResolver.descriptors[f.GetTypeName()]; ok && !f.IsRepeated() {222 decoder := NewDecoder(valueResolver, f.GetTypeName(), nil)223 inner := attribute.GetMutableBag(nil)224 defer inner.Done()225 if err := decoder.Decode(v, inner, ""); err != nil {226 dv.err = multierror.Append(dv.err, fmt.Errorf("failed to decode field %q: %v", f.GetName(), err))227 return228 }229 switch f.GetTypeName() {230 case ".istio.policy.v1beta1.Value":231 // pop oneof inner value from the bag to the field value232 names := inner.Names()233 if len(names) == 1 {234 if val, ok := inner.Get(names[0]); ok {235 dv.out.Set(name, val)236 }237 }238 case ".istio.policy.v1beta1.IPAddress",239 ".istio.policy.v1beta1.Duration",240 ".istio.policy.v1beta1.DNSName":241 if value, ok := inner.Get("value"); ok {242 dv.out.Set(name, value)243 }244 case ".google.protobuf.Duration":245 seconds, secondsOk := inner.Get("seconds")246 nanos, nanosOk := inner.Get("nanos")247 if secondsOk || nanosOk {248 // must default to int64 for casting to work249 if seconds == nil {250 seconds = int64(0)251 }252 if nanos == nil {253 nanos = int64(0)254 }255 dv.out.Set(name, time.Duration(seconds.(int64))*time.Second+time.Duration(nanos.(int64)))256 }257 }258 return259 }260 // TODO: implement sub-message decoding261 return262 }263 // fallback into packed repeated encoding264 if f.IsRepeated() && (f.IsPacked() || f.IsPacked3()) {265 var m int266 for len(v) > 0 {267 switch f.GetType() {268 case descriptor.FieldDescriptorProto_TYPE_BOOL,269 descriptor.FieldDescriptorProto_TYPE_INT32,270 descriptor.FieldDescriptorProto_TYPE_INT64,271 descriptor.FieldDescriptorProto_TYPE_UINT32,272 descriptor.FieldDescriptorProto_TYPE_UINT64,273 descriptor.FieldDescriptorProto_TYPE_SINT32,274 descriptor.FieldDescriptorProto_TYPE_SINT64,275 descriptor.FieldDescriptorProto_TYPE_ENUM:276 var elt uint64277 elt, m = wire.ConsumeVarint(v)278 if m < 0 {279 dv.err = multierror.Append(dv.err, fmt.Errorf("failed to parse packed varint field %q", f.GetName()))280 return281 }282 dv.Varint(n, elt)283 case descriptor.FieldDescriptorProto_TYPE_FIXED32,284 descriptor.FieldDescriptorProto_TYPE_SFIXED32,285 descriptor.FieldDescriptorProto_TYPE_FLOAT:286 var elt uint32287 elt, m = wire.ConsumeFixed32(v)288 if m < 0 {289 dv.err = multierror.Append(dv.err, fmt.Errorf("failed to parse packed fixed32 field %q", f.GetName()))290 return291 }292 dv.Fixed32(n, elt)293 case descriptor.FieldDescriptorProto_TYPE_FIXED64,294 descriptor.FieldDescriptorProto_TYPE_SFIXED64,295 descriptor.FieldDescriptorProto_TYPE_DOUBLE:296 var elt uint64297 elt, m = wire.ConsumeFixed64(v)298 if m < 0 {299 dv.err = multierror.Append(dv.err, fmt.Errorf("failed to parse packed fixed64 field %q", f.GetName()))300 return301 }302 dv.Fixed64(n, elt)303 default:304 dv.err = multierror.Append(dv.err, fmt.Errorf("unexpected field type %q for packed repeated bytes encoding", f.GetType()))305 return306 }307 v = v[m:]308 }309 return310 }311 dv.err = multierror.Append(dv.err, fmt.Errorf("unexpected field type %q for bytes encoding", f.GetType()))312}313type valueTypeResolver struct {314 descriptors map[string]*descriptor.DescriptorProto315}316func getDescriptorProto(msg descriptor.Message) *descriptor.DescriptorProto {317 _, desc := descriptor.ForMessage(msg)318 return desc319}320func newValueTypeResolver() *valueTypeResolver {321 out := &valueTypeResolver{322 descriptors: map[string]*descriptor.DescriptorProto{323 ".istio.policy.v1beta1.Value": getDescriptorProto(&v1beta1.Value{}),324 ".istio.policy.v1beta1.IPAddress": getDescriptorProto(&v1beta1.IPAddress{}),325 ".istio.policy.v1beta1.Duration": getDescriptorProto(&v1beta1.Duration{}),326 ".istio.policy.v1beta1.TimeStamp": getDescriptorProto(&v1beta1.TimeStamp{}),327 ".istio.policy.v1beta1.DNSName": getDescriptorProto(&v1beta1.DNSName{}),328 ".google.protobuf.Duration": getDescriptorProto(&types.Duration{}),329 ".google.protobuf.Timestamp": getDescriptorProto(&types.Timestamp{}),330 },331 }332 return out333}334func (vtr *valueTypeResolver) ResolveMessage(msg string) *descriptor.DescriptorProto {335 return vtr.descriptors[msg]336}337func (vtr *valueTypeResolver) ResolveEnum(string) *descriptor.EnumDescriptorProto {338 return nil339}340func (vtr *valueTypeResolver) ResolveService(string) (*descriptor.ServiceDescriptorProto, string) {341 return nil, ""342}343var (344 valueResolver = newValueTypeResolver()345)346// DecodeType converts protobuf types to mixer's IL types.347// Note that due to absence of corresponding types for a variety of concrete values produced by the decoder,348// the returned value may be an unspecified type.349func DecodeType(resolver Resolver, desc *descriptor.FieldDescriptorProto) v1beta1.ValueType {350 if desc.GetType() == descriptor.FieldDescriptorProto_TYPE_MESSAGE {351 fieldType := resolver.ResolveMessage(desc.GetTypeName())352 if fieldType != nil && len(fieldType.Field) == 2 &&353 fieldType.GetOptions().GetMapEntry() &&354 fieldType.Field[0].GetType() == descriptor.FieldDescriptorProto_TYPE_STRING &&355 fieldType.Field[1].GetType() == descriptor.FieldDescriptorProto_TYPE_STRING {356 return v1beta1.STRING_MAP357 }358 if desc.IsRepeated() {359 return v1beta1.VALUE_TYPE_UNSPECIFIED360 }361 switch desc.GetTypeName() {362 case ".istio.policy.v1beta1.Value":363 return v1beta1.VALUE_TYPE_UNSPECIFIED364 case ".istio.policy.v1beta1.IPAddress":365 return v1beta1.IP_ADDRESS366 case ".istio.policy.v1beta1.Duration", ".google.protobuf.Duration":367 return v1beta1.DURATION368 case ".istio.policy.v1beta1.TimeStamp", ".google.protobuf.Timestamp":369 return v1beta1.TIMESTAMP370 case ".istio.policy.v1beta1.DNSName":371 return v1beta1.DNS_NAME372 }373 }374 // array types are missing375 if desc.IsRepeated() {376 return v1beta1.VALUE_TYPE_UNSPECIFIED377 }378 switch desc.GetType() {379 case descriptor.FieldDescriptorProto_TYPE_BOOL:380 return v1beta1.BOOL381 case descriptor.FieldDescriptorProto_TYPE_INT32,382 descriptor.FieldDescriptorProto_TYPE_INT64,383 descriptor.FieldDescriptorProto_TYPE_UINT32,384 descriptor.FieldDescriptorProto_TYPE_UINT64,385 descriptor.FieldDescriptorProto_TYPE_SINT32,386 descriptor.FieldDescriptorProto_TYPE_SINT64,387 descriptor.FieldDescriptorProto_TYPE_ENUM,388 descriptor.FieldDescriptorProto_TYPE_FIXED32,389 descriptor.FieldDescriptorProto_TYPE_SFIXED32,390 descriptor.FieldDescriptorProto_TYPE_FIXED64,391 descriptor.FieldDescriptorProto_TYPE_SFIXED64:392 return v1beta1.INT64...

Full Screen

Full Screen

itemOwner.go

Source:itemOwner.go Github

copy

Full Screen

...70 return c.GetContainer(ItemProto.GetItemContainerType(typ))71}72//CanAddItem 能否放入item73func (c *ContainerOwner) canAddItem(item ItemProto.IItem) bool {74 container := c.GetItemContainerByItemType(item.GetType())75 if container != nil {76 num := container.GetCanAddNum(item.GetConfigID(), item.GetType(), item.GetNum())77 if num != item.GetNum() {78 return false79 }80 return container.HasEnoughSpace(1)81 }82 return false83}84//AddItemToPack 往目标包裹添加道具85func (c *ContainerOwner) AddItemToPack(item ItemProto.IItem) bool {86 container := c.GetItemContainerByItemType(item.GetType())87 if container != nil {88 _, ok := container.AddItem(item)89 return ok90 }91 return false92}93func (c *ContainerOwner) RemoveItem(configID uint32, typ uint32, num uint32) uint32 {94 container := c.GetItemContainerByItemType(typ)95 if container != nil {96 removeNum, _ := container.RemoveItemNum(configID, typ, num)97 return removeNum98 }99 return 0100}101func (c *ContainerOwner) AddItem(configID uint32, typ uint32, num uint32, args ...uint32) uint32 {102 container := c.GetItemContainerByItemType(typ)103 if container != nil {104 num = container.GetCanAddNum(configID, typ, num)105 return container.AddItemNum(configID, typ, num, args...)106 }107 return 0108}109func (c *ContainerOwner) UpdataItem(item ItemProto.IItem) {110 c.Traversal(func(container IItemContainer) (bool, interface{}) {111 _item := container.GetIItemByID(item.GetID())112 if _item == nil {113 return true, nil114 }115 container.UpdataItem(item)116 return false, nil117 })118}119func (c *ContainerOwner) GetItemNum(configID uint32, typ uint32) uint32 {120 container := c.GetItemContainerByItemType(typ)121 if container != nil {122 return container.GetItemNum(configID, typ)123 }124 return 0125}126func (c *ContainerOwner) getItem(typ uint32, pos int32) ItemProto.IItem {127 container := c.GetItemContainerByItemType(typ)128 if container != nil {129 item := container.GetIItem(pos)130 return item131 }132 return nil133}134func (c *ContainerOwner) AddItemList(items []*Proto.DropMaterial, args ...uint32) []*Proto.GetItemData{135 var itemMap map[int32][]*Proto.DropMaterial136 itemMap = make(map[int32][]*Proto.DropMaterial)137 //整理下items,区分包裹类型,合并同类道具138 for _, v := range items {139 //包裹140 container := c.GetItemContainerByItemType(v.MaterialType)141 if container == nil {142 return nil143 }144 _c, ok := itemMap[container.GetType()]145 if ok == false {146 list := make([]*Proto.DropMaterial, 0)147 itemMap[container.GetType()] = list148 _c, _ = itemMap[container.GetType()] //应该不会没有把149 }150 found := false151 for k2, v2 := range _c {152 if v2.MaterialId == v.MaterialId && v2.MaterialType == v.MaterialType {153 //同类数量合并154 itemMap[container.GetType()][k2].MaterialNum += v.MaterialNum155 itemMap[container.GetType()][k2].MaterialNum = container.GetCanAddNum(v2.MaterialId, v2.MaterialType, itemMap[container.GetType()][k2].MaterialNum)156 found = true157 break158 }159 }160 if found == false {161 itemMap[container.GetType()] = append(itemMap[container.GetType()], &Proto.DropMaterial{162 MaterialId:v.MaterialId,163 MaterialType:v.MaterialType,164 MaterialNum:container.GetCanAddNum(v.MaterialId, v.MaterialType, v.MaterialNum),165 })166 }167 }168 list := make([]*Proto.GetItemData, 0)169 for k, param := range itemMap {170 container := c.GetContainer(int32(k))171 if container == nil {172 return nil173 }174 _list := container.AddItemList(param)175 if len(_list) > 0 {176 list = append(list, _list...)177 }178 }179 return list180}181func (c *ContainerOwner) RemoveItemList(items []ItemProto.IItem) []ItemProto.IItem{182 var itemMap map[int32][]ItemProto.IItem183 itemMap = make(map[int32][]ItemProto.IItem)184 removeList := make([]ItemProto.IItem, 0)185 //整理下items,区分包裹类型,合并同类道具186 for _, v := range items {187 //包裹188 container := c.GetItemContainerByItemType(v.GetType())189 if container == nil {190 return removeList191 }192 _, ok := itemMap[container.GetType()]193 if ok == false {194 list := make([]ItemProto.IItem, 0)195 itemMap[container.GetType()] = list196 }197 itemMap[container.GetType()] = append(itemMap[container.GetType()], v)198 }199 for k, param := range itemMap {200 container := c.GetContainer(int32(k))201 if container == nil {202 return nil203 }204 _list := container.RemoveItemList(param)205 if len(_list) > 0 {206 removeList = append(removeList, _list...)207 }208 }209 return removeList210}211func (c *ContainerOwner) CanAddItemList(items []*Proto.DropMaterial) ([]int32,bool) {212 var itemMap map[int32][]*Proto.DropMaterial213 itemMap = make(map[int32][]*Proto.DropMaterial)214 fullCList := make([]int32, 0)215 //整理下items,区分包裹类型,合并同类道具216 for _, v := range items {217 //包裹218 container := c.GetItemContainerByItemType(v.MaterialType)219 if container == nil {220 return nil,false221 }222 _c, ok := itemMap[container.GetType()]223 if ok == false {224 list := make([]*Proto.DropMaterial, 0)225 itemMap[container.GetType()] = list226 _c, _ = itemMap[container.GetType()] //应该不会没有把227 }228 found := false229 for k2, v2 := range _c {230 if v2.MaterialId == v.MaterialId && v2.MaterialType == v.MaterialType {231 //同类数量合并232 itemMap[container.GetType()][k2].MaterialNum += v.MaterialNum233 found = true234 }235 break236 }237 if found == false {238 itemMap[container.GetType()] = append(itemMap[container.GetType()], &Proto.DropMaterial{239 MaterialId:v.MaterialId,240 MaterialType:v.MaterialType,241 MaterialNum:v.MaterialNum,242 })243 }244 }245 can := true246 for k, param := range itemMap {247 container := c.GetContainer(int32(k))248 if container == nil {249 return nil,false250 }251 if container.CanAddItemList(param) == false {252 fullCList = append(fullCList, k)253 can = false254 continue255 }256 }257 return fullCList, can258}259func (c *ContainerOwner) CanAddItemIList(items []ItemProto.IItem) ([]int32,bool) {260 list := make([]*Proto.DropMaterial, 0)261 for _, v := range items {262 list = append(list, &Proto.DropMaterial{263 MaterialId: v.GetConfigID(),264 MaterialType: v.GetType(),265 MaterialNum: v.GetNum(),266 })267 }268 return c.CanAddItemList(list)269}270func (c *ContainerOwner) AddItems(items []ItemProto.IItem) []ItemProto.IItem {271 list := make([]ItemProto.IItem, 0)272 for _, v := range items {273 if c.AddItemToPack(v) == true {274 list = append(list, v)275 }276 }277 return list278}...

Full Screen

Full Screen

verifyProto.go

Source:verifyProto.go Github

copy

Full Screen

...29 assertProto(actual.GetReward().GetFelIron() == 5)30 assertProto(actual.GetReward().GetAtium() == 1)31 assertProto(len(actual.GetReward().GetItem()) == 3)32 assertProto(actual.GetReward().GetItem()[0].GetItemID() == 10001)33 assertProto(actual.GetReward().GetItem()[0].GetType() == 1)34 assertProto(actual.GetReward().GetItem()[0].GetCount() == 1)35 assertProto(actual.GetReward().GetItem()[1].GetItemID() == 10002)36 assertProto(actual.GetReward().GetItem()[1].GetType() == 2)37 assertProto(actual.GetReward().GetItem()[1].GetCount() == 2)38 assertProto(actual.GetReward().GetItem()[2].GetItemID() == 0)39 assertProto(actual.GetReward().GetItem()[2].GetType() == 0)40 assertProto(actual.GetReward().GetItem()[2].GetCount() == 0)41 actual, ok = reader.Datas[2]42 assertProto(ok)43 assertProto(actual.GetKey() == 2)44 assertProto(actual.GetHide() == false)45 assertProto(actual.GetEnable() == false)46 assertProto(actual.GetName() == "名稱2")47 assertProto(actual.GetReward().GetDesc() == "獎勵說明2")48 assertProto(actual.GetReward().GetGold() == 200)49 assertProto(actual.GetReward().GetDiamond() == 20)50 assertProto(actual.GetReward().GetCrystal() == 299)51 assertProto(actual.GetReward().GetFelIron() == 10)52 assertProto(actual.GetReward().GetAtium() == 2)53 assertProto(len(actual.GetReward().GetItem()) == 3)54 assertProto(actual.GetReward().GetItem()[0].GetItemID() == 10001)55 assertProto(actual.GetReward().GetItem()[0].GetType() == 1)56 assertProto(actual.GetReward().GetItem()[0].GetCount() == 1)57 assertProto(actual.GetReward().GetItem()[1].GetItemID() == 10002)58 assertProto(actual.GetReward().GetItem()[1].GetType() == 2)59 assertProto(actual.GetReward().GetItem()[1].GetCount() == 2)60 assertProto(actual.GetReward().GetItem()[2].GetItemID() == 10003)61 assertProto(actual.GetReward().GetItem()[2].GetType() == 3)62 assertProto(actual.GetReward().GetItem()[2].GetCount() == 3)63 actual, ok = reader.Datas[3]64 assertProto(ok == false)65 fmt.Println("verify proto: success")66}67//nolint // 太多魔術數字了, 所以只好略過lint68func verifyProto2(path string) {69 reader := sheeterProto.VerifyData2Reader{}70 if err := reader.FromPath(path); err != nil {71 panic(fmt.Errorf("verify proto: %w", err))72 } // if73 actual, ok := reader.Datas[1]74 assertProto(ok)75 assertProto(actual.GetKey() == 1)76 assertProto(actual.GetHide() == false)77 assertProto(actual.GetEnable() == true)78 assertProto(actual.GetName() == "名稱1")79 assertProto(actual.GetReward().GetDesc() == "獎勵說明1")80 assertProto(actual.GetReward().GetGold() == 100)81 assertProto(actual.GetReward().GetDiamond() == 10)82 assertProto(actual.GetReward().GetCrystal() == 0)83 assertProto(actual.GetReward().GetFelIron() == 0)84 assertProto(actual.GetReward().GetAtium() == 0)85 assertProto(len(actual.GetReward().GetItem()) == 3)86 assertProto(actual.GetReward().GetItem()[0].GetItemID() == 10001)87 assertProto(actual.GetReward().GetItem()[0].GetType() == 1)88 assertProto(actual.GetReward().GetItem()[0].GetCount() == 1)89 assertProto(actual.GetReward().GetItem()[1].GetItemID() == 10002)90 assertProto(actual.GetReward().GetItem()[1].GetType() == 2)91 assertProto(actual.GetReward().GetItem()[1].GetCount() == 2)92 assertProto(actual.GetReward().GetItem()[2].GetItemID() == 0)93 assertProto(actual.GetReward().GetItem()[2].GetType() == 0)94 assertProto(actual.GetReward().GetItem()[2].GetCount() == 0)95 actual, ok = reader.Datas[2]96 assertProto(ok)97 assertProto(actual.GetKey() == 2)98 assertProto(actual.GetHide() == false)99 assertProto(actual.GetEnable() == false)100 assertProto(actual.GetName() == "名稱2")101 assertProto(actual.GetReward().GetDesc() == "獎勵說明2")102 assertProto(actual.GetReward().GetGold() == 200)103 assertProto(actual.GetReward().GetDiamond() == 20)104 assertProto(actual.GetReward().GetCrystal() == 0)105 assertProto(actual.GetReward().GetFelIron() == 0)106 assertProto(actual.GetReward().GetAtium() == 0)107 assertProto(len(actual.GetReward().GetItem()) == 3)108 assertProto(actual.GetReward().GetItem()[0].GetItemID() == 10001)109 assertProto(actual.GetReward().GetItem()[0].GetType() == 1)110 assertProto(actual.GetReward().GetItem()[0].GetCount() == 1)111 assertProto(actual.GetReward().GetItem()[1].GetItemID() == 10002)112 assertProto(actual.GetReward().GetItem()[1].GetType() == 2)113 assertProto(actual.GetReward().GetItem()[1].GetCount() == 2)114 assertProto(actual.GetReward().GetItem()[2].GetItemID() == 10003)115 assertProto(actual.GetReward().GetItem()[2].GetType() == 3)116 assertProto(actual.GetReward().GetItem()[2].GetCount() == 3)117 actual, ok = reader.Datas[3]118 assertProto(ok == false)119 fmt.Println("verify proto: success")120}121func assertProto(condition bool) {122 if condition == false {123 panic(fmt.Errorf("verify proto: verify failed"))124 } // if125}...

Full Screen

Full Screen

GetType

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 g := generator.New()4 g.CommandLineParameters("test")5 g.WrapTypes()6 g.SetPackageNames("test", "test", "test")7 g.BuildTypeNameMap()8 file := new(descriptor.FileDescriptorProto)9 file.Name = proto.String("test.proto")10 file.Package = proto.String("test")11 file.Dependency = []string{"google/protobuf/any.proto"}12 file.MessageType = make([]*descriptor.DescriptorProto, 0)13 message := new(descriptor.DescriptorProto)14 message.Name = proto.String("TestMessage")15 message.Field = make([]*descriptor.FieldDescriptorProto, 0)16 field := new(descriptor.FieldDescriptorProto)17 field.Name = proto.String("test_field")18 field.Type = descriptor.FieldDescriptorProto_TYPE_MESSAGE.Enum()19 field.TypeName = proto.String(".google.protobuf.Any")20 message.Field = append(message.Field, field)21 file.MessageType = append(file.MessageType, message)22 g.Request.FileToGenerate = append(g.Request.FileToGenerate, "test.proto")23 g.Request.ProtoFile = append(g.Request.ProtoFile, file)24 g.GenerateAllFiles()25 fmt.Println(g.Response.String())26}27import (28func main() {29 g := generator.New()30 g.CommandLineParameters("test")31 g.WrapTypes()32 g.SetPackageNames("test", "test

Full Screen

Full Screen

GetType

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 data, err := ioutil.ReadAll(os.Stdin)4 if err != nil {5 log.Fatalln("Reading input:", err)6 }7 requests := new(plugin.CodeGeneratorRequest)8 if err := proto.Unmarshal(data, requests); err != nil {9 log.Fatalln("Unmarshaling input:", err)10 }11 responses := new(plugin.CodeGeneratorResponse)12 for _, file := range requests.GetProtoFile() {13 if file.GetName() == "2.proto" {14 for _, message := range file.GetMessageType() {15 for _, field := range message.GetField() {16 fmt.Println(field.GetType())17 fmt.Println(field.GetTypeName())18 fmt.Println(field.GetName())19 }20 }21 }22 }23 data, err = proto.Marshal(responses)24 if err != nil {25 log.Fatalln("Marshaling output:", err)26 }27 if _, err := os.Stdout.Write(data); err != nil {28 log.Fatalln("Writing output:", err)29 }30}

Full Screen

Full Screen

GetType

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 t := &timestamp.Timestamp{Seconds: 100, Nanos: 200}4 w := &wrappers.Int32Value{Value: 123}5 a := &any.Any{TypeUrl: "foo", Value: []byte("bar")}6 protoMessages := []proto.Message{t, w, a}7 for _, v := range protoMessages {8 fmt.Println(proto.MessageName(v))9 }10}11func ToAny(m proto.Message) (*any.Any, error)12func ToAny(m proto.Message) (*anypb.Any, error)13func ToTimestamp(t *timestamp.Timestamp) *timestamppb.Timestamp14func ToTimestamp(t *timestamppb.Timestamp) *timestamp.Timestamp15func ToWrapperInt32(w *wrappers.Int32Value) *wrapperspb.Int32Value16func ToWrapperInt32(w *wrapperspb.Int32Value) *wrappers.Int32Value17func ToWrapperString(w *wrappers.StringValue) *wrapperspb.StringValue18func ToWrapperString(w *wrapperspb.StringValue) *wrappers.StringValue19import (

Full Screen

Full Screen

GetType

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 t := &timestamp.Timestamp{4 }5 any, err := anypb.New(t)6 if err != nil {7 fmt.Println("anypb.New() failed with error: ", err)8 }9 s := &wrappers.StringValue{10 }11 any2, err := anypb.New(s)12 if err != nil {13 fmt.Println("anypb.New() failed with error: ", err)14 }15 anySlice := []*anypb.Any{any, any2}16 protoSlice := make([]proto.Message, len(anySlice))17 for i, any := range anySlice {18 protoSlice[i] = proto.MessageType(typeURL).Elem().New()19 if err := any.UnmarshalTo(protoSlice[i]); err != nil {20 fmt.Println("any.UnmarshalTo() failed with error: ", err)21 }22 }23 for _, p := range protoSlice {24 fmt.Println(proto.MessageName(p))25 }26}27import (

Full Screen

Full Screen

GetType

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 d := duration.Duration{Seconds: 10, Nanos: 10}4 fmt.Println(reflect.TypeOf(d))5 fmt.Println(proto.MessageName(&d))6 fmt.Println(proto.MessageType(proto.MessageName(&d)))7 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem())8 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().Kind())9 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().NumField())10 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().Field(0).Name)11 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().Field(0).Type)12 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().Field(0).Type.Kind())13 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().Field(0).Type.Name())14 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().Field(0).Type.NumField())15 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().Field(0).Type.Field(0).Name)16 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().Field(0).Type.Field(0).Type)17 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().Field(0).Type.Field(0).Type.Kind())18 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().Field(0).Type.Field(0).Type.Name())19 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().Field(0).Type.Field(0).Type.NumField())20 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().Field(0).Type.Field(0).Type.Field(0).Name)21 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().Field(0).Type.Field(0).Type.Field(0).Type)22 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().Field(0).Type.Field(0).Type.Field(0).Type.Kind())23 fmt.Println(proto.MessageType(proto.MessageName(&d)).Elem().Field(0).Type.Field(0).Type.Field(0).Type.Name())24 fmt.Println(proto.MessageType

Full Screen

Full Screen

GetType

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 d := &date.Date{Year: 2019, Month: 4, Day: 20}4 fmt.Println("Date Object:", d)5 t := proto.MessageName(d)6 fmt.Println("Type of Date Object:", t)7 m := ptypes.MessageName(d)8 fmt.Println("Proto Message Type:", m)9}

Full Screen

Full Screen

GetType

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 pod := &api.Pod{4 ObjectMeta: api.ObjectMeta{5 },6 Spec: api.PodSpec{7 Containers: []api.Container{8 {9 Resources: api.ResourceRequirements{10 Limits: api.ResourceList{11 api.ResourceCPU: resource.MustParse("100m"),12 api.ResourceMemory: resource.MustParse("100Mi"),13 },14 Requests: api.ResourceList{15 api.ResourceCPU: resource.MustParse("100m"),16 api.ResourceMemory: resource.MustParse("100Mi"),17 },18 },19 },20 },21 },22 }23 podList := &api.PodList{24 ListMeta: api.ListMeta{25 },26 Items: []api.Pod{27 },28 }29 podStatus := &api.PodStatus{

Full Screen

Full Screen

GetType

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := &protoclass.ProtoClass{4 }5 fmt.Println(p.GetType())6}

Full Screen

Full Screen

GetType

Using AI Code Generation

copy

Full Screen

1proto.RegisterType((*MyMessage)(nil), "MyMessage")2m := &MyMessage{}3t := proto.MessageType("MyMessage")4if t != nil {5 fmt.Println(t.Elem().Name())6}7proto.RegisterType((*MyMessage)(nil), "MyMessage")8m := &MyMessage{}9fmt.Println(proto.MessageName(m))10proto.RegisterType((*MyMessage)(nil), "MyMessage")11m := &MyMessage{}12t := proto.MessageType(proto.MessageName(m))13if t != nil {14 fmt.Println(t.Elem().Name())15}16proto.RegisterType((*MyMessage)(nil), "MyMessage")17m := &MyMessage{}18t := proto.MessageType("MyMessage")19if t != nil {20 fmt.Println(t.Elem().Name())21}22proto.RegisterType((*MyMessage)(nil), "MyMessage")23m := &MyMessage{}24t := proto.MessageType(proto.MessageName(m))25if t != nil {26 fmt.Println(t.Elem().Name())27}28proto.RegisterType((*MyMessage)(nil), "MyMessage")29m := &MyMessage{}30t := proto.MessageType("MyMessage")31if t != nil {32 fmt.Println(t.Elem().Name())33}34proto.RegisterType((*MyMessage)(nil), "MyMessage")35m := &MyMessage{}36t := proto.MessageType(proto.MessageName(m))37if t != nil {38 fmt.Println(t.Elem().Name())39}40proto.RegisterType((*MyMessage)(nil), "MyMessage")41m := &MyMessage{}42t := proto.MessageType("MyMessage")43if t != nil {44 fmt.Println(t.Elem().Name())45}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Rod automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful