go.uber.org/yarpc@v1.72.1/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/NOSERVICES/NOSERVICES.go (about) 1 // Code generated by thriftrw v1.29.2. DO NOT EDIT. 2 // @generated 3 4 package NOSERVICES 5 6 import ( 7 fmt "fmt" 8 stream "go.uber.org/thriftrw/protocol/stream" 9 thriftreflect "go.uber.org/thriftrw/thriftreflect" 10 wire "go.uber.org/thriftrw/wire" 11 zapcore "go.uber.org/zap/zapcore" 12 strings "strings" 13 ) 14 15 type ExWithAnnotation struct { 16 Foo *string `json:"foo,omitempty"` 17 } 18 19 // ToWire translates a ExWithAnnotation struct into a Thrift-level intermediate 20 // representation. This intermediate representation may be serialized 21 // into bytes using a ThriftRW protocol implementation. 22 // 23 // An error is returned if the struct or any of its fields failed to 24 // validate. 25 // 26 // x, err := v.ToWire() 27 // if err != nil { 28 // return err 29 // } 30 // 31 // if err := binaryProtocol.Encode(x, writer); err != nil { 32 // return err 33 // } 34 func (v *ExWithAnnotation) ToWire() (wire.Value, error) { 35 var ( 36 fields [1]wire.Field 37 i int = 0 38 w wire.Value 39 err error 40 ) 41 42 if v.Foo != nil { 43 w, err = wire.NewValueString(*(v.Foo)), error(nil) 44 if err != nil { 45 return w, err 46 } 47 fields[i] = wire.Field{ID: 1, Value: w} 48 i++ 49 } 50 51 return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil 52 } 53 54 // FromWire deserializes a ExWithAnnotation struct from its Thrift-level 55 // representation. The Thrift-level representation may be obtained 56 // from a ThriftRW protocol implementation. 57 // 58 // An error is returned if we were unable to build a ExWithAnnotation struct 59 // from the provided intermediate representation. 60 // 61 // x, err := binaryProtocol.Decode(reader, wire.TStruct) 62 // if err != nil { 63 // return nil, err 64 // } 65 // 66 // var v ExWithAnnotation 67 // if err := v.FromWire(x); err != nil { 68 // return nil, err 69 // } 70 // return &v, nil 71 func (v *ExWithAnnotation) FromWire(w wire.Value) error { 72 var err error 73 74 for _, field := range w.GetStruct().Fields { 75 switch field.ID { 76 case 1: 77 if field.Value.Type() == wire.TBinary { 78 var x string 79 x, err = field.Value.GetString(), error(nil) 80 v.Foo = &x 81 if err != nil { 82 return err 83 } 84 85 } 86 } 87 } 88 89 return nil 90 } 91 92 // Encode serializes a ExWithAnnotation struct directly into bytes, without going 93 // through an intermediary type. 94 // 95 // An error is returned if a ExWithAnnotation struct could not be encoded. 96 func (v *ExWithAnnotation) Encode(sw stream.Writer) error { 97 if err := sw.WriteStructBegin(); err != nil { 98 return err 99 } 100 101 if v.Foo != nil { 102 if err := sw.WriteFieldBegin(stream.FieldHeader{ID: 1, Type: wire.TBinary}); err != nil { 103 return err 104 } 105 if err := sw.WriteString(*(v.Foo)); err != nil { 106 return err 107 } 108 if err := sw.WriteFieldEnd(); err != nil { 109 return err 110 } 111 } 112 113 return sw.WriteStructEnd() 114 } 115 116 // Decode deserializes a ExWithAnnotation struct directly from its Thrift-level 117 // representation, without going through an intemediary type. 118 // 119 // An error is returned if a ExWithAnnotation struct could not be generated from the wire 120 // representation. 121 func (v *ExWithAnnotation) Decode(sr stream.Reader) error { 122 123 if err := sr.ReadStructBegin(); err != nil { 124 return err 125 } 126 127 fh, ok, err := sr.ReadFieldBegin() 128 if err != nil { 129 return err 130 } 131 132 for ok { 133 switch { 134 case fh.ID == 1 && fh.Type == wire.TBinary: 135 var x string 136 x, err = sr.ReadString() 137 v.Foo = &x 138 if err != nil { 139 return err 140 } 141 142 default: 143 if err := sr.Skip(fh.Type); err != nil { 144 return err 145 } 146 } 147 148 if err := sr.ReadFieldEnd(); err != nil { 149 return err 150 } 151 152 if fh, ok, err = sr.ReadFieldBegin(); err != nil { 153 return err 154 } 155 } 156 157 if err := sr.ReadStructEnd(); err != nil { 158 return err 159 } 160 161 return nil 162 } 163 164 // String returns a readable string representation of a ExWithAnnotation 165 // struct. 166 func (v *ExWithAnnotation) String() string { 167 if v == nil { 168 return "<nil>" 169 } 170 171 var fields [1]string 172 i := 0 173 if v.Foo != nil { 174 fields[i] = fmt.Sprintf("Foo: %v", *(v.Foo)) 175 i++ 176 } 177 178 return fmt.Sprintf("ExWithAnnotation{%v}", strings.Join(fields[:i], ", ")) 179 } 180 181 // ErrorName is the name of this type as defined in the Thrift 182 // file. 183 func (*ExWithAnnotation) ErrorName() string { 184 return "ExWithAnnotation" 185 } 186 187 func _String_EqualsPtr(lhs, rhs *string) bool { 188 if lhs != nil && rhs != nil { 189 190 x := *lhs 191 y := *rhs 192 return (x == y) 193 } 194 return lhs == nil && rhs == nil 195 } 196 197 // Equals returns true if all the fields of this ExWithAnnotation match the 198 // provided ExWithAnnotation. 199 // 200 // This function performs a deep comparison. 201 func (v *ExWithAnnotation) Equals(rhs *ExWithAnnotation) bool { 202 if v == nil { 203 return rhs == nil 204 } else if rhs == nil { 205 return false 206 } 207 if !_String_EqualsPtr(v.Foo, rhs.Foo) { 208 return false 209 } 210 211 return true 212 } 213 214 // MarshalLogObject implements zapcore.ObjectMarshaler, enabling 215 // fast logging of ExWithAnnotation. 216 func (v *ExWithAnnotation) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) { 217 if v == nil { 218 return nil 219 } 220 if v.Foo != nil { 221 enc.AddString("foo", *v.Foo) 222 } 223 return err 224 } 225 226 // GetFoo returns the value of Foo if it is set or its 227 // zero value if it is unset. 228 func (v *ExWithAnnotation) GetFoo() (o string) { 229 if v != nil && v.Foo != nil { 230 return *v.Foo 231 } 232 233 return 234 } 235 236 // IsSetFoo returns true if Foo is not nil. 237 func (v *ExWithAnnotation) IsSetFoo() bool { 238 return v != nil && v.Foo != nil 239 } 240 241 func (v *ExWithAnnotation) Error() string { 242 return v.String() 243 } 244 245 type ExWithoutAnnotation struct { 246 Bar *string `json:"bar,omitempty"` 247 } 248 249 // ToWire translates a ExWithoutAnnotation struct into a Thrift-level intermediate 250 // representation. This intermediate representation may be serialized 251 // into bytes using a ThriftRW protocol implementation. 252 // 253 // An error is returned if the struct or any of its fields failed to 254 // validate. 255 // 256 // x, err := v.ToWire() 257 // if err != nil { 258 // return err 259 // } 260 // 261 // if err := binaryProtocol.Encode(x, writer); err != nil { 262 // return err 263 // } 264 func (v *ExWithoutAnnotation) ToWire() (wire.Value, error) { 265 var ( 266 fields [1]wire.Field 267 i int = 0 268 w wire.Value 269 err error 270 ) 271 272 if v.Bar != nil { 273 w, err = wire.NewValueString(*(v.Bar)), error(nil) 274 if err != nil { 275 return w, err 276 } 277 fields[i] = wire.Field{ID: 1, Value: w} 278 i++ 279 } 280 281 return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil 282 } 283 284 // FromWire deserializes a ExWithoutAnnotation struct from its Thrift-level 285 // representation. The Thrift-level representation may be obtained 286 // from a ThriftRW protocol implementation. 287 // 288 // An error is returned if we were unable to build a ExWithoutAnnotation struct 289 // from the provided intermediate representation. 290 // 291 // x, err := binaryProtocol.Decode(reader, wire.TStruct) 292 // if err != nil { 293 // return nil, err 294 // } 295 // 296 // var v ExWithoutAnnotation 297 // if err := v.FromWire(x); err != nil { 298 // return nil, err 299 // } 300 // return &v, nil 301 func (v *ExWithoutAnnotation) FromWire(w wire.Value) error { 302 var err error 303 304 for _, field := range w.GetStruct().Fields { 305 switch field.ID { 306 case 1: 307 if field.Value.Type() == wire.TBinary { 308 var x string 309 x, err = field.Value.GetString(), error(nil) 310 v.Bar = &x 311 if err != nil { 312 return err 313 } 314 315 } 316 } 317 } 318 319 return nil 320 } 321 322 // Encode serializes a ExWithoutAnnotation struct directly into bytes, without going 323 // through an intermediary type. 324 // 325 // An error is returned if a ExWithoutAnnotation struct could not be encoded. 326 func (v *ExWithoutAnnotation) Encode(sw stream.Writer) error { 327 if err := sw.WriteStructBegin(); err != nil { 328 return err 329 } 330 331 if v.Bar != nil { 332 if err := sw.WriteFieldBegin(stream.FieldHeader{ID: 1, Type: wire.TBinary}); err != nil { 333 return err 334 } 335 if err := sw.WriteString(*(v.Bar)); err != nil { 336 return err 337 } 338 if err := sw.WriteFieldEnd(); err != nil { 339 return err 340 } 341 } 342 343 return sw.WriteStructEnd() 344 } 345 346 // Decode deserializes a ExWithoutAnnotation struct directly from its Thrift-level 347 // representation, without going through an intemediary type. 348 // 349 // An error is returned if a ExWithoutAnnotation struct could not be generated from the wire 350 // representation. 351 func (v *ExWithoutAnnotation) Decode(sr stream.Reader) error { 352 353 if err := sr.ReadStructBegin(); err != nil { 354 return err 355 } 356 357 fh, ok, err := sr.ReadFieldBegin() 358 if err != nil { 359 return err 360 } 361 362 for ok { 363 switch { 364 case fh.ID == 1 && fh.Type == wire.TBinary: 365 var x string 366 x, err = sr.ReadString() 367 v.Bar = &x 368 if err != nil { 369 return err 370 } 371 372 default: 373 if err := sr.Skip(fh.Type); err != nil { 374 return err 375 } 376 } 377 378 if err := sr.ReadFieldEnd(); err != nil { 379 return err 380 } 381 382 if fh, ok, err = sr.ReadFieldBegin(); err != nil { 383 return err 384 } 385 } 386 387 if err := sr.ReadStructEnd(); err != nil { 388 return err 389 } 390 391 return nil 392 } 393 394 // String returns a readable string representation of a ExWithoutAnnotation 395 // struct. 396 func (v *ExWithoutAnnotation) String() string { 397 if v == nil { 398 return "<nil>" 399 } 400 401 var fields [1]string 402 i := 0 403 if v.Bar != nil { 404 fields[i] = fmt.Sprintf("Bar: %v", *(v.Bar)) 405 i++ 406 } 407 408 return fmt.Sprintf("ExWithoutAnnotation{%v}", strings.Join(fields[:i], ", ")) 409 } 410 411 // ErrorName is the name of this type as defined in the Thrift 412 // file. 413 func (*ExWithoutAnnotation) ErrorName() string { 414 return "ExWithoutAnnotation" 415 } 416 417 // Equals returns true if all the fields of this ExWithoutAnnotation match the 418 // provided ExWithoutAnnotation. 419 // 420 // This function performs a deep comparison. 421 func (v *ExWithoutAnnotation) Equals(rhs *ExWithoutAnnotation) bool { 422 if v == nil { 423 return rhs == nil 424 } else if rhs == nil { 425 return false 426 } 427 if !_String_EqualsPtr(v.Bar, rhs.Bar) { 428 return false 429 } 430 431 return true 432 } 433 434 // MarshalLogObject implements zapcore.ObjectMarshaler, enabling 435 // fast logging of ExWithoutAnnotation. 436 func (v *ExWithoutAnnotation) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) { 437 if v == nil { 438 return nil 439 } 440 if v.Bar != nil { 441 enc.AddString("bar", *v.Bar) 442 } 443 return err 444 } 445 446 // GetBar returns the value of Bar if it is set or its 447 // zero value if it is unset. 448 func (v *ExWithoutAnnotation) GetBar() (o string) { 449 if v != nil && v.Bar != nil { 450 return *v.Bar 451 } 452 453 return 454 } 455 456 // IsSetBar returns true if Bar is not nil. 457 func (v *ExWithoutAnnotation) IsSetBar() bool { 458 return v != nil && v.Bar != nil 459 } 460 461 func (v *ExWithoutAnnotation) Error() string { 462 return v.String() 463 } 464 465 type Struct struct { 466 Baz *string `json:"baz,omitempty"` 467 } 468 469 // ToWire translates a Struct struct into a Thrift-level intermediate 470 // representation. This intermediate representation may be serialized 471 // into bytes using a ThriftRW protocol implementation. 472 // 473 // An error is returned if the struct or any of its fields failed to 474 // validate. 475 // 476 // x, err := v.ToWire() 477 // if err != nil { 478 // return err 479 // } 480 // 481 // if err := binaryProtocol.Encode(x, writer); err != nil { 482 // return err 483 // } 484 func (v *Struct) ToWire() (wire.Value, error) { 485 var ( 486 fields [1]wire.Field 487 i int = 0 488 w wire.Value 489 err error 490 ) 491 492 if v.Baz != nil { 493 w, err = wire.NewValueString(*(v.Baz)), error(nil) 494 if err != nil { 495 return w, err 496 } 497 fields[i] = wire.Field{ID: 1, Value: w} 498 i++ 499 } 500 501 return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil 502 } 503 504 // FromWire deserializes a Struct struct from its Thrift-level 505 // representation. The Thrift-level representation may be obtained 506 // from a ThriftRW protocol implementation. 507 // 508 // An error is returned if we were unable to build a Struct struct 509 // from the provided intermediate representation. 510 // 511 // x, err := binaryProtocol.Decode(reader, wire.TStruct) 512 // if err != nil { 513 // return nil, err 514 // } 515 // 516 // var v Struct 517 // if err := v.FromWire(x); err != nil { 518 // return nil, err 519 // } 520 // return &v, nil 521 func (v *Struct) FromWire(w wire.Value) error { 522 var err error 523 524 for _, field := range w.GetStruct().Fields { 525 switch field.ID { 526 case 1: 527 if field.Value.Type() == wire.TBinary { 528 var x string 529 x, err = field.Value.GetString(), error(nil) 530 v.Baz = &x 531 if err != nil { 532 return err 533 } 534 535 } 536 } 537 } 538 539 return nil 540 } 541 542 // Encode serializes a Struct struct directly into bytes, without going 543 // through an intermediary type. 544 // 545 // An error is returned if a Struct struct could not be encoded. 546 func (v *Struct) Encode(sw stream.Writer) error { 547 if err := sw.WriteStructBegin(); err != nil { 548 return err 549 } 550 551 if v.Baz != nil { 552 if err := sw.WriteFieldBegin(stream.FieldHeader{ID: 1, Type: wire.TBinary}); err != nil { 553 return err 554 } 555 if err := sw.WriteString(*(v.Baz)); err != nil { 556 return err 557 } 558 if err := sw.WriteFieldEnd(); err != nil { 559 return err 560 } 561 } 562 563 return sw.WriteStructEnd() 564 } 565 566 // Decode deserializes a Struct struct directly from its Thrift-level 567 // representation, without going through an intemediary type. 568 // 569 // An error is returned if a Struct struct could not be generated from the wire 570 // representation. 571 func (v *Struct) Decode(sr stream.Reader) error { 572 573 if err := sr.ReadStructBegin(); err != nil { 574 return err 575 } 576 577 fh, ok, err := sr.ReadFieldBegin() 578 if err != nil { 579 return err 580 } 581 582 for ok { 583 switch { 584 case fh.ID == 1 && fh.Type == wire.TBinary: 585 var x string 586 x, err = sr.ReadString() 587 v.Baz = &x 588 if err != nil { 589 return err 590 } 591 592 default: 593 if err := sr.Skip(fh.Type); err != nil { 594 return err 595 } 596 } 597 598 if err := sr.ReadFieldEnd(); err != nil { 599 return err 600 } 601 602 if fh, ok, err = sr.ReadFieldBegin(); err != nil { 603 return err 604 } 605 } 606 607 if err := sr.ReadStructEnd(); err != nil { 608 return err 609 } 610 611 return nil 612 } 613 614 // String returns a readable string representation of a Struct 615 // struct. 616 func (v *Struct) String() string { 617 if v == nil { 618 return "<nil>" 619 } 620 621 var fields [1]string 622 i := 0 623 if v.Baz != nil { 624 fields[i] = fmt.Sprintf("Baz: %v", *(v.Baz)) 625 i++ 626 } 627 628 return fmt.Sprintf("Struct{%v}", strings.Join(fields[:i], ", ")) 629 } 630 631 // Equals returns true if all the fields of this Struct match the 632 // provided Struct. 633 // 634 // This function performs a deep comparison. 635 func (v *Struct) Equals(rhs *Struct) bool { 636 if v == nil { 637 return rhs == nil 638 } else if rhs == nil { 639 return false 640 } 641 if !_String_EqualsPtr(v.Baz, rhs.Baz) { 642 return false 643 } 644 645 return true 646 } 647 648 // MarshalLogObject implements zapcore.ObjectMarshaler, enabling 649 // fast logging of Struct. 650 func (v *Struct) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) { 651 if v == nil { 652 return nil 653 } 654 if v.Baz != nil { 655 enc.AddString("baz", *v.Baz) 656 } 657 return err 658 } 659 660 // GetBaz returns the value of Baz if it is set or its 661 // zero value if it is unset. 662 func (v *Struct) GetBaz() (o string) { 663 if v != nil && v.Baz != nil { 664 return *v.Baz 665 } 666 667 return 668 } 669 670 // IsSetBaz returns true if Baz is not nil. 671 func (v *Struct) IsSetBaz() bool { 672 return v != nil && v.Baz != nil 673 } 674 675 // ThriftModule represents the IDL file used to generate this package. 676 var ThriftModule = &thriftreflect.ThriftModule{ 677 Name: "NOSERVICES", 678 Package: "go.uber.org/yarpc/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/NOSERVICES", 679 FilePath: "NOSERVICES.thrift", 680 SHA1: "bc28a223c8e87e320722bf77136e0eec1f1d18d6", 681 Raw: rawIDL, 682 } 683 684 const rawIDL = "// Thrift file with no service to ensure that types_yarpc.go is always\n// generated.\n\nexception ExWithAnnotation {\n 1: optional string foo\n} (\n rpc.code = \"OUT_OF_RANGE\"\n)\n\nexception ExWithoutAnnotation {\n 1: optional string bar\n}\n\nstruct Struct {\n 1: optional string baz\n}\n"