github.com/cloudwego/dynamicgo@v0.2.6-0.20240519101509-707f41b6b834/testdata/kitex_gen/skip/skip.go (about) 1 // Code generated by thriftgo (0.1.3). DO NOT EDIT. 2 3 package skip 4 5 import ( 6 "context" 7 "fmt" 8 "github.com/apache/thrift/lib/go/thrift" 9 "strings" 10 ) 11 12 type TestListMap struct { 13 ListMap []map[string]string `thrift:"listMap,1" json:"listMap"` 14 } 15 16 func NewTestListMap() *TestListMap { 17 return &TestListMap{} 18 } 19 20 func (p *TestListMap) GetListMap() (v []map[string]string) { 21 return p.ListMap 22 } 23 func (p *TestListMap) SetListMap(val []map[string]string) { 24 p.ListMap = val 25 } 26 27 var fieldIDToName_TestListMap = map[int16]string{ 28 1: "listMap", 29 } 30 31 func (p *TestListMap) Read(iprot thrift.TProtocol) (err error) { 32 33 var fieldTypeId thrift.TType 34 var fieldId int16 35 36 if _, err = iprot.ReadStructBegin(); err != nil { 37 goto ReadStructBeginError 38 } 39 40 for { 41 _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() 42 if err != nil { 43 goto ReadFieldBeginError 44 } 45 if fieldTypeId == thrift.STOP { 46 break 47 } 48 49 switch fieldId { 50 case 1: 51 if fieldTypeId == thrift.LIST { 52 if err = p.ReadField1(iprot); err != nil { 53 goto ReadFieldError 54 } 55 } else { 56 if err = iprot.Skip(fieldTypeId); err != nil { 57 goto SkipFieldError 58 } 59 } 60 default: 61 if err = iprot.Skip(fieldTypeId); err != nil { 62 goto SkipFieldError 63 } 64 } 65 66 if err = iprot.ReadFieldEnd(); err != nil { 67 goto ReadFieldEndError 68 } 69 } 70 if err = iprot.ReadStructEnd(); err != nil { 71 goto ReadStructEndError 72 } 73 74 return nil 75 ReadStructBeginError: 76 return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 77 ReadFieldBeginError: 78 return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 79 ReadFieldError: 80 return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_TestListMap[fieldId]), err) 81 SkipFieldError: 82 return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 83 84 ReadFieldEndError: 85 return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 86 ReadStructEndError: 87 return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 88 } 89 90 func (p *TestListMap) ReadField1(iprot thrift.TProtocol) error { 91 _, size, err := iprot.ReadListBegin() 92 if err != nil { 93 return err 94 } 95 p.ListMap = make([]map[string]string, 0, size) 96 for i := 0; i < size; i++ { 97 _, _, size, err := iprot.ReadMapBegin() 98 if err != nil { 99 return err 100 } 101 _elem := make(map[string]string, size) 102 for i := 0; i < size; i++ { 103 var _key string 104 if v, err := iprot.ReadString(); err != nil { 105 return err 106 } else { 107 _key = v 108 } 109 110 var _val string 111 if v, err := iprot.ReadString(); err != nil { 112 return err 113 } else { 114 _val = v 115 } 116 117 _elem[_key] = _val 118 } 119 if err := iprot.ReadMapEnd(); err != nil { 120 return err 121 } 122 123 p.ListMap = append(p.ListMap, _elem) 124 } 125 if err := iprot.ReadListEnd(); err != nil { 126 return err 127 } 128 return nil 129 } 130 131 func (p *TestListMap) Write(oprot thrift.TProtocol) (err error) { 132 var fieldId int16 133 if err = oprot.WriteStructBegin("TestListMap"); err != nil { 134 goto WriteStructBeginError 135 } 136 if p != nil { 137 if err = p.writeField1(oprot); err != nil { 138 fieldId = 1 139 goto WriteFieldError 140 } 141 142 } 143 if err = oprot.WriteFieldStop(); err != nil { 144 goto WriteFieldStopError 145 } 146 if err = oprot.WriteStructEnd(); err != nil { 147 goto WriteStructEndError 148 } 149 return nil 150 WriteStructBeginError: 151 return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) 152 WriteFieldError: 153 return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) 154 WriteFieldStopError: 155 return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) 156 WriteStructEndError: 157 return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) 158 } 159 160 func (p *TestListMap) writeField1(oprot thrift.TProtocol) (err error) { 161 if err = oprot.WriteFieldBegin("listMap", thrift.LIST, 1); err != nil { 162 goto WriteFieldBeginError 163 } 164 if err := oprot.WriteListBegin(thrift.MAP, len(p.ListMap)); err != nil { 165 return err 166 } 167 for _, v := range p.ListMap { 168 if err := oprot.WriteMapBegin(thrift.STRING, thrift.STRING, len(v)); err != nil { 169 return err 170 } 171 for k, v := range v { 172 173 if err := oprot.WriteString(k); err != nil { 174 return err 175 } 176 177 if err := oprot.WriteString(v); err != nil { 178 return err 179 } 180 } 181 if err := oprot.WriteMapEnd(); err != nil { 182 return err 183 } 184 } 185 if err := oprot.WriteListEnd(); err != nil { 186 return err 187 } 188 if err = oprot.WriteFieldEnd(); err != nil { 189 goto WriteFieldEndError 190 } 191 return nil 192 WriteFieldBeginError: 193 return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) 194 WriteFieldEndError: 195 return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) 196 } 197 198 func (p *TestListMap) String() string { 199 if p == nil { 200 return "<nil>" 201 } 202 return fmt.Sprintf("TestListMap(%+v)", *p) 203 } 204 205 func (p *TestListMap) DeepEqual(ano *TestListMap) bool { 206 if p == ano { 207 return true 208 } else if p == nil || ano == nil { 209 return false 210 } 211 if !p.Field1DeepEqual(ano.ListMap) { 212 return false 213 } 214 return true 215 } 216 217 func (p *TestListMap) Field1DeepEqual(src []map[string]string) bool { 218 219 if len(p.ListMap) != len(src) { 220 return false 221 } 222 for i, v := range p.ListMap { 223 _src := src[i] 224 if len(v) != len(_src) { 225 return false 226 } 227 for k, v := range v { 228 _src1 := _src[k] 229 if strings.Compare(v, _src1) != 0 { 230 return false 231 } 232 } 233 } 234 return true 235 } 236 237 type SkipTest interface { 238 TestListMap(ctx context.Context, req *TestListMap) (r *TestListMap, err error) 239 } 240 241 type SkipTestClient struct { 242 c thrift.TClient 243 } 244 245 func NewSkipTestClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *SkipTestClient { 246 return &SkipTestClient{ 247 c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)), 248 } 249 } 250 251 func NewSkipTestClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *SkipTestClient { 252 return &SkipTestClient{ 253 c: thrift.NewTStandardClient(iprot, oprot), 254 } 255 } 256 257 func NewSkipTestClient(c thrift.TClient) *SkipTestClient { 258 return &SkipTestClient{ 259 c: c, 260 } 261 } 262 263 func (p *SkipTestClient) Client_() thrift.TClient { 264 return p.c 265 } 266 267 func (p *SkipTestClient) TestListMap(ctx context.Context, req *TestListMap) (r *TestListMap, err error) { 268 var _args SkipTestTestListMapArgs 269 _args.Req = req 270 var _result SkipTestTestListMapResult 271 if err = p.Client_().Call(ctx, "TestListMap", &_args, &_result); err != nil { 272 return 273 } 274 return _result.GetSuccess(), nil 275 } 276 277 type SkipTestProcessor struct { 278 processorMap map[string]thrift.TProcessorFunction 279 handler SkipTest 280 } 281 282 func (p *SkipTestProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { 283 p.processorMap[key] = processor 284 } 285 286 func (p *SkipTestProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { 287 processor, ok = p.processorMap[key] 288 return processor, ok 289 } 290 291 func (p *SkipTestProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { 292 return p.processorMap 293 } 294 295 func NewSkipTestProcessor(handler SkipTest) *SkipTestProcessor { 296 self := &SkipTestProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} 297 self.AddToProcessorMap("TestListMap", &skipTestProcessorTestListMap{handler: handler}) 298 return self 299 } 300 func (p *SkipTestProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { 301 name, _, seqId, err := iprot.ReadMessageBegin() 302 if err != nil { 303 return false, err 304 } 305 if processor, ok := p.GetProcessorFunction(name); ok { 306 return processor.Process(ctx, seqId, iprot, oprot) 307 } 308 iprot.Skip(thrift.STRUCT) 309 iprot.ReadMessageEnd() 310 x := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) 311 oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) 312 x.Write(oprot) 313 oprot.WriteMessageEnd() 314 oprot.Flush(ctx) 315 return false, x 316 } 317 318 type skipTestProcessorTestListMap struct { 319 handler SkipTest 320 } 321 322 func (p *skipTestProcessorTestListMap) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { 323 args := SkipTestTestListMapArgs{} 324 if err = args.Read(iprot); err != nil { 325 iprot.ReadMessageEnd() 326 x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) 327 oprot.WriteMessageBegin("TestListMap", thrift.EXCEPTION, seqId) 328 x.Write(oprot) 329 oprot.WriteMessageEnd() 330 oprot.Flush(ctx) 331 return false, err 332 } 333 334 iprot.ReadMessageEnd() 335 var err2 error 336 result := SkipTestTestListMapResult{} 337 var retval *TestListMap 338 if retval, err2 = p.handler.TestListMap(ctx, args.Req); err2 != nil { 339 x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing TestListMap: "+err2.Error()) 340 oprot.WriteMessageBegin("TestListMap", thrift.EXCEPTION, seqId) 341 x.Write(oprot) 342 oprot.WriteMessageEnd() 343 oprot.Flush(ctx) 344 return true, err2 345 } else { 346 result.Success = retval 347 } 348 if err2 = oprot.WriteMessageBegin("TestListMap", thrift.REPLY, seqId); err2 != nil { 349 err = err2 350 } 351 if err2 = result.Write(oprot); err == nil && err2 != nil { 352 err = err2 353 } 354 if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { 355 err = err2 356 } 357 if err2 = oprot.Flush(ctx); err == nil && err2 != nil { 358 err = err2 359 } 360 if err != nil { 361 return 362 } 363 return true, err 364 } 365 366 type SkipTestTestListMapArgs struct { 367 Req *TestListMap `thrift:"req,1" json:"req"` 368 } 369 370 func NewSkipTestTestListMapArgs() *SkipTestTestListMapArgs { 371 return &SkipTestTestListMapArgs{} 372 } 373 374 var SkipTestTestListMapArgs_Req_DEFAULT *TestListMap 375 376 func (p *SkipTestTestListMapArgs) GetReq() (v *TestListMap) { 377 if !p.IsSetReq() { 378 return SkipTestTestListMapArgs_Req_DEFAULT 379 } 380 return p.Req 381 } 382 func (p *SkipTestTestListMapArgs) SetReq(val *TestListMap) { 383 p.Req = val 384 } 385 386 var fieldIDToName_SkipTestTestListMapArgs = map[int16]string{ 387 1: "req", 388 } 389 390 func (p *SkipTestTestListMapArgs) IsSetReq() bool { 391 return p.Req != nil 392 } 393 394 func (p *SkipTestTestListMapArgs) Read(iprot thrift.TProtocol) (err error) { 395 396 var fieldTypeId thrift.TType 397 var fieldId int16 398 399 if _, err = iprot.ReadStructBegin(); err != nil { 400 goto ReadStructBeginError 401 } 402 403 for { 404 _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() 405 if err != nil { 406 goto ReadFieldBeginError 407 } 408 if fieldTypeId == thrift.STOP { 409 break 410 } 411 412 switch fieldId { 413 case 1: 414 if fieldTypeId == thrift.STRUCT { 415 if err = p.ReadField1(iprot); err != nil { 416 goto ReadFieldError 417 } 418 } else { 419 if err = iprot.Skip(fieldTypeId); err != nil { 420 goto SkipFieldError 421 } 422 } 423 default: 424 if err = iprot.Skip(fieldTypeId); err != nil { 425 goto SkipFieldError 426 } 427 } 428 429 if err = iprot.ReadFieldEnd(); err != nil { 430 goto ReadFieldEndError 431 } 432 } 433 if err = iprot.ReadStructEnd(); err != nil { 434 goto ReadStructEndError 435 } 436 437 return nil 438 ReadStructBeginError: 439 return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 440 ReadFieldBeginError: 441 return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 442 ReadFieldError: 443 return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_SkipTestTestListMapArgs[fieldId]), err) 444 SkipFieldError: 445 return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 446 447 ReadFieldEndError: 448 return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 449 ReadStructEndError: 450 return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 451 } 452 453 func (p *SkipTestTestListMapArgs) ReadField1(iprot thrift.TProtocol) error { 454 p.Req = NewTestListMap() 455 if err := p.Req.Read(iprot); err != nil { 456 return err 457 } 458 return nil 459 } 460 461 func (p *SkipTestTestListMapArgs) Write(oprot thrift.TProtocol) (err error) { 462 var fieldId int16 463 if err = oprot.WriteStructBegin("TestListMap_args"); err != nil { 464 goto WriteStructBeginError 465 } 466 if p != nil { 467 if err = p.writeField1(oprot); err != nil { 468 fieldId = 1 469 goto WriteFieldError 470 } 471 472 } 473 if err = oprot.WriteFieldStop(); err != nil { 474 goto WriteFieldStopError 475 } 476 if err = oprot.WriteStructEnd(); err != nil { 477 goto WriteStructEndError 478 } 479 return nil 480 WriteStructBeginError: 481 return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) 482 WriteFieldError: 483 return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) 484 WriteFieldStopError: 485 return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) 486 WriteStructEndError: 487 return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) 488 } 489 490 func (p *SkipTestTestListMapArgs) writeField1(oprot thrift.TProtocol) (err error) { 491 if err = oprot.WriteFieldBegin("req", thrift.STRUCT, 1); err != nil { 492 goto WriteFieldBeginError 493 } 494 if err := p.Req.Write(oprot); err != nil { 495 return err 496 } 497 if err = oprot.WriteFieldEnd(); err != nil { 498 goto WriteFieldEndError 499 } 500 return nil 501 WriteFieldBeginError: 502 return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) 503 WriteFieldEndError: 504 return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) 505 } 506 507 func (p *SkipTestTestListMapArgs) String() string { 508 if p == nil { 509 return "<nil>" 510 } 511 return fmt.Sprintf("SkipTestTestListMapArgs(%+v)", *p) 512 } 513 514 func (p *SkipTestTestListMapArgs) DeepEqual(ano *SkipTestTestListMapArgs) bool { 515 if p == ano { 516 return true 517 } else if p == nil || ano == nil { 518 return false 519 } 520 if !p.Field1DeepEqual(ano.Req) { 521 return false 522 } 523 return true 524 } 525 526 func (p *SkipTestTestListMapArgs) Field1DeepEqual(src *TestListMap) bool { 527 528 if !p.Req.DeepEqual(src) { 529 return false 530 } 531 return true 532 } 533 534 type SkipTestTestListMapResult struct { 535 Success *TestListMap `thrift:"success,0" json:"success,omitempty"` 536 } 537 538 func NewSkipTestTestListMapResult() *SkipTestTestListMapResult { 539 return &SkipTestTestListMapResult{} 540 } 541 542 var SkipTestTestListMapResult_Success_DEFAULT *TestListMap 543 544 func (p *SkipTestTestListMapResult) GetSuccess() (v *TestListMap) { 545 if !p.IsSetSuccess() { 546 return SkipTestTestListMapResult_Success_DEFAULT 547 } 548 return p.Success 549 } 550 func (p *SkipTestTestListMapResult) SetSuccess(x interface{}) { 551 p.Success = x.(*TestListMap) 552 } 553 554 var fieldIDToName_SkipTestTestListMapResult = map[int16]string{ 555 0: "success", 556 } 557 558 func (p *SkipTestTestListMapResult) IsSetSuccess() bool { 559 return p.Success != nil 560 } 561 562 func (p *SkipTestTestListMapResult) Read(iprot thrift.TProtocol) (err error) { 563 564 var fieldTypeId thrift.TType 565 var fieldId int16 566 567 if _, err = iprot.ReadStructBegin(); err != nil { 568 goto ReadStructBeginError 569 } 570 571 for { 572 _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() 573 if err != nil { 574 goto ReadFieldBeginError 575 } 576 if fieldTypeId == thrift.STOP { 577 break 578 } 579 580 switch fieldId { 581 case 0: 582 if fieldTypeId == thrift.STRUCT { 583 if err = p.ReadField0(iprot); err != nil { 584 goto ReadFieldError 585 } 586 } else { 587 if err = iprot.Skip(fieldTypeId); err != nil { 588 goto SkipFieldError 589 } 590 } 591 default: 592 if err = iprot.Skip(fieldTypeId); err != nil { 593 goto SkipFieldError 594 } 595 } 596 597 if err = iprot.ReadFieldEnd(); err != nil { 598 goto ReadFieldEndError 599 } 600 } 601 if err = iprot.ReadStructEnd(); err != nil { 602 goto ReadStructEndError 603 } 604 605 return nil 606 ReadStructBeginError: 607 return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 608 ReadFieldBeginError: 609 return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 610 ReadFieldError: 611 return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_SkipTestTestListMapResult[fieldId]), err) 612 SkipFieldError: 613 return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 614 615 ReadFieldEndError: 616 return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 617 ReadStructEndError: 618 return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 619 } 620 621 func (p *SkipTestTestListMapResult) ReadField0(iprot thrift.TProtocol) error { 622 p.Success = NewTestListMap() 623 if err := p.Success.Read(iprot); err != nil { 624 return err 625 } 626 return nil 627 } 628 629 func (p *SkipTestTestListMapResult) Write(oprot thrift.TProtocol) (err error) { 630 var fieldId int16 631 if err = oprot.WriteStructBegin("TestListMap_result"); err != nil { 632 goto WriteStructBeginError 633 } 634 if p != nil { 635 if err = p.writeField0(oprot); err != nil { 636 fieldId = 0 637 goto WriteFieldError 638 } 639 640 } 641 if err = oprot.WriteFieldStop(); err != nil { 642 goto WriteFieldStopError 643 } 644 if err = oprot.WriteStructEnd(); err != nil { 645 goto WriteStructEndError 646 } 647 return nil 648 WriteStructBeginError: 649 return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) 650 WriteFieldError: 651 return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) 652 WriteFieldStopError: 653 return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) 654 WriteStructEndError: 655 return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) 656 } 657 658 func (p *SkipTestTestListMapResult) writeField0(oprot thrift.TProtocol) (err error) { 659 if p.IsSetSuccess() { 660 if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { 661 goto WriteFieldBeginError 662 } 663 if err := p.Success.Write(oprot); err != nil { 664 return err 665 } 666 if err = oprot.WriteFieldEnd(); err != nil { 667 goto WriteFieldEndError 668 } 669 } 670 return nil 671 WriteFieldBeginError: 672 return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) 673 WriteFieldEndError: 674 return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) 675 } 676 677 func (p *SkipTestTestListMapResult) String() string { 678 if p == nil { 679 return "<nil>" 680 } 681 return fmt.Sprintf("SkipTestTestListMapResult(%+v)", *p) 682 } 683 684 func (p *SkipTestTestListMapResult) DeepEqual(ano *SkipTestTestListMapResult) bool { 685 if p == ano { 686 return true 687 } else if p == nil || ano == nil { 688 return false 689 } 690 if !p.Field0DeepEqual(ano.Success) { 691 return false 692 } 693 return true 694 } 695 696 func (p *SkipTestTestListMapResult) Field0DeepEqual(src *TestListMap) bool { 697 698 if !p.Success.DeepEqual(src) { 699 return false 700 } 701 return true 702 }