go.uber.org/yarpc@v1.72.1/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends/extends.go (about) 1 // Code generated by thriftrw v1.29.2. DO NOT EDIT. 2 // @generated 3 4 package extends 5 6 import ( 7 errors "errors" 8 fmt "fmt" 9 stream "go.uber.org/thriftrw/protocol/stream" 10 thriftreflect "go.uber.org/thriftrw/thriftreflect" 11 wire "go.uber.org/thriftrw/wire" 12 zapcore "go.uber.org/zap/zapcore" 13 strings "strings" 14 ) 15 16 // ThriftModule represents the IDL file used to generate this package. 17 var ThriftModule = &thriftreflect.ThriftModule{ 18 Name: "extends", 19 Package: "go.uber.org/yarpc/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends", 20 FilePath: "extends.thrift", 21 SHA1: "5dc89427890e0f8f94285fc648815882150591b9", 22 Raw: rawIDL, 23 } 24 25 const rawIDL = "service Name {\n\tstring name()\n}\nservice Foo extends Name {}\nservice Bar extends Foo {}\n" 26 27 // Name_Name_Args represents the arguments for the Name.name function. 28 // 29 // The arguments for name are sent and received over the wire as this struct. 30 type Name_Name_Args struct { 31 } 32 33 // ToWire translates a Name_Name_Args struct into a Thrift-level intermediate 34 // representation. This intermediate representation may be serialized 35 // into bytes using a ThriftRW protocol implementation. 36 // 37 // An error is returned if the struct or any of its fields failed to 38 // validate. 39 // 40 // x, err := v.ToWire() 41 // if err != nil { 42 // return err 43 // } 44 // 45 // if err := binaryProtocol.Encode(x, writer); err != nil { 46 // return err 47 // } 48 func (v *Name_Name_Args) ToWire() (wire.Value, error) { 49 var ( 50 fields [0]wire.Field 51 i int = 0 52 ) 53 54 return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil 55 } 56 57 // FromWire deserializes a Name_Name_Args struct from its Thrift-level 58 // representation. The Thrift-level representation may be obtained 59 // from a ThriftRW protocol implementation. 60 // 61 // An error is returned if we were unable to build a Name_Name_Args struct 62 // from the provided intermediate representation. 63 // 64 // x, err := binaryProtocol.Decode(reader, wire.TStruct) 65 // if err != nil { 66 // return nil, err 67 // } 68 // 69 // var v Name_Name_Args 70 // if err := v.FromWire(x); err != nil { 71 // return nil, err 72 // } 73 // return &v, nil 74 func (v *Name_Name_Args) FromWire(w wire.Value) error { 75 76 for _, field := range w.GetStruct().Fields { 77 switch field.ID { 78 } 79 } 80 81 return nil 82 } 83 84 // Encode serializes a Name_Name_Args struct directly into bytes, without going 85 // through an intermediary type. 86 // 87 // An error is returned if a Name_Name_Args struct could not be encoded. 88 func (v *Name_Name_Args) Encode(sw stream.Writer) error { 89 if err := sw.WriteStructBegin(); err != nil { 90 return err 91 } 92 93 return sw.WriteStructEnd() 94 } 95 96 // Decode deserializes a Name_Name_Args struct directly from its Thrift-level 97 // representation, without going through an intemediary type. 98 // 99 // An error is returned if a Name_Name_Args struct could not be generated from the wire 100 // representation. 101 func (v *Name_Name_Args) Decode(sr stream.Reader) error { 102 103 if err := sr.ReadStructBegin(); err != nil { 104 return err 105 } 106 107 fh, ok, err := sr.ReadFieldBegin() 108 if err != nil { 109 return err 110 } 111 112 for ok { 113 switch { 114 default: 115 if err := sr.Skip(fh.Type); err != nil { 116 return err 117 } 118 } 119 120 if err := sr.ReadFieldEnd(); err != nil { 121 return err 122 } 123 124 if fh, ok, err = sr.ReadFieldBegin(); err != nil { 125 return err 126 } 127 } 128 129 if err := sr.ReadStructEnd(); err != nil { 130 return err 131 } 132 133 return nil 134 } 135 136 // String returns a readable string representation of a Name_Name_Args 137 // struct. 138 func (v *Name_Name_Args) String() string { 139 if v == nil { 140 return "<nil>" 141 } 142 143 var fields [0]string 144 i := 0 145 146 return fmt.Sprintf("Name_Name_Args{%v}", strings.Join(fields[:i], ", ")) 147 } 148 149 // Equals returns true if all the fields of this Name_Name_Args match the 150 // provided Name_Name_Args. 151 // 152 // This function performs a deep comparison. 153 func (v *Name_Name_Args) Equals(rhs *Name_Name_Args) bool { 154 if v == nil { 155 return rhs == nil 156 } else if rhs == nil { 157 return false 158 } 159 160 return true 161 } 162 163 // MarshalLogObject implements zapcore.ObjectMarshaler, enabling 164 // fast logging of Name_Name_Args. 165 func (v *Name_Name_Args) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) { 166 if v == nil { 167 return nil 168 } 169 return err 170 } 171 172 // MethodName returns the name of the Thrift function as specified in 173 // the IDL, for which this struct represent the arguments. 174 // 175 // This will always be "name" for this struct. 176 func (v *Name_Name_Args) MethodName() string { 177 return "name" 178 } 179 180 // EnvelopeType returns the kind of value inside this struct. 181 // 182 // This will always be Call for this struct. 183 func (v *Name_Name_Args) EnvelopeType() wire.EnvelopeType { 184 return wire.Call 185 } 186 187 // Name_Name_Helper provides functions that aid in handling the 188 // parameters and return values of the Name.name 189 // function. 190 var Name_Name_Helper = struct { 191 // Args accepts the parameters of name in-order and returns 192 // the arguments struct for the function. 193 Args func() *Name_Name_Args 194 195 // IsException returns true if the given error can be thrown 196 // by name. 197 // 198 // An error can be thrown by name only if the 199 // corresponding exception type was mentioned in the 'throws' 200 // section for it in the Thrift file. 201 IsException func(error) bool 202 203 // WrapResponse returns the result struct for name 204 // given its return value and error. 205 // 206 // This allows mapping values and errors returned by 207 // name into a serializable result struct. 208 // WrapResponse returns a non-nil error if the provided 209 // error cannot be thrown by name 210 // 211 // value, err := name(args) 212 // result, err := Name_Name_Helper.WrapResponse(value, err) 213 // if err != nil { 214 // return fmt.Errorf("unexpected error from name: %v", err) 215 // } 216 // serialize(result) 217 WrapResponse func(string, error) (*Name_Name_Result, error) 218 219 // UnwrapResponse takes the result struct for name 220 // and returns the value or error returned by it. 221 // 222 // The error is non-nil only if name threw an 223 // exception. 224 // 225 // result := deserialize(bytes) 226 // value, err := Name_Name_Helper.UnwrapResponse(result) 227 UnwrapResponse func(*Name_Name_Result) (string, error) 228 }{} 229 230 func init() { 231 Name_Name_Helper.Args = func() *Name_Name_Args { 232 return &Name_Name_Args{} 233 } 234 235 Name_Name_Helper.IsException = func(err error) bool { 236 switch err.(type) { 237 default: 238 return false 239 } 240 } 241 242 Name_Name_Helper.WrapResponse = func(success string, err error) (*Name_Name_Result, error) { 243 if err == nil { 244 return &Name_Name_Result{Success: &success}, nil 245 } 246 247 return nil, err 248 } 249 Name_Name_Helper.UnwrapResponse = func(result *Name_Name_Result) (success string, err error) { 250 251 if result.Success != nil { 252 success = *result.Success 253 return 254 } 255 256 err = errors.New("expected a non-void result") 257 return 258 } 259 260 } 261 262 // Name_Name_Result represents the result of a Name.name function call. 263 // 264 // The result of a name execution is sent and received over the wire as this struct. 265 // 266 // Success is set only if the function did not throw an exception. 267 type Name_Name_Result struct { 268 // Value returned by name after a successful execution. 269 Success *string `json:"success,omitempty"` 270 } 271 272 // ToWire translates a Name_Name_Result struct into a Thrift-level intermediate 273 // representation. This intermediate representation may be serialized 274 // into bytes using a ThriftRW protocol implementation. 275 // 276 // An error is returned if the struct or any of its fields failed to 277 // validate. 278 // 279 // x, err := v.ToWire() 280 // if err != nil { 281 // return err 282 // } 283 // 284 // if err := binaryProtocol.Encode(x, writer); err != nil { 285 // return err 286 // } 287 func (v *Name_Name_Result) ToWire() (wire.Value, error) { 288 var ( 289 fields [1]wire.Field 290 i int = 0 291 w wire.Value 292 err error 293 ) 294 295 if v.Success != nil { 296 w, err = wire.NewValueString(*(v.Success)), error(nil) 297 if err != nil { 298 return w, err 299 } 300 fields[i] = wire.Field{ID: 0, Value: w} 301 i++ 302 } 303 304 if i != 1 { 305 return wire.Value{}, fmt.Errorf("Name_Name_Result should have exactly one field: got %v fields", i) 306 } 307 308 return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil 309 } 310 311 // FromWire deserializes a Name_Name_Result struct from its Thrift-level 312 // representation. The Thrift-level representation may be obtained 313 // from a ThriftRW protocol implementation. 314 // 315 // An error is returned if we were unable to build a Name_Name_Result struct 316 // from the provided intermediate representation. 317 // 318 // x, err := binaryProtocol.Decode(reader, wire.TStruct) 319 // if err != nil { 320 // return nil, err 321 // } 322 // 323 // var v Name_Name_Result 324 // if err := v.FromWire(x); err != nil { 325 // return nil, err 326 // } 327 // return &v, nil 328 func (v *Name_Name_Result) FromWire(w wire.Value) error { 329 var err error 330 331 for _, field := range w.GetStruct().Fields { 332 switch field.ID { 333 case 0: 334 if field.Value.Type() == wire.TBinary { 335 var x string 336 x, err = field.Value.GetString(), error(nil) 337 v.Success = &x 338 if err != nil { 339 return err 340 } 341 342 } 343 } 344 } 345 346 count := 0 347 if v.Success != nil { 348 count++ 349 } 350 if count != 1 { 351 return fmt.Errorf("Name_Name_Result should have exactly one field: got %v fields", count) 352 } 353 354 return nil 355 } 356 357 // Encode serializes a Name_Name_Result struct directly into bytes, without going 358 // through an intermediary type. 359 // 360 // An error is returned if a Name_Name_Result struct could not be encoded. 361 func (v *Name_Name_Result) Encode(sw stream.Writer) error { 362 if err := sw.WriteStructBegin(); err != nil { 363 return err 364 } 365 366 if v.Success != nil { 367 if err := sw.WriteFieldBegin(stream.FieldHeader{ID: 0, Type: wire.TBinary}); err != nil { 368 return err 369 } 370 if err := sw.WriteString(*(v.Success)); err != nil { 371 return err 372 } 373 if err := sw.WriteFieldEnd(); err != nil { 374 return err 375 } 376 } 377 378 count := 0 379 if v.Success != nil { 380 count++ 381 } 382 383 if count != 1 { 384 return fmt.Errorf("Name_Name_Result should have exactly one field: got %v fields", count) 385 } 386 387 return sw.WriteStructEnd() 388 } 389 390 // Decode deserializes a Name_Name_Result struct directly from its Thrift-level 391 // representation, without going through an intemediary type. 392 // 393 // An error is returned if a Name_Name_Result struct could not be generated from the wire 394 // representation. 395 func (v *Name_Name_Result) Decode(sr stream.Reader) error { 396 397 if err := sr.ReadStructBegin(); err != nil { 398 return err 399 } 400 401 fh, ok, err := sr.ReadFieldBegin() 402 if err != nil { 403 return err 404 } 405 406 for ok { 407 switch { 408 case fh.ID == 0 && fh.Type == wire.TBinary: 409 var x string 410 x, err = sr.ReadString() 411 v.Success = &x 412 if err != nil { 413 return err 414 } 415 416 default: 417 if err := sr.Skip(fh.Type); err != nil { 418 return err 419 } 420 } 421 422 if err := sr.ReadFieldEnd(); err != nil { 423 return err 424 } 425 426 if fh, ok, err = sr.ReadFieldBegin(); err != nil { 427 return err 428 } 429 } 430 431 if err := sr.ReadStructEnd(); err != nil { 432 return err 433 } 434 435 count := 0 436 if v.Success != nil { 437 count++ 438 } 439 if count != 1 { 440 return fmt.Errorf("Name_Name_Result should have exactly one field: got %v fields", count) 441 } 442 443 return nil 444 } 445 446 // String returns a readable string representation of a Name_Name_Result 447 // struct. 448 func (v *Name_Name_Result) String() string { 449 if v == nil { 450 return "<nil>" 451 } 452 453 var fields [1]string 454 i := 0 455 if v.Success != nil { 456 fields[i] = fmt.Sprintf("Success: %v", *(v.Success)) 457 i++ 458 } 459 460 return fmt.Sprintf("Name_Name_Result{%v}", strings.Join(fields[:i], ", ")) 461 } 462 463 func _String_EqualsPtr(lhs, rhs *string) bool { 464 if lhs != nil && rhs != nil { 465 466 x := *lhs 467 y := *rhs 468 return (x == y) 469 } 470 return lhs == nil && rhs == nil 471 } 472 473 // Equals returns true if all the fields of this Name_Name_Result match the 474 // provided Name_Name_Result. 475 // 476 // This function performs a deep comparison. 477 func (v *Name_Name_Result) Equals(rhs *Name_Name_Result) bool { 478 if v == nil { 479 return rhs == nil 480 } else if rhs == nil { 481 return false 482 } 483 if !_String_EqualsPtr(v.Success, rhs.Success) { 484 return false 485 } 486 487 return true 488 } 489 490 // MarshalLogObject implements zapcore.ObjectMarshaler, enabling 491 // fast logging of Name_Name_Result. 492 func (v *Name_Name_Result) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) { 493 if v == nil { 494 return nil 495 } 496 if v.Success != nil { 497 enc.AddString("success", *v.Success) 498 } 499 return err 500 } 501 502 // GetSuccess returns the value of Success if it is set or its 503 // zero value if it is unset. 504 func (v *Name_Name_Result) GetSuccess() (o string) { 505 if v != nil && v.Success != nil { 506 return *v.Success 507 } 508 509 return 510 } 511 512 // IsSetSuccess returns true if Success is not nil. 513 func (v *Name_Name_Result) IsSetSuccess() bool { 514 return v != nil && v.Success != nil 515 } 516 517 // MethodName returns the name of the Thrift function as specified in 518 // the IDL, for which this struct represent the result. 519 // 520 // This will always be "name" for this struct. 521 func (v *Name_Name_Result) MethodName() string { 522 return "name" 523 } 524 525 // EnvelopeType returns the kind of value inside this struct. 526 // 527 // This will always be Reply for this struct. 528 func (v *Name_Name_Result) EnvelopeType() wire.EnvelopeType { 529 return wire.Reply 530 }