github.com/cloudwego/kitex@v0.9.0/internal/mocks/thrift/fast/k-test.go (about) 1 /* 2 * Copyright 2022 CloudWeGo Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // Code generated by Kitex v0.4.3. DO NOT EDIT. 18 19 package fast 20 21 import ( 22 "bytes" 23 "fmt" 24 "reflect" 25 "strings" 26 27 "github.com/apache/thrift/lib/go/thrift" 28 29 "github.com/cloudwego/kitex/pkg/protocol/bthrift" 30 ) 31 32 // unused protection 33 var ( 34 _ = fmt.Formatter(nil) 35 _ = (*bytes.Buffer)(nil) 36 _ = (*strings.Builder)(nil) 37 _ = reflect.Type(nil) 38 _ = thrift.TProtocol(nil) 39 _ = bthrift.BinaryWriter(nil) 40 ) 41 42 func (p *MockReq) FastRead(buf []byte) (int, error) { 43 var err error 44 var offset int 45 var l int 46 var fieldTypeId thrift.TType 47 var fieldId int16 48 _, l, err = bthrift.Binary.ReadStructBegin(buf) 49 offset += l 50 if err != nil { 51 goto ReadStructBeginError 52 } 53 54 for { 55 _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 56 offset += l 57 if err != nil { 58 goto ReadFieldBeginError 59 } 60 if fieldTypeId == thrift.STOP { 61 break 62 } 63 switch fieldId { 64 case 1: 65 if fieldTypeId == thrift.STRING { 66 l, err = p.FastReadField1(buf[offset:]) 67 offset += l 68 if err != nil { 69 goto ReadFieldError 70 } 71 } else { 72 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 73 offset += l 74 if err != nil { 75 goto SkipFieldError 76 } 77 } 78 case 2: 79 if fieldTypeId == thrift.MAP { 80 l, err = p.FastReadField2(buf[offset:]) 81 offset += l 82 if err != nil { 83 goto ReadFieldError 84 } 85 } else { 86 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 87 offset += l 88 if err != nil { 89 goto SkipFieldError 90 } 91 } 92 case 3: 93 if fieldTypeId == thrift.LIST { 94 l, err = p.FastReadField3(buf[offset:]) 95 offset += l 96 if err != nil { 97 goto ReadFieldError 98 } 99 } else { 100 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 101 offset += l 102 if err != nil { 103 goto SkipFieldError 104 } 105 } 106 default: 107 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 108 offset += l 109 if err != nil { 110 goto SkipFieldError 111 } 112 } 113 114 l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 115 offset += l 116 if err != nil { 117 goto ReadFieldEndError 118 } 119 } 120 l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 121 offset += l 122 if err != nil { 123 goto ReadStructEndError 124 } 125 126 return offset, nil 127 ReadStructBeginError: 128 return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 129 ReadFieldBeginError: 130 return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 131 ReadFieldError: 132 return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_MockReq[fieldId]), err) 133 SkipFieldError: 134 return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 135 ReadFieldEndError: 136 return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 137 ReadStructEndError: 138 return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 139 } 140 141 func (p *MockReq) FastReadField1(buf []byte) (int, error) { 142 offset := 0 143 144 if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 145 return offset, err 146 } else { 147 offset += l 148 149 p.Msg = v 150 151 } 152 return offset, nil 153 } 154 155 func (p *MockReq) FastReadField2(buf []byte) (int, error) { 156 offset := 0 157 158 _, _, size, l, err := bthrift.Binary.ReadMapBegin(buf[offset:]) 159 offset += l 160 if err != nil { 161 return offset, err 162 } 163 p.StrMap = make(map[string]string, size) 164 for i := 0; i < size; i++ { 165 var _key string 166 if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 167 return offset, err 168 } else { 169 offset += l 170 171 _key = v 172 173 } 174 175 var _val string 176 if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 177 return offset, err 178 } else { 179 offset += l 180 181 _val = v 182 183 } 184 185 p.StrMap[_key] = _val 186 } 187 if l, err := bthrift.Binary.ReadMapEnd(buf[offset:]); err != nil { 188 return offset, err 189 } else { 190 offset += l 191 } 192 return offset, nil 193 } 194 195 func (p *MockReq) FastReadField3(buf []byte) (int, error) { 196 offset := 0 197 198 _, size, l, err := bthrift.Binary.ReadListBegin(buf[offset:]) 199 offset += l 200 if err != nil { 201 return offset, err 202 } 203 p.StrList = make([]string, 0, size) 204 for i := 0; i < size; i++ { 205 var _elem string 206 if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 207 return offset, err 208 } else { 209 offset += l 210 211 _elem = v 212 213 } 214 215 p.StrList = append(p.StrList, _elem) 216 } 217 if l, err := bthrift.Binary.ReadListEnd(buf[offset:]); err != nil { 218 return offset, err 219 } else { 220 offset += l 221 } 222 return offset, nil 223 } 224 225 // for compatibility 226 func (p *MockReq) FastWrite(buf []byte) int { 227 return 0 228 } 229 230 func (p *MockReq) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 231 offset := 0 232 offset += bthrift.Binary.WriteStructBegin(buf[offset:], "MockReq") 233 if p != nil { 234 offset += p.fastWriteField1(buf[offset:], binaryWriter) 235 offset += p.fastWriteField2(buf[offset:], binaryWriter) 236 offset += p.fastWriteField3(buf[offset:], binaryWriter) 237 } 238 offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 239 offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 240 return offset 241 } 242 243 func (p *MockReq) BLength() int { 244 l := 0 245 l += bthrift.Binary.StructBeginLength("MockReq") 246 if p != nil { 247 l += p.field1Length() 248 l += p.field2Length() 249 l += p.field3Length() 250 } 251 l += bthrift.Binary.FieldStopLength() 252 l += bthrift.Binary.StructEndLength() 253 return l 254 } 255 256 func (p *MockReq) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 257 offset := 0 258 offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "Msg", thrift.STRING, 1) 259 offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Msg) 260 261 offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 262 return offset 263 } 264 265 func (p *MockReq) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { 266 offset := 0 267 offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "strMap", thrift.MAP, 2) 268 mapBeginOffset := offset 269 offset += bthrift.Binary.MapBeginLength(thrift.STRING, thrift.STRING, 0) 270 var length int 271 for k, v := range p.StrMap { 272 length++ 273 274 offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, k) 275 276 offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, v) 277 278 } 279 bthrift.Binary.WriteMapBegin(buf[mapBeginOffset:], thrift.STRING, thrift.STRING, length) 280 offset += bthrift.Binary.WriteMapEnd(buf[offset:]) 281 offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 282 return offset 283 } 284 285 func (p *MockReq) fastWriteField3(buf []byte, binaryWriter bthrift.BinaryWriter) int { 286 offset := 0 287 offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "strList", thrift.LIST, 3) 288 listBeginOffset := offset 289 offset += bthrift.Binary.ListBeginLength(thrift.STRING, 0) 290 var length int 291 for _, v := range p.StrList { 292 length++ 293 offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, v) 294 295 } 296 bthrift.Binary.WriteListBegin(buf[listBeginOffset:], thrift.STRING, length) 297 offset += bthrift.Binary.WriteListEnd(buf[offset:]) 298 offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 299 return offset 300 } 301 302 func (p *MockReq) field1Length() int { 303 l := 0 304 l += bthrift.Binary.FieldBeginLength("Msg", thrift.STRING, 1) 305 l += bthrift.Binary.StringLengthNocopy(p.Msg) 306 307 l += bthrift.Binary.FieldEndLength() 308 return l 309 } 310 311 func (p *MockReq) field2Length() int { 312 l := 0 313 l += bthrift.Binary.FieldBeginLength("strMap", thrift.MAP, 2) 314 l += bthrift.Binary.MapBeginLength(thrift.STRING, thrift.STRING, len(p.StrMap)) 315 for k, v := range p.StrMap { 316 317 l += bthrift.Binary.StringLengthNocopy(k) 318 319 l += bthrift.Binary.StringLengthNocopy(v) 320 321 } 322 l += bthrift.Binary.MapEndLength() 323 l += bthrift.Binary.FieldEndLength() 324 return l 325 } 326 327 func (p *MockReq) field3Length() int { 328 l := 0 329 l += bthrift.Binary.FieldBeginLength("strList", thrift.LIST, 3) 330 l += bthrift.Binary.ListBeginLength(thrift.STRING, len(p.StrList)) 331 for _, v := range p.StrList { 332 l += bthrift.Binary.StringLengthNocopy(v) 333 334 } 335 l += bthrift.Binary.ListEndLength() 336 l += bthrift.Binary.FieldEndLength() 337 return l 338 } 339 340 func (p *Exception) FastRead(buf []byte) (int, error) { 341 var err error 342 var offset int 343 var l int 344 var fieldTypeId thrift.TType 345 var fieldId int16 346 _, l, err = bthrift.Binary.ReadStructBegin(buf) 347 offset += l 348 if err != nil { 349 goto ReadStructBeginError 350 } 351 352 for { 353 _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 354 offset += l 355 if err != nil { 356 goto ReadFieldBeginError 357 } 358 if fieldTypeId == thrift.STOP { 359 break 360 } 361 switch fieldId { 362 case 1: 363 if fieldTypeId == thrift.I32 { 364 l, err = p.FastReadField1(buf[offset:]) 365 offset += l 366 if err != nil { 367 goto ReadFieldError 368 } 369 } else { 370 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 371 offset += l 372 if err != nil { 373 goto SkipFieldError 374 } 375 } 376 case 255: 377 if fieldTypeId == thrift.STRING { 378 l, err = p.FastReadField255(buf[offset:]) 379 offset += l 380 if err != nil { 381 goto ReadFieldError 382 } 383 } else { 384 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 385 offset += l 386 if err != nil { 387 goto SkipFieldError 388 } 389 } 390 default: 391 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 392 offset += l 393 if err != nil { 394 goto SkipFieldError 395 } 396 } 397 398 l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 399 offset += l 400 if err != nil { 401 goto ReadFieldEndError 402 } 403 } 404 l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 405 offset += l 406 if err != nil { 407 goto ReadStructEndError 408 } 409 410 return offset, nil 411 ReadStructBeginError: 412 return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 413 ReadFieldBeginError: 414 return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 415 ReadFieldError: 416 return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_Exception[fieldId]), err) 417 SkipFieldError: 418 return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 419 ReadFieldEndError: 420 return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 421 ReadStructEndError: 422 return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 423 } 424 425 func (p *Exception) FastReadField1(buf []byte) (int, error) { 426 offset := 0 427 428 if v, l, err := bthrift.Binary.ReadI32(buf[offset:]); err != nil { 429 return offset, err 430 } else { 431 offset += l 432 433 p.Code = v 434 435 } 436 return offset, nil 437 } 438 439 func (p *Exception) FastReadField255(buf []byte) (int, error) { 440 offset := 0 441 442 if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 443 return offset, err 444 } else { 445 offset += l 446 447 p.Msg = v 448 449 } 450 return offset, nil 451 } 452 453 // for compatibility 454 func (p *Exception) FastWrite(buf []byte) int { 455 return 0 456 } 457 458 func (p *Exception) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 459 offset := 0 460 offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Exception") 461 if p != nil { 462 offset += p.fastWriteField1(buf[offset:], binaryWriter) 463 offset += p.fastWriteField255(buf[offset:], binaryWriter) 464 } 465 offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 466 offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 467 return offset 468 } 469 470 func (p *Exception) BLength() int { 471 l := 0 472 l += bthrift.Binary.StructBeginLength("Exception") 473 if p != nil { 474 l += p.field1Length() 475 l += p.field255Length() 476 } 477 l += bthrift.Binary.FieldStopLength() 478 l += bthrift.Binary.StructEndLength() 479 return l 480 } 481 482 func (p *Exception) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 483 offset := 0 484 offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "code", thrift.I32, 1) 485 offset += bthrift.Binary.WriteI32(buf[offset:], p.Code) 486 487 offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 488 return offset 489 } 490 491 func (p *Exception) fastWriteField255(buf []byte, binaryWriter bthrift.BinaryWriter) int { 492 offset := 0 493 offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "msg", thrift.STRING, 255) 494 offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Msg) 495 496 offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 497 return offset 498 } 499 500 func (p *Exception) field1Length() int { 501 l := 0 502 l += bthrift.Binary.FieldBeginLength("code", thrift.I32, 1) 503 l += bthrift.Binary.I32Length(p.Code) 504 505 l += bthrift.Binary.FieldEndLength() 506 return l 507 } 508 509 func (p *Exception) field255Length() int { 510 l := 0 511 l += bthrift.Binary.FieldBeginLength("msg", thrift.STRING, 255) 512 l += bthrift.Binary.StringLengthNocopy(p.Msg) 513 514 l += bthrift.Binary.FieldEndLength() 515 return l 516 } 517 518 func (p *MockTestArgs) FastRead(buf []byte) (int, error) { 519 var err error 520 var offset int 521 var l int 522 var fieldTypeId thrift.TType 523 var fieldId int16 524 _, l, err = bthrift.Binary.ReadStructBegin(buf) 525 offset += l 526 if err != nil { 527 goto ReadStructBeginError 528 } 529 530 for { 531 _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 532 offset += l 533 if err != nil { 534 goto ReadFieldBeginError 535 } 536 if fieldTypeId == thrift.STOP { 537 break 538 } 539 switch fieldId { 540 case 1: 541 if fieldTypeId == thrift.STRUCT { 542 l, err = p.FastReadField1(buf[offset:]) 543 offset += l 544 if err != nil { 545 goto ReadFieldError 546 } 547 } else { 548 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 549 offset += l 550 if err != nil { 551 goto SkipFieldError 552 } 553 } 554 default: 555 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 556 offset += l 557 if err != nil { 558 goto SkipFieldError 559 } 560 } 561 562 l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 563 offset += l 564 if err != nil { 565 goto ReadFieldEndError 566 } 567 } 568 l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 569 offset += l 570 if err != nil { 571 goto ReadStructEndError 572 } 573 574 return offset, nil 575 ReadStructBeginError: 576 return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 577 ReadFieldBeginError: 578 return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 579 ReadFieldError: 580 return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_MockTestArgs[fieldId]), err) 581 SkipFieldError: 582 return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 583 ReadFieldEndError: 584 return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 585 ReadStructEndError: 586 return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 587 } 588 589 func (p *MockTestArgs) FastReadField1(buf []byte) (int, error) { 590 offset := 0 591 592 tmp := NewMockReq() 593 if l, err := tmp.FastRead(buf[offset:]); err != nil { 594 return offset, err 595 } else { 596 offset += l 597 } 598 p.Req = tmp 599 return offset, nil 600 } 601 602 // for compatibility 603 func (p *MockTestArgs) FastWrite(buf []byte) int { 604 return 0 605 } 606 607 func (p *MockTestArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 608 offset := 0 609 offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Test_args") 610 if p != nil { 611 offset += p.fastWriteField1(buf[offset:], binaryWriter) 612 } 613 offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 614 offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 615 return offset 616 } 617 618 func (p *MockTestArgs) BLength() int { 619 l := 0 620 l += bthrift.Binary.StructBeginLength("Test_args") 621 if p != nil { 622 l += p.field1Length() 623 } 624 l += bthrift.Binary.FieldStopLength() 625 l += bthrift.Binary.StructEndLength() 626 return l 627 } 628 629 func (p *MockTestArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 630 offset := 0 631 offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req", thrift.STRUCT, 1) 632 offset += p.Req.FastWriteNocopy(buf[offset:], binaryWriter) 633 offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 634 return offset 635 } 636 637 func (p *MockTestArgs) field1Length() int { 638 l := 0 639 l += bthrift.Binary.FieldBeginLength("req", thrift.STRUCT, 1) 640 l += p.Req.BLength() 641 l += bthrift.Binary.FieldEndLength() 642 return l 643 } 644 645 func (p *MockTestResult) FastRead(buf []byte) (int, error) { 646 var err error 647 var offset int 648 var l int 649 var fieldTypeId thrift.TType 650 var fieldId int16 651 _, l, err = bthrift.Binary.ReadStructBegin(buf) 652 offset += l 653 if err != nil { 654 goto ReadStructBeginError 655 } 656 657 for { 658 _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 659 offset += l 660 if err != nil { 661 goto ReadFieldBeginError 662 } 663 if fieldTypeId == thrift.STOP { 664 break 665 } 666 switch fieldId { 667 case 0: 668 if fieldTypeId == thrift.STRING { 669 l, err = p.FastReadField0(buf[offset:]) 670 offset += l 671 if err != nil { 672 goto ReadFieldError 673 } 674 } else { 675 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 676 offset += l 677 if err != nil { 678 goto SkipFieldError 679 } 680 } 681 default: 682 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 683 offset += l 684 if err != nil { 685 goto SkipFieldError 686 } 687 } 688 689 l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 690 offset += l 691 if err != nil { 692 goto ReadFieldEndError 693 } 694 } 695 l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 696 offset += l 697 if err != nil { 698 goto ReadStructEndError 699 } 700 701 return offset, nil 702 ReadStructBeginError: 703 return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 704 ReadFieldBeginError: 705 return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 706 ReadFieldError: 707 return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_MockTestResult[fieldId]), err) 708 SkipFieldError: 709 return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 710 ReadFieldEndError: 711 return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 712 ReadStructEndError: 713 return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 714 } 715 716 func (p *MockTestResult) FastReadField0(buf []byte) (int, error) { 717 offset := 0 718 719 if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 720 return offset, err 721 } else { 722 offset += l 723 p.Success = &v 724 725 } 726 return offset, nil 727 } 728 729 // for compatibility 730 func (p *MockTestResult) FastWrite(buf []byte) int { 731 return 0 732 } 733 734 func (p *MockTestResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 735 offset := 0 736 offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Test_result") 737 if p != nil { 738 offset += p.fastWriteField0(buf[offset:], binaryWriter) 739 } 740 offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 741 offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 742 return offset 743 } 744 745 func (p *MockTestResult) BLength() int { 746 l := 0 747 l += bthrift.Binary.StructBeginLength("Test_result") 748 if p != nil { 749 l += p.field0Length() 750 } 751 l += bthrift.Binary.FieldStopLength() 752 l += bthrift.Binary.StructEndLength() 753 return l 754 } 755 756 func (p *MockTestResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { 757 offset := 0 758 if p.IsSetSuccess() { 759 offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRING, 0) 760 offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, *p.Success) 761 762 offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 763 } 764 return offset 765 } 766 767 func (p *MockTestResult) field0Length() int { 768 l := 0 769 if p.IsSetSuccess() { 770 l += bthrift.Binary.FieldBeginLength("success", thrift.STRING, 0) 771 l += bthrift.Binary.StringLengthNocopy(*p.Success) 772 773 l += bthrift.Binary.FieldEndLength() 774 } 775 return l 776 } 777 778 func (p *MockExceptionTestArgs) FastRead(buf []byte) (int, error) { 779 var err error 780 var offset int 781 var l int 782 var fieldTypeId thrift.TType 783 var fieldId int16 784 _, l, err = bthrift.Binary.ReadStructBegin(buf) 785 offset += l 786 if err != nil { 787 goto ReadStructBeginError 788 } 789 790 for { 791 _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 792 offset += l 793 if err != nil { 794 goto ReadFieldBeginError 795 } 796 if fieldTypeId == thrift.STOP { 797 break 798 } 799 switch fieldId { 800 case 1: 801 if fieldTypeId == thrift.STRUCT { 802 l, err = p.FastReadField1(buf[offset:]) 803 offset += l 804 if err != nil { 805 goto ReadFieldError 806 } 807 } else { 808 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 809 offset += l 810 if err != nil { 811 goto SkipFieldError 812 } 813 } 814 default: 815 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 816 offset += l 817 if err != nil { 818 goto SkipFieldError 819 } 820 } 821 822 l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 823 offset += l 824 if err != nil { 825 goto ReadFieldEndError 826 } 827 } 828 l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 829 offset += l 830 if err != nil { 831 goto ReadStructEndError 832 } 833 834 return offset, nil 835 ReadStructBeginError: 836 return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 837 ReadFieldBeginError: 838 return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 839 ReadFieldError: 840 return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_MockExceptionTestArgs[fieldId]), err) 841 SkipFieldError: 842 return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 843 ReadFieldEndError: 844 return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 845 ReadStructEndError: 846 return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 847 } 848 849 func (p *MockExceptionTestArgs) FastReadField1(buf []byte) (int, error) { 850 offset := 0 851 852 tmp := NewMockReq() 853 if l, err := tmp.FastRead(buf[offset:]); err != nil { 854 return offset, err 855 } else { 856 offset += l 857 } 858 p.Req = tmp 859 return offset, nil 860 } 861 862 // for compatibility 863 func (p *MockExceptionTestArgs) FastWrite(buf []byte) int { 864 return 0 865 } 866 867 func (p *MockExceptionTestArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 868 offset := 0 869 offset += bthrift.Binary.WriteStructBegin(buf[offset:], "ExceptionTest_args") 870 if p != nil { 871 offset += p.fastWriteField1(buf[offset:], binaryWriter) 872 } 873 offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 874 offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 875 return offset 876 } 877 878 func (p *MockExceptionTestArgs) BLength() int { 879 l := 0 880 l += bthrift.Binary.StructBeginLength("ExceptionTest_args") 881 if p != nil { 882 l += p.field1Length() 883 } 884 l += bthrift.Binary.FieldStopLength() 885 l += bthrift.Binary.StructEndLength() 886 return l 887 } 888 889 func (p *MockExceptionTestArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 890 offset := 0 891 offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req", thrift.STRUCT, 1) 892 offset += p.Req.FastWriteNocopy(buf[offset:], binaryWriter) 893 offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 894 return offset 895 } 896 897 func (p *MockExceptionTestArgs) field1Length() int { 898 l := 0 899 l += bthrift.Binary.FieldBeginLength("req", thrift.STRUCT, 1) 900 l += p.Req.BLength() 901 l += bthrift.Binary.FieldEndLength() 902 return l 903 } 904 905 func (p *MockExceptionTestResult) FastRead(buf []byte) (int, error) { 906 var err error 907 var offset int 908 var l int 909 var fieldTypeId thrift.TType 910 var fieldId int16 911 _, l, err = bthrift.Binary.ReadStructBegin(buf) 912 offset += l 913 if err != nil { 914 goto ReadStructBeginError 915 } 916 917 for { 918 _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) 919 offset += l 920 if err != nil { 921 goto ReadFieldBeginError 922 } 923 if fieldTypeId == thrift.STOP { 924 break 925 } 926 switch fieldId { 927 case 0: 928 if fieldTypeId == thrift.STRING { 929 l, err = p.FastReadField0(buf[offset:]) 930 offset += l 931 if err != nil { 932 goto ReadFieldError 933 } 934 } else { 935 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 936 offset += l 937 if err != nil { 938 goto SkipFieldError 939 } 940 } 941 case 1: 942 if fieldTypeId == thrift.STRUCT { 943 l, err = p.FastReadField1(buf[offset:]) 944 offset += l 945 if err != nil { 946 goto ReadFieldError 947 } 948 } else { 949 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 950 offset += l 951 if err != nil { 952 goto SkipFieldError 953 } 954 } 955 default: 956 l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) 957 offset += l 958 if err != nil { 959 goto SkipFieldError 960 } 961 } 962 963 l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) 964 offset += l 965 if err != nil { 966 goto ReadFieldEndError 967 } 968 } 969 l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) 970 offset += l 971 if err != nil { 972 goto ReadStructEndError 973 } 974 975 return offset, nil 976 ReadStructBeginError: 977 return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) 978 ReadFieldBeginError: 979 return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) 980 ReadFieldError: 981 return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_MockExceptionTestResult[fieldId]), err) 982 SkipFieldError: 983 return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) 984 ReadFieldEndError: 985 return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) 986 ReadStructEndError: 987 return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) 988 } 989 990 func (p *MockExceptionTestResult) FastReadField0(buf []byte) (int, error) { 991 offset := 0 992 993 if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { 994 return offset, err 995 } else { 996 offset += l 997 p.Success = &v 998 999 } 1000 return offset, nil 1001 } 1002 1003 func (p *MockExceptionTestResult) FastReadField1(buf []byte) (int, error) { 1004 offset := 0 1005 1006 tmp := NewException() 1007 if l, err := tmp.FastRead(buf[offset:]); err != nil { 1008 return offset, err 1009 } else { 1010 offset += l 1011 } 1012 p.Err = tmp 1013 return offset, nil 1014 } 1015 1016 // for compatibility 1017 func (p *MockExceptionTestResult) FastWrite(buf []byte) int { 1018 return 0 1019 } 1020 1021 func (p *MockExceptionTestResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1022 offset := 0 1023 offset += bthrift.Binary.WriteStructBegin(buf[offset:], "ExceptionTest_result") 1024 if p != nil { 1025 offset += p.fastWriteField0(buf[offset:], binaryWriter) 1026 offset += p.fastWriteField1(buf[offset:], binaryWriter) 1027 } 1028 offset += bthrift.Binary.WriteFieldStop(buf[offset:]) 1029 offset += bthrift.Binary.WriteStructEnd(buf[offset:]) 1030 return offset 1031 } 1032 1033 func (p *MockExceptionTestResult) BLength() int { 1034 l := 0 1035 l += bthrift.Binary.StructBeginLength("ExceptionTest_result") 1036 if p != nil { 1037 l += p.field0Length() 1038 l += p.field1Length() 1039 } 1040 l += bthrift.Binary.FieldStopLength() 1041 l += bthrift.Binary.StructEndLength() 1042 return l 1043 } 1044 1045 func (p *MockExceptionTestResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1046 offset := 0 1047 if p.IsSetSuccess() { 1048 offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRING, 0) 1049 offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, *p.Success) 1050 1051 offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1052 } 1053 return offset 1054 } 1055 1056 func (p *MockExceptionTestResult) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { 1057 offset := 0 1058 if p.IsSetErr() { 1059 offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "err", thrift.STRUCT, 1) 1060 offset += p.Err.FastWriteNocopy(buf[offset:], binaryWriter) 1061 offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) 1062 } 1063 return offset 1064 } 1065 1066 func (p *MockExceptionTestResult) field0Length() int { 1067 l := 0 1068 if p.IsSetSuccess() { 1069 l += bthrift.Binary.FieldBeginLength("success", thrift.STRING, 0) 1070 l += bthrift.Binary.StringLengthNocopy(*p.Success) 1071 1072 l += bthrift.Binary.FieldEndLength() 1073 } 1074 return l 1075 } 1076 1077 func (p *MockExceptionTestResult) field1Length() int { 1078 l := 0 1079 if p.IsSetErr() { 1080 l += bthrift.Binary.FieldBeginLength("err", thrift.STRUCT, 1) 1081 l += p.Err.BLength() 1082 l += bthrift.Binary.FieldEndLength() 1083 } 1084 return l 1085 } 1086 1087 func (p *MockTestArgs) GetFirstArgument() interface{} { 1088 return p.Req 1089 } 1090 1091 func (p *MockTestResult) GetResult() interface{} { 1092 return p.Success 1093 } 1094 1095 func (p *MockExceptionTestArgs) GetFirstArgument() interface{} { 1096 return p.Req 1097 } 1098 1099 func (p *MockExceptionTestResult) GetResult() interface{} { 1100 return p.Success 1101 }