//go:build gofuzz
// +build gofuzz
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package fuzz
import (
"context"
"fmt"
"strconv"
"github.com/apache/thrift/lib/go/test/fuzz/gen-go/shared"
"github.com/apache/thrift/lib/go/test/fuzz/gen-go/tutorial"
"github.com/apache/thrift/lib/go/test/fuzz/gen-go/fuzztest"
"github.com/apache/thrift/lib/go/thrift"
)
const nbFuzzedProtocols = 2
// 10MB message size limit to prevent over-allocation during fuzzing
const FUZZ_MAX_MESSAGE_SIZE = 10 * 1024 * 1024
func fuzzChooseProtocol(d byte, t thrift.TTransport) thrift.TProtocol {
switch d % nbFuzzedProtocols {
default:
fallthrough
case 0:
return thrift.NewTBinaryProtocolFactoryConf(nil).GetProtocol(t)
case 1:
return thrift.NewTCompactProtocolFactoryConf(nil).GetProtocol(t)
case 2:
return thrift.NewTJSONProtocolFactory().GetProtocol(t)
}
}
func FuzzTutorial(data []byte) int {
if len(data) < 2 {
return 0
}
inputTransport := thrift.NewTMemoryBuffer()
inputTransport.Buffer.Write(data[2:])
outputTransport := thrift.NewTMemoryBuffer()
outputProtocol := fuzzChooseProtocol(data[0], outputTransport)
inputProtocol := fuzzChooseProtocol(data[1], inputTransport)
ctx := thrift.SetResponseHelper(
context.Background(),
thrift.TResponseHelper{
THeaderResponseHelper: thrift.NewTHeaderResponseHelper(outputProtocol),
},
)
handler := NewCalculatorHandler()
processor := tutorial.NewCalculatorProcessor(handler)
ok := true
var err error
for ok {
ok, err = processor.Process(ctx, inputProtocol, outputProtocol)
if err != nil {
// Handle parse error
return 0
}
res := make([]byte, 1024)
n, err := outputTransport.Buffer.Read(res)
fmt.Printf("lol %d %s %v\n", n, err, res)
}
return 1
}
type CalculatorHandler struct {
log map[int]*shared.SharedStruct
}
func NewCalculatorHandler() *CalculatorHandler {
return &CalculatorHandler{log: make(map[int]*shared.SharedStruct)}
}
func (p *CalculatorHandler) Ping(ctx context.Context) (err error) {
fmt.Print("ping()\n")
return nil
}
func (p *CalculatorHandler) Add(ctx context.Context, num1 int32, num2 int32) (retval17 int32, err error) {
fmt.Print("add(", num1, ",", num2, ")\n")
return num1 + num2, nil
}
func (p *CalculatorHandler) Calculate(ctx context.Context, logid int32, w *tutorial.Work) (val int32, err error) {
fmt.Print("calculate(", logid, ", {", w.Op, ",", w.Num1, ",", w.Num2, "})\n")
switch w.Op {
case tutorial.Operation_ADD:
val = w.Num1 + w.Num2
break
case tutorial.Operation_SUBTRACT:
val = w.Num1 - w.Num2
break
case tutorial.Operation_MULTIPLY:
val = w.Num1 * w.Num2
break
case tutorial.Operation_DIVIDE:
if w.Num2 == 0 {
ouch := tutorial.NewInvalidOperation()
ouch.WhatOp = int32(w.Op)
ouch.Why = "Cannot divide by 0"
err = ouch
return
}
val = w.Num1 / w.Num2
break
default:
ouch := tutorial.NewInvalidOperation()
ouch.WhatOp = int32(w.Op)
ouch.Why = "Unknown operation"
err = ouch
return
}
entry := shared.NewSharedStruct()
entry.Key = logid
entry.Value = strconv.Itoa(int(val))
k := int(logid)
p.log[k] = entry
return val, err
}
func (p *CalculatorHandler) GetStruct(ctx context.Context, key int32) (*shared.SharedStruct, error) {
fmt.Print("getStruct(", key, ")\n")
v, _ := p.log[int(key)]
return v, nil
}
func (p *CalculatorHandler) Zip(ctx context.Context) (err error) {
fmt.Print("zip()\n")
return nil
}
func FuzzParseBinary(data []byte) int {
// Skip if input is too small
if len(data) < 1 {
return 0
}
// Create transport and protocol
transport := thrift.NewTMemoryBufferLen(len(data))
defer func() {
transport.Close()
// Reset the buffer to release memory
transport.Buffer.Reset()
}()
transport.Write(data)
config := &thrift.TConfiguration{
MaxMessageSize: FUZZ_MAX_MESSAGE_SIZE,
}
protocol := thrift.NewTBinaryProtocolFactoryConf(config).GetProtocol(transport)
// Try to read the FuzzTest structure
fuzzTest := fuzztest.NewFuzzTest()
err := fuzzTest.Read(context.Background(), protocol)
if err != nil {
// Invalid input, but not a crash
return 0
}
// Successfully parsed
return 1
}
func FuzzParseCompact(data []byte) int {
// Skip if input is too small
if len(data) < 1 {
return 0
}
// Create transport and protocol
transport := thrift.NewTMemoryBufferLen(len(data))
defer func() {
transport.Close()
// Reset the buffer to release memory
transport.Buffer.Reset()
}()
transport.Write(data)
config := &thrift.TConfiguration{
MaxMessageSize: FUZZ_MAX_MESSAGE_SIZE,
}
protocol := thrift.NewTCompactProtocolFactoryConf(config).GetProtocol(transport)
// Try to read the FuzzTest structure
fuzzTest := fuzztest.NewFuzzTest()
err := fuzzTest.Read(context.Background(), protocol)
if err != nil {
// Invalid input, but not a crash
return 0
}
// Successfully parsed
return 1
}
func FuzzParseJson(data []byte) int {
// Skip if input is too small
if len(data) < 1 {
return 0
}
// Create transport and protocol
transport := thrift.NewTMemoryBufferLen(len(data))
defer func() {
transport.Close()
// Reset the buffer to release memory
transport.Buffer.Reset()
}()
transport.Write(data)
protocol := thrift.NewTJSONProtocolFactory().GetProtocol(transport)
// Try to read the FuzzTest structure
fuzzTest := fuzztest.NewFuzzTest()
err := fuzzTest.Read(context.Background(), protocol)
if err != nil {
// Invalid input, but not a crash
return 0
}
// Successfully parsed
return 1
}
func FuzzRoundtripBinary(data []byte) int {
// Skip if input is too small
if len(data) < 1 {
return 0
}
config := &thrift.TConfiguration{
MaxMessageSize: FUZZ_MAX_MESSAGE_SIZE,
}
// First parse
transport := thrift.NewTMemoryBufferLen(len(data))
transport.Write(data)
protocol := thrift.NewTBinaryProtocolFactoryConf(config).GetProtocol(transport)
// Try to read the FuzzTest structure
test1 := fuzztest.NewFuzzTest()
err := test1.Read(context.Background(), protocol)
if err != nil {
// Invalid input, but not a crash
return 0
}
// Serialize back
outTransport := thrift.NewTMemoryBuffer()
outProtocol := thrift.NewTBinaryProtocolFactoryConf(config).GetProtocol(outTransport)
err = test1.Write(context.Background(), outProtocol)
if err != nil {
return 0
}
// Get serialized data and deserialize again
serialized := outTransport.Bytes()
reTransport := thrift.NewTMemoryBufferLen(len(serialized))
reTransport.Write(serialized)
reProtocol := thrift.NewTBinaryProtocolFactoryConf(config).GetProtocol(reTransport)
test2 := fuzztest.NewFuzzTest()
err = test2.Read(context.Background(), reProtocol)
if err != nil {
return 0
}
// Verify equality
if !test1.Equals(test2) {
panic("Roundtrip failed: objects not equal after deserialization")
}
return 1
}
func FuzzRoundtripCompact(data []byte) int {
// Skip if input is too small
if len(data) < 1 {
return 0
}
config := &thrift.TConfiguration{
MaxMessageSize: FUZZ_MAX_MESSAGE_SIZE,
}
// First parse
transport := thrift.NewTMemoryBufferLen(len(data))
transport.Write(data)
protocol := thrift.NewTCompactProtocolFactoryConf(config).GetProtocol(transport)
// Try to read the FuzzTest structure
test1 := fuzztest.NewFuzzTest()
err := test1.Read(context.Background(), protocol)
if err != nil {
// Invalid input, but not a crash
return 0
}
// Serialize back
outTransport := thrift.NewTMemoryBuffer()
outProtocol := thrift.NewTCompactProtocolFactoryConf(config).GetProtocol(outTransport)
err = test1.Write(context.Background(), outProtocol)
if err != nil {
return 0
}
// Get serialized data and deserialize again
serialized := outTransport.Bytes()
reTransport := thrift.NewTMemoryBufferLen(len(serialized))
reTransport.Write(serialized)
reProtocol := thrift.NewTCompactProtocolFactoryConf(config).GetProtocol(reTransport)
test2 := fuzztest.NewFuzzTest()
err = test2.Read(context.Background(), reProtocol)
if err != nil {
return 0
}
// Verify equality
if !test1.Equals(test2) {
panic("Roundtrip failed: objects not equal after deserialization")
}
return 1
}
func FuzzRoundtripJson(data []byte) int {
// Skip if input is too small
if len(data) < 1 {
return 0
}
// First parse
transport := thrift.NewTMemoryBufferLen(len(data))
transport.Write(data)
protocol := thrift.NewTJSONProtocolFactory().GetProtocol(transport)
// Try to read the FuzzTest structure
test1 := fuzztest.NewFuzzTest()
err := test1.Read(context.Background(), protocol)
if err != nil {
// Invalid input, but not a crash
return 0
}
// Serialize back
outTransport := thrift.NewTMemoryBuffer()
outProtocol := thrift.NewTJSONProtocolFactory().GetProtocol(outTransport)
err = test1.Write(context.Background(), outProtocol)
if err != nil {
return 0
}
// Get serialized data and deserialize again
serialized := outTransport.Bytes()
reTransport := thrift.NewTMemoryBufferLen(len(serialized))
reTransport.Write(serialized)
reProtocol := thrift.NewTJSONProtocolFactory().GetProtocol(reTransport)
test2 := fuzztest.NewFuzzTest()
err = test2.Read(context.Background(), reProtocol)
if err != nil {
return 0
}
// Verify equality
if !test1.Equals(test2) {
panic("Roundtrip failed: objects not equal after deserialization")
}
return 1
}
// Code generated by Thrift Compiler (0.23.0). DO NOT EDIT.
package fuzztest
import (
"bytes"
"context"
"errors"
"fmt"
"iter"
"log/slog"
"time"
thrift "github.com/apache/thrift/lib/go/thrift"
"strings"
"regexp"
)
// (needed to ensure safety because of naive import list construction.)
var _ = bytes.Equal
var _ = context.Background
var _ = errors.New
var _ = fmt.Printf
var _ = iter.Pull[int]
var _ = slog.Log
var _ = time.Now
var _ = thrift.ZERO
// (needed by validator.)
var _ = strings.Contains
var _ = regexp.MatchString
func init() {
}
// Code generated by Thrift Compiler (0.23.0). DO NOT EDIT.
package fuzztest
import (
"bytes"
"context"
"database/sql/driver"
"errors"
"fmt"
"iter"
"log/slog"
"time"
thrift "github.com/apache/thrift/lib/go/thrift"
"strings"
"regexp"
)
// (needed to ensure safety because of naive import list construction.)
var _ = bytes.Equal
var _ = context.Background
var _ = errors.New
var _ = fmt.Printf
var _ = iter.Pull[int]
var _ = slog.Log
var _ = time.Now
var _ = thrift.ZERO
// (needed by validator.)
var _ = strings.Contains
var _ = regexp.MatchString
type TestEnum int64
const (
TestEnum_ZERO TestEnum = 0
TestEnum_ONE TestEnum = 1
TestEnum_TWO TestEnum = 2
TestEnum_NEGATIVE TestEnum = -1
TestEnum_LARGE TestEnum = 32767
TestEnum_HEX_VALUE TestEnum = 255
)
var knownTestEnumValues = []TestEnum{
TestEnum_ZERO,
TestEnum_ONE,
TestEnum_TWO,
TestEnum_NEGATIVE,
TestEnum_LARGE,
TestEnum_HEX_VALUE,
}
func TestEnumValues() iter.Seq[TestEnum] {
return func(yield func(TestEnum) bool) {
for _, v := range knownTestEnumValues {
if !yield(v) {
return
}
}
}
}
func (p TestEnum) String() string {
switch p {
case TestEnum_ZERO: return "ZERO"
case TestEnum_ONE: return "ONE"
case TestEnum_TWO: return "TWO"
case TestEnum_NEGATIVE: return "NEGATIVE"
case TestEnum_LARGE: return "LARGE"
case TestEnum_HEX_VALUE: return "HEX_VALUE"
}
return "<UNSET>"
}
func TestEnumFromString(s string) (TestEnum, error) {
switch s {
case "ZERO": return TestEnum_ZERO, nil
case "ONE": return TestEnum_ONE, nil
case "TWO": return TestEnum_TWO, nil
case "NEGATIVE": return TestEnum_NEGATIVE, nil
case "LARGE": return TestEnum_LARGE, nil
case "HEX_VALUE": return TestEnum_HEX_VALUE, nil
}
return TestEnum(0), fmt.Errorf("not a valid TestEnum string")
}
func TestEnumPtr(v TestEnum) *TestEnum { return &v }
func (p TestEnum) MarshalText() ([]byte, error) {
return []byte(p.String()), nil
}
func (p *TestEnum) UnmarshalText(text []byte) error {
q, err := TestEnumFromString(string(text))
if err != nil {
return err
}
*p = q
return nil
}
func (p *TestEnum) Scan(value interface{}) error {
v, ok := value.(int64)
if !ok {
return errors.New("Scan value is not int64")
}
*p = TestEnum(v)
return nil
}
func (p *TestEnum) Value() (driver.Value, error) {
if p == nil {
return nil, nil
}
return int64(*p), nil
}
type UserId int64
func UserIdPtr(v UserId) *UserId { return &v }
type BinaryData []byte
func BinaryDataPtr(v BinaryData) *BinaryData { return &v }
// Attributes:
// - BoolField
// - ByteField
// - I16Field
// - I32Field
// - I64Field
// - DoubleField
// - StringField
// - BinaryField
// - UUIDField
//
type BasicTypes struct {
BoolField bool `thrift:"bool_field,1" db:"bool_field" json:"bool_field"`
ByteField int8 `thrift:"byte_field,2" db:"byte_field" json:"byte_field"`
I16Field int16 `thrift:"i16_field,3" db:"i16_field" json:"i16_field"`
I32Field int32 `thrift:"i32_field,4" db:"i32_field" json:"i32_field"`
I64Field int64 `thrift:"i64_field,5" db:"i64_field" json:"i64_field"`
DoubleField float64 `thrift:"double_field,6" db:"double_field" json:"double_field"`
StringField string `thrift:"string_field,7" db:"string_field" json:"string_field"`
BinaryField []byte `thrift:"binary_field,8" db:"binary_field" json:"binary_field"`
UUIDField thrift.Tuuid `thrift:"uuid_field,9" db:"uuid_field" json:"uuid_field"`
}
func NewBasicTypes() *BasicTypes {
return &BasicTypes{}
}
func (p *BasicTypes) GetBoolField() bool {
return p.BoolField
}
func (p *BasicTypes) GetByteField() int8 {
return p.ByteField
}
func (p *BasicTypes) GetI16Field() int16 {
return p.I16Field
}
func (p *BasicTypes) GetI32Field() int32 {
return p.I32Field
}
func (p *BasicTypes) GetI64Field() int64 {
return p.I64Field
}
func (p *BasicTypes) GetDoubleField() float64 {
return p.DoubleField
}
func (p *BasicTypes) GetStringField() string {
return p.StringField
}
func (p *BasicTypes) GetBinaryField() []byte {
return p.BinaryField
}
func (p *BasicTypes) GetUUIDField() thrift.Tuuid {
return p.UUIDField
}
func (p *BasicTypes) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 1:
if fieldTypeId == thrift.BOOL {
if err := p.ReadField1(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 2:
if fieldTypeId == thrift.BYTE {
if err := p.ReadField2(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 3:
if fieldTypeId == thrift.I16 {
if err := p.ReadField3(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 4:
if fieldTypeId == thrift.I32 {
if err := p.ReadField4(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 5:
if fieldTypeId == thrift.I64 {
if err := p.ReadField5(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 6:
if fieldTypeId == thrift.DOUBLE {
if err := p.ReadField6(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 7:
if fieldTypeId == thrift.STRING {
if err := p.ReadField7(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 8:
if fieldTypeId == thrift.STRING {
if err := p.ReadField8(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 9:
if fieldTypeId == thrift.UUID {
if err := p.ReadField9(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *BasicTypes) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadBool(ctx); err != nil {
return thrift.PrependError("error reading field 1: ", err)
} else {
p.BoolField = v
}
return nil
}
func (p *BasicTypes) ReadField2(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadByte(ctx); err != nil {
return thrift.PrependError("error reading field 2: ", err)
} else {
temp := int8(v)
p.ByteField = temp
}
return nil
}
func (p *BasicTypes) ReadField3(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI16(ctx); err != nil {
return thrift.PrependError("error reading field 3: ", err)
} else {
p.I16Field = v
}
return nil
}
func (p *BasicTypes) ReadField4(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 4: ", err)
} else {
p.I32Field = v
}
return nil
}
func (p *BasicTypes) ReadField5(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI64(ctx); err != nil {
return thrift.PrependError("error reading field 5: ", err)
} else {
p.I64Field = v
}
return nil
}
func (p *BasicTypes) ReadField6(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadDouble(ctx); err != nil {
return thrift.PrependError("error reading field 6: ", err)
} else {
p.DoubleField = v
}
return nil
}
func (p *BasicTypes) ReadField7(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadString(ctx); err != nil {
return thrift.PrependError("error reading field 7: ", err)
} else {
p.StringField = v
}
return nil
}
func (p *BasicTypes) ReadField8(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadBinary(ctx); err != nil {
return thrift.PrependError("error reading field 8: ", err)
} else {
p.BinaryField = v
}
return nil
}
func (p *BasicTypes) ReadField9(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadUUID(ctx); err != nil {
return thrift.PrependError("error reading field 9: ", err)
} else {
p.UUIDField = v
}
return nil
}
func (p *BasicTypes) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "BasicTypes"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField1(ctx, oprot); err != nil { return err }
if err := p.writeField2(ctx, oprot); err != nil { return err }
if err := p.writeField3(ctx, oprot); err != nil { return err }
if err := p.writeField4(ctx, oprot); err != nil { return err }
if err := p.writeField5(ctx, oprot); err != nil { return err }
if err := p.writeField6(ctx, oprot); err != nil { return err }
if err := p.writeField7(ctx, oprot); err != nil { return err }
if err := p.writeField8(ctx, oprot); err != nil { return err }
if err := p.writeField9(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *BasicTypes) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "bool_field", thrift.BOOL, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:bool_field: ", p), err)
}
if err := oprot.WriteBool(ctx, bool(p.BoolField)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.bool_field (1) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:bool_field: ", p), err)
}
return err
}
func (p *BasicTypes) writeField2(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "byte_field", thrift.BYTE, 2); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:byte_field: ", p), err)
}
if err := oprot.WriteByte(ctx, int8(p.ByteField)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.byte_field (2) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 2:byte_field: ", p), err)
}
return err
}
func (p *BasicTypes) writeField3(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "i16_field", thrift.I16, 3); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:i16_field: ", p), err)
}
if err := oprot.WriteI16(ctx, int16(p.I16Field)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.i16_field (3) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 3:i16_field: ", p), err)
}
return err
}
func (p *BasicTypes) writeField4(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "i32_field", thrift.I32, 4); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:i32_field: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.I32Field)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.i32_field (4) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 4:i32_field: ", p), err)
}
return err
}
func (p *BasicTypes) writeField5(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "i64_field", thrift.I64, 5); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 5:i64_field: ", p), err)
}
if err := oprot.WriteI64(ctx, int64(p.I64Field)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.i64_field (5) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 5:i64_field: ", p), err)
}
return err
}
func (p *BasicTypes) writeField6(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "double_field", thrift.DOUBLE, 6); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 6:double_field: ", p), err)
}
if err := oprot.WriteDouble(ctx, float64(p.DoubleField)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.double_field (6) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 6:double_field: ", p), err)
}
return err
}
func (p *BasicTypes) writeField7(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "string_field", thrift.STRING, 7); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 7:string_field: ", p), err)
}
if err := oprot.WriteString(ctx, string(p.StringField)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.string_field (7) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 7:string_field: ", p), err)
}
return err
}
func (p *BasicTypes) writeField8(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "binary_field", thrift.STRING, 8); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 8:binary_field: ", p), err)
}
if err := oprot.WriteBinary(ctx, p.BinaryField); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.binary_field (8) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 8:binary_field: ", p), err)
}
return err
}
func (p *BasicTypes) writeField9(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "uuid_field", thrift.UUID, 9); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 9:uuid_field: ", p), err)
}
if err := oprot.WriteUUID(ctx, thrift.Tuuid(p.UUIDField)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.uuid_field (9) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 9:uuid_field: ", p), err)
}
return err
}
func (p *BasicTypes) Equals(other *BasicTypes) bool {
if p == other {
return true
} else if p == nil || other == nil {
return false
}
if p.BoolField != other.BoolField { return false }
if p.ByteField != other.ByteField { return false }
if p.I16Field != other.I16Field { return false }
if p.I32Field != other.I32Field { return false }
if p.I64Field != other.I64Field { return false }
if p.DoubleField != other.DoubleField { return false }
if p.StringField != other.StringField { return false }
if bytes.Compare(p.BinaryField, other.BinaryField) != 0 { return false }
if p.UUIDField != other.UUIDField { return false }
return true
}
func (p *BasicTypes) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("BasicTypes(%+v)", *p)
}
func (p *BasicTypes) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*fuzztest.BasicTypes",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*BasicTypes)(nil)
func (p *BasicTypes) Validate() error {
return nil
}
// Attributes:
// - ReqField
// - OptField
// - DefaultField
// - OptWithDefault
// - ReqWithDefault
//
type Requiredness struct {
ReqField int32 `thrift:"req_field,1,required" db:"req_field" json:"req_field"`
OptField *int32 `thrift:"opt_field,2" db:"opt_field" json:"opt_field,omitempty"`
DefaultField int32 `thrift:"default_field,3" db:"default_field" json:"default_field"`
OptWithDefault string `thrift:"opt_with_default,4" db:"opt_with_default" json:"opt_with_default"`
ReqWithDefault bool `thrift:"req_with_default,5,required" db:"req_with_default" json:"req_with_default"`
}
func NewRequiredness() *Requiredness {
return &Requiredness{
OptWithDefault: "test",
ReqWithDefault: true,
}
}
func (p *Requiredness) GetReqField() int32 {
return p.ReqField
}
var Requiredness_OptField_DEFAULT int32
func (p *Requiredness) GetOptField() int32 {
if !p.IsSetOptField() {
return Requiredness_OptField_DEFAULT
}
return *p.OptField
}
func (p *Requiredness) GetDefaultField() int32 {
return p.DefaultField
}
var Requiredness_OptWithDefault_DEFAULT string = "test"
func (p *Requiredness) GetOptWithDefault() string {
return p.OptWithDefault
}
func (p *Requiredness) GetReqWithDefault() bool {
return p.ReqWithDefault
}
func (p *Requiredness) IsSetOptField() bool {
return p.OptField != nil
}
func (p *Requiredness) IsSetOptWithDefault() bool {
return p.OptWithDefault != Requiredness_OptWithDefault_DEFAULT
}
func (p *Requiredness) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
var issetReqField bool = false;
var issetReqWithDefault bool = false;
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 1:
if fieldTypeId == thrift.I32 {
if err := p.ReadField1(ctx, iprot); err != nil {
return err
}
issetReqField = true
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 2:
if fieldTypeId == thrift.I32 {
if err := p.ReadField2(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 3:
if fieldTypeId == thrift.I32 {
if err := p.ReadField3(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 4:
if fieldTypeId == thrift.STRING {
if err := p.ReadField4(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 5:
if fieldTypeId == thrift.BOOL {
if err := p.ReadField5(ctx, iprot); err != nil {
return err
}
issetReqWithDefault = true
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
if !issetReqField{
return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field ReqField is not set"))
}
if !issetReqWithDefault{
return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field ReqWithDefault is not set"))
}
return nil
}
func (p *Requiredness) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 1: ", err)
} else {
p.ReqField = v
}
return nil
}
func (p *Requiredness) ReadField2(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 2: ", err)
} else {
p.OptField = &v
}
return nil
}
func (p *Requiredness) ReadField3(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 3: ", err)
} else {
p.DefaultField = v
}
return nil
}
func (p *Requiredness) ReadField4(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadString(ctx); err != nil {
return thrift.PrependError("error reading field 4: ", err)
} else {
p.OptWithDefault = v
}
return nil
}
func (p *Requiredness) ReadField5(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadBool(ctx); err != nil {
return thrift.PrependError("error reading field 5: ", err)
} else {
p.ReqWithDefault = v
}
return nil
}
func (p *Requiredness) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "Requiredness"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField1(ctx, oprot); err != nil { return err }
if err := p.writeField2(ctx, oprot); err != nil { return err }
if err := p.writeField3(ctx, oprot); err != nil { return err }
if err := p.writeField4(ctx, oprot); err != nil { return err }
if err := p.writeField5(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *Requiredness) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "req_field", thrift.I32, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:req_field: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.ReqField)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.req_field (1) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:req_field: ", p), err)
}
return err
}
func (p *Requiredness) writeField2(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetOptField() {
if err := oprot.WriteFieldBegin(ctx, "opt_field", thrift.I32, 2); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:opt_field: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(*p.OptField)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.opt_field (2) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 2:opt_field: ", p), err)
}
}
return err
}
func (p *Requiredness) writeField3(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "default_field", thrift.I32, 3); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:default_field: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.DefaultField)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.default_field (3) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 3:default_field: ", p), err)
}
return err
}
func (p *Requiredness) writeField4(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetOptWithDefault() {
if err := oprot.WriteFieldBegin(ctx, "opt_with_default", thrift.STRING, 4); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:opt_with_default: ", p), err)
}
if err := oprot.WriteString(ctx, string(p.OptWithDefault)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.opt_with_default (4) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 4:opt_with_default: ", p), err)
}
}
return err
}
func (p *Requiredness) writeField5(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "req_with_default", thrift.BOOL, 5); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 5:req_with_default: ", p), err)
}
if err := oprot.WriteBool(ctx, bool(p.ReqWithDefault)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.req_with_default (5) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 5:req_with_default: ", p), err)
}
return err
}
func (p *Requiredness) Equals(other *Requiredness) bool {
if p == other {
return true
} else if p == nil || other == nil {
return false
}
if p.ReqField != other.ReqField { return false }
if p.OptField != other.OptField {
if p.OptField == nil || other.OptField == nil {
return false
}
if (*p.OptField) != (*other.OptField) { return false }
}
if p.DefaultField != other.DefaultField { return false }
if p.OptWithDefault != other.OptWithDefault { return false }
if p.ReqWithDefault != other.ReqWithDefault { return false }
return true
}
func (p *Requiredness) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("Requiredness(%+v)", *p)
}
func (p *Requiredness) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*fuzztest.Requiredness",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*Requiredness)(nil)
func (p *Requiredness) Validate() error {
return nil
}
// Attributes:
// - First
// - Gap
// - MediumID
// - LargeID
//
type FieldIDTest struct {
First int32 `thrift:"first,1" db:"first" json:"first"`
// unused fields # 2 to 99
Gap int32 `thrift:"gap,100" db:"gap" json:"gap"`
// unused fields # 101 to 254
MediumID int32 `thrift:"medium_id,255" db:"medium_id" json:"medium_id"`
// unused fields # 256 to 32766
LargeID int32 `thrift:"large_id,32767" db:"large_id" json:"large_id"`
}
func NewFieldIDTest() *FieldIDTest {
return &FieldIDTest{}
}
func (p *FieldIDTest) GetFirst() int32 {
return p.First
}
func (p *FieldIDTest) GetGap() int32 {
return p.Gap
}
func (p *FieldIDTest) GetMediumID() int32 {
return p.MediumID
}
func (p *FieldIDTest) GetLargeID() int32 {
return p.LargeID
}
func (p *FieldIDTest) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 1:
if fieldTypeId == thrift.I32 {
if err := p.ReadField1(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 100:
if fieldTypeId == thrift.I32 {
if err := p.ReadField100(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 255:
if fieldTypeId == thrift.I32 {
if err := p.ReadField255(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 32767:
if fieldTypeId == thrift.I32 {
if err := p.ReadField32767(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *FieldIDTest) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 1: ", err)
} else {
p.First = v
}
return nil
}
func (p *FieldIDTest) ReadField100(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 100: ", err)
} else {
p.Gap = v
}
return nil
}
func (p *FieldIDTest) ReadField255(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 255: ", err)
} else {
p.MediumID = v
}
return nil
}
func (p *FieldIDTest) ReadField32767(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 32767: ", err)
} else {
p.LargeID = v
}
return nil
}
func (p *FieldIDTest) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "FieldIDTest"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField1(ctx, oprot); err != nil { return err }
if err := p.writeField100(ctx, oprot); err != nil { return err }
if err := p.writeField255(ctx, oprot); err != nil { return err }
if err := p.writeField32767(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *FieldIDTest) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "first", thrift.I32, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:first: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.First)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.first (1) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:first: ", p), err)
}
return err
}
func (p *FieldIDTest) writeField100(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "gap", thrift.I32, 100); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 100:gap: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.Gap)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.gap (100) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 100:gap: ", p), err)
}
return err
}
func (p *FieldIDTest) writeField255(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "medium_id", thrift.I32, 255); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 255:medium_id: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.MediumID)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.medium_id (255) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 255:medium_id: ", p), err)
}
return err
}
func (p *FieldIDTest) writeField32767(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "large_id", thrift.I32, 32767); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 32767:large_id: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.LargeID)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.large_id (32767) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 32767:large_id: ", p), err)
}
return err
}
func (p *FieldIDTest) Equals(other *FieldIDTest) bool {
if p == other {
return true
} else if p == nil || other == nil {
return false
}
if p.First != other.First { return false }
if p.Gap != other.Gap { return false }
if p.MediumID != other.MediumID { return false }
if p.LargeID != other.LargeID { return false }
return true
}
func (p *FieldIDTest) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("FieldIDTest(%+v)", *p)
}
func (p *FieldIDTest) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*fuzztest.FieldIDTest",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*FieldIDTest)(nil)
func (p *FieldIDTest) Validate() error {
return nil
}
type EmptyStruct struct {
}
func NewEmptyStruct() *EmptyStruct {
return &EmptyStruct{}
}
func (p *EmptyStruct) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *EmptyStruct) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "EmptyStruct"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *EmptyStruct) Equals(other *EmptyStruct) bool {
if p == other {
return true
} else if p == nil || other == nil {
return false
}
return true
}
func (p *EmptyStruct) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("EmptyStruct(%+v)", *p)
}
func (p *EmptyStruct) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*fuzztest.EmptyStruct",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*EmptyStruct)(nil)
func (p *EmptyStruct) Validate() error {
return nil
}
// Attributes:
// - IntField
// - StringField
// - StructField
// - BinaryField
//
type TestUnion struct {
IntField *int32 `thrift:"int_field,1" db:"int_field" json:"int_field,omitempty"`
StringField *string `thrift:"string_field,2" db:"string_field" json:"string_field,omitempty"`
StructField *BasicTypes `thrift:"struct_field,3" db:"struct_field" json:"struct_field,omitempty"`
BinaryField []byte `thrift:"binary_field,4" db:"binary_field" json:"binary_field,omitempty"`
}
func NewTestUnion() *TestUnion {
return &TestUnion{}
}
var TestUnion_IntField_DEFAULT int32
func (p *TestUnion) GetIntField() int32 {
if !p.IsSetIntField() {
return TestUnion_IntField_DEFAULT
}
return *p.IntField
}
var TestUnion_StringField_DEFAULT string
func (p *TestUnion) GetStringField() string {
if !p.IsSetStringField() {
return TestUnion_StringField_DEFAULT
}
return *p.StringField
}
var TestUnion_StructField_DEFAULT *BasicTypes
func (p *TestUnion) GetStructField() *BasicTypes {
if !p.IsSetStructField() {
return TestUnion_StructField_DEFAULT
}
return p.StructField
}
var TestUnion_BinaryField_DEFAULT []byte
func (p *TestUnion) GetBinaryField() []byte {
return p.BinaryField
}
func (p *TestUnion) CountSetFieldsTestUnion() int {
count := 0
if (p.IsSetIntField()) {
count++
}
if (p.IsSetStringField()) {
count++
}
if (p.IsSetStructField()) {
count++
}
if (p.IsSetBinaryField()) {
count++
}
return count
}
func (p *TestUnion) IsSetIntField() bool {
return p.IntField != nil
}
func (p *TestUnion) IsSetStringField() bool {
return p.StringField != nil
}
func (p *TestUnion) IsSetStructField() bool {
return p.StructField != nil
}
func (p *TestUnion) IsSetBinaryField() bool {
return p.BinaryField != nil
}
func (p *TestUnion) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 1:
if fieldTypeId == thrift.I32 {
if err := p.ReadField1(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 2:
if fieldTypeId == thrift.STRING {
if err := p.ReadField2(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 3:
if fieldTypeId == thrift.STRUCT {
if err := p.ReadField3(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 4:
if fieldTypeId == thrift.STRING {
if err := p.ReadField4(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *TestUnion) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 1: ", err)
} else {
p.IntField = &v
}
return nil
}
func (p *TestUnion) ReadField2(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadString(ctx); err != nil {
return thrift.PrependError("error reading field 2: ", err)
} else {
p.StringField = &v
}
return nil
}
func (p *TestUnion) ReadField3(ctx context.Context, iprot thrift.TProtocol) error {
p.StructField = &BasicTypes{}
if err := p.StructField.Read(ctx, iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.StructField), err)
}
return nil
}
func (p *TestUnion) ReadField4(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadBinary(ctx); err != nil {
return thrift.PrependError("error reading field 4: ", err)
} else {
p.BinaryField = v
}
return nil
}
func (p *TestUnion) Write(ctx context.Context, oprot thrift.TProtocol) error {
if c := p.CountSetFieldsTestUnion(); c != 1 {
return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("%T write union: exactly one field must be set (%d set)", p, c))
}
if err := oprot.WriteStructBegin(ctx, "TestUnion"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField1(ctx, oprot); err != nil { return err }
if err := p.writeField2(ctx, oprot); err != nil { return err }
if err := p.writeField3(ctx, oprot); err != nil { return err }
if err := p.writeField4(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *TestUnion) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetIntField() {
if err := oprot.WriteFieldBegin(ctx, "int_field", thrift.I32, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:int_field: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(*p.IntField)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.int_field (1) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:int_field: ", p), err)
}
}
return err
}
func (p *TestUnion) writeField2(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetStringField() {
if err := oprot.WriteFieldBegin(ctx, "string_field", thrift.STRING, 2); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:string_field: ", p), err)
}
if err := oprot.WriteString(ctx, string(*p.StringField)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.string_field (2) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 2:string_field: ", p), err)
}
}
return err
}
func (p *TestUnion) writeField3(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetStructField() {
if err := oprot.WriteFieldBegin(ctx, "struct_field", thrift.STRUCT, 3); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:struct_field: ", p), err)
}
if err := p.StructField.Write(ctx, oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.StructField), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 3:struct_field: ", p), err)
}
}
return err
}
func (p *TestUnion) writeField4(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetBinaryField() {
if err := oprot.WriteFieldBegin(ctx, "binary_field", thrift.STRING, 4); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:binary_field: ", p), err)
}
if err := oprot.WriteBinary(ctx, p.BinaryField); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.binary_field (4) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 4:binary_field: ", p), err)
}
}
return err
}
func (p *TestUnion) Equals(other *TestUnion) bool {
if p == other {
return true
} else if p == nil || other == nil {
return false
}
if p.IntField != other.IntField {
if p.IntField == nil || other.IntField == nil {
return false
}
if (*p.IntField) != (*other.IntField) { return false }
}
if p.StringField != other.StringField {
if p.StringField == nil || other.StringField == nil {
return false
}
if (*p.StringField) != (*other.StringField) { return false }
}
if !p.StructField.Equals(other.StructField) { return false }
if bytes.Compare(p.BinaryField, other.BinaryField) != 0 { return false }
return true
}
func (p *TestUnion) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("TestUnion(%+v)", *p)
}
func (p *TestUnion) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*fuzztest.TestUnion",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*TestUnion)(nil)
func (p *TestUnion) Validate() error {
return nil
}
// Attributes:
// - IntList
// - StringSet
// - IntStringMap
// - StructList
// - NestedMap
// - TypedefSet
//
type Containers struct {
IntList []int32 `thrift:"int_list,1" db:"int_list" json:"int_list"`
StringSet []string `thrift:"string_set,2" db:"string_set" json:"string_set"`
IntStringMap map[int32]string `thrift:"int_string_map,3" db:"int_string_map" json:"int_string_map"`
StructList []*BasicTypes `thrift:"struct_list,4" db:"struct_list" json:"struct_list"`
NestedMap map[string][]int32 `thrift:"nested_map,5" db:"nested_map" json:"nested_map"`
TypedefSet []UserId `thrift:"typedef_set,6" db:"typedef_set" json:"typedef_set"`
}
func NewContainers() *Containers {
return &Containers{}
}
func (p *Containers) GetIntList() []int32 {
return p.IntList
}
func (p *Containers) GetStringSet() []string {
return p.StringSet
}
func (p *Containers) GetIntStringMap() map[int32]string {
return p.IntStringMap
}
func (p *Containers) GetStructList() []*BasicTypes {
return p.StructList
}
func (p *Containers) GetNestedMap() map[string][]int32 {
return p.NestedMap
}
func (p *Containers) GetTypedefSet() []UserId {
return p.TypedefSet
}
func (p *Containers) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 1:
if fieldTypeId == thrift.LIST {
if err := p.ReadField1(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 2:
if fieldTypeId == thrift.SET {
if err := p.ReadField2(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 3:
if fieldTypeId == thrift.MAP {
if err := p.ReadField3(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 4:
if fieldTypeId == thrift.LIST {
if err := p.ReadField4(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 5:
if fieldTypeId == thrift.MAP {
if err := p.ReadField5(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 6:
if fieldTypeId == thrift.SET {
if err := p.ReadField6(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *Containers) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
_, size, err := iprot.ReadListBegin(ctx)
if err != nil {
return thrift.PrependError("error reading list begin: ", err)
}
tSlice := make([]int32, 0, size)
p.IntList = tSlice
for i := 0; i < size; i++ {
var _elem0 int32
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 0: ", err)
} else {
_elem0 = v
}
p.IntList = append(p.IntList, _elem0)
}
if err := iprot.ReadListEnd(ctx); err != nil {
return thrift.PrependError("error reading list end: ", err)
}
return nil
}
func (p *Containers) ReadField2(ctx context.Context, iprot thrift.TProtocol) error {
_, size, err := iprot.ReadSetBegin(ctx)
if err != nil {
return thrift.PrependError("error reading set begin: ", err)
}
tSet := make([]string, 0, size)
p.StringSet = tSet
for i := 0; i < size; i++ {
var _elem1 string
if v, err := iprot.ReadString(ctx); err != nil {
return thrift.PrependError("error reading field 0: ", err)
} else {
_elem1 = v
}
p.StringSet = append(p.StringSet, _elem1)
}
if err := iprot.ReadSetEnd(ctx); err != nil {
return thrift.PrependError("error reading set end: ", err)
}
return nil
}
func (p *Containers) ReadField3(ctx context.Context, iprot thrift.TProtocol) error {
_, _, size, err := iprot.ReadMapBegin(ctx)
if err != nil {
return thrift.PrependError("error reading map begin: ", err)
}
tMap := make(map[int32]string, size)
p.IntStringMap = tMap
for i := 0; i < size; i++ {
var _key2 int32
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 0: ", err)
} else {
_key2 = v
}
var _val3 string
if v, err := iprot.ReadString(ctx); err != nil {
return thrift.PrependError("error reading field 0: ", err)
} else {
_val3 = v
}
p.IntStringMap[_key2] = _val3
}
if err := iprot.ReadMapEnd(ctx); err != nil {
return thrift.PrependError("error reading map end: ", err)
}
return nil
}
func (p *Containers) ReadField4(ctx context.Context, iprot thrift.TProtocol) error {
_, size, err := iprot.ReadListBegin(ctx)
if err != nil {
return thrift.PrependError("error reading list begin: ", err)
}
tSlice := make([]*BasicTypes, 0, size)
p.StructList = tSlice
for i := 0; i < size; i++ {
_elem4 := &BasicTypes{}
if err := _elem4.Read(ctx, iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem4), err)
}
p.StructList = append(p.StructList, _elem4)
}
if err := iprot.ReadListEnd(ctx); err != nil {
return thrift.PrependError("error reading list end: ", err)
}
return nil
}
func (p *Containers) ReadField5(ctx context.Context, iprot thrift.TProtocol) error {
_, _, size, err := iprot.ReadMapBegin(ctx)
if err != nil {
return thrift.PrependError("error reading map begin: ", err)
}
tMap := make(map[string][]int32, size)
p.NestedMap = tMap
for i := 0; i < size; i++ {
var _key5 string
if v, err := iprot.ReadString(ctx); err != nil {
return thrift.PrependError("error reading field 0: ", err)
} else {
_key5 = v
}
_, size, err := iprot.ReadListBegin(ctx)
if err != nil {
return thrift.PrependError("error reading list begin: ", err)
}
tSlice := make([]int32, 0, size)
_val6 := tSlice
for i := 0; i < size; i++ {
var _elem7 int32
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 0: ", err)
} else {
_elem7 = v
}
_val6 = append(_val6, _elem7)
}
if err := iprot.ReadListEnd(ctx); err != nil {
return thrift.PrependError("error reading list end: ", err)
}
p.NestedMap[_key5] = _val6
}
if err := iprot.ReadMapEnd(ctx); err != nil {
return thrift.PrependError("error reading map end: ", err)
}
return nil
}
func (p *Containers) ReadField6(ctx context.Context, iprot thrift.TProtocol) error {
_, size, err := iprot.ReadSetBegin(ctx)
if err != nil {
return thrift.PrependError("error reading set begin: ", err)
}
tSet := make([]UserId, 0, size)
p.TypedefSet = tSet
for i := 0; i < size; i++ {
var _elem8 UserId
if v, err := iprot.ReadI64(ctx); err != nil {
return thrift.PrependError("error reading field 0: ", err)
} else {
temp := UserId(v)
_elem8 = temp
}
p.TypedefSet = append(p.TypedefSet, _elem8)
}
if err := iprot.ReadSetEnd(ctx); err != nil {
return thrift.PrependError("error reading set end: ", err)
}
return nil
}
func (p *Containers) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "Containers"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField1(ctx, oprot); err != nil { return err }
if err := p.writeField2(ctx, oprot); err != nil { return err }
if err := p.writeField3(ctx, oprot); err != nil { return err }
if err := p.writeField4(ctx, oprot); err != nil { return err }
if err := p.writeField5(ctx, oprot); err != nil { return err }
if err := p.writeField6(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *Containers) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "int_list", thrift.LIST, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:int_list: ", p), err)
}
if err := oprot.WriteListBegin(ctx, thrift.I32, len(p.IntList)); err != nil {
return thrift.PrependError("error writing list begin: ", err)
}
for _, v := range p.IntList {
if err := oprot.WriteI32(ctx, int32(v)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
}
}
if err := oprot.WriteListEnd(ctx); err != nil {
return thrift.PrependError("error writing list end: ", err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:int_list: ", p), err)
}
return err
}
func (p *Containers) writeField2(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "string_set", thrift.SET, 2); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:string_set: ", p), err)
}
if err := oprot.WriteSetBegin(ctx, thrift.STRING, len(p.StringSet)); err != nil {
return thrift.PrependError("error writing set begin: ", err)
}
for i := 0; i<len(p.StringSet); i++ {
for j := i+1; j<len(p.StringSet); j++ {
if func(tgt, src string) bool {
if tgt != src { return false }
return true
}(p.StringSet[i], p.StringSet[j]) {
return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("%T error writing set field %q: slice is not unique", p.StringSet, "p.StringSet"))
}
}
}
for _, v := range p.StringSet {
if err := oprot.WriteString(ctx, string(v)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
}
}
if err := oprot.WriteSetEnd(ctx); err != nil {
return thrift.PrependError("error writing set end: ", err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 2:string_set: ", p), err)
}
return err
}
func (p *Containers) writeField3(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "int_string_map", thrift.MAP, 3); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:int_string_map: ", p), err)
}
if err := oprot.WriteMapBegin(ctx, thrift.I32, thrift.STRING, len(p.IntStringMap)); err != nil {
return thrift.PrependError("error writing map begin: ", err)
}
for k, v := range p.IntStringMap {
if err := oprot.WriteI32(ctx, int32(k)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
}
if err := oprot.WriteString(ctx, string(v)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
}
}
if err := oprot.WriteMapEnd(ctx); err != nil {
return thrift.PrependError("error writing map end: ", err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 3:int_string_map: ", p), err)
}
return err
}
func (p *Containers) writeField4(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "struct_list", thrift.LIST, 4); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:struct_list: ", p), err)
}
if err := oprot.WriteListBegin(ctx, thrift.STRUCT, len(p.StructList)); err != nil {
return thrift.PrependError("error writing list begin: ", err)
}
for _, v := range p.StructList {
if err := v.Write(ctx, oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err)
}
}
if err := oprot.WriteListEnd(ctx); err != nil {
return thrift.PrependError("error writing list end: ", err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 4:struct_list: ", p), err)
}
return err
}
func (p *Containers) writeField5(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "nested_map", thrift.MAP, 5); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 5:nested_map: ", p), err)
}
if err := oprot.WriteMapBegin(ctx, thrift.STRING, thrift.LIST, len(p.NestedMap)); err != nil {
return thrift.PrependError("error writing map begin: ", err)
}
for k, v := range p.NestedMap {
if err := oprot.WriteString(ctx, string(k)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
}
if err := oprot.WriteListBegin(ctx, thrift.I32, len(v)); err != nil {
return thrift.PrependError("error writing list begin: ", err)
}
for _, v := range v {
if err := oprot.WriteI32(ctx, int32(v)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
}
}
if err := oprot.WriteListEnd(ctx); err != nil {
return thrift.PrependError("error writing list end: ", err)
}
}
if err := oprot.WriteMapEnd(ctx); err != nil {
return thrift.PrependError("error writing map end: ", err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 5:nested_map: ", p), err)
}
return err
}
func (p *Containers) writeField6(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "typedef_set", thrift.SET, 6); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 6:typedef_set: ", p), err)
}
if err := oprot.WriteSetBegin(ctx, thrift.I64, len(p.TypedefSet)); err != nil {
return thrift.PrependError("error writing set begin: ", err)
}
for i := 0; i<len(p.TypedefSet); i++ {
for j := i+1; j<len(p.TypedefSet); j++ {
if func(tgt, src UserId) bool {
if tgt != src { return false }
return true
}(p.TypedefSet[i], p.TypedefSet[j]) {
return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("%T error writing set field %q: slice is not unique", p.TypedefSet, "p.TypedefSet"))
}
}
}
for _, v := range p.TypedefSet {
if err := oprot.WriteI64(ctx, int64(v)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
}
}
if err := oprot.WriteSetEnd(ctx); err != nil {
return thrift.PrependError("error writing set end: ", err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 6:typedef_set: ", p), err)
}
return err
}
func (p *Containers) Equals(other *Containers) bool {
if p == other {
return true
} else if p == nil || other == nil {
return false
}
if len(p.IntList) != len(other.IntList) { return false }
for i, _tgt := range p.IntList {
_src9 := other.IntList[i]
if _tgt != _src9 { return false }
}
if len(p.StringSet) != len(other.StringSet) { return false }
for i, _tgt := range p.StringSet {
_src10 := other.StringSet[i]
if _tgt != _src10 { return false }
}
if len(p.IntStringMap) != len(other.IntStringMap) { return false }
for k, _tgt := range p.IntStringMap {
_src11 := other.IntStringMap[k]
if _tgt != _src11 { return false }
}
if len(p.StructList) != len(other.StructList) { return false }
for i, _tgt := range p.StructList {
_src12 := other.StructList[i]
if !_tgt.Equals(_src12) { return false }
}
if len(p.NestedMap) != len(other.NestedMap) { return false }
for k, _tgt := range p.NestedMap {
_src13 := other.NestedMap[k]
if len(_tgt) != len(_src13) { return false }
for i, _tgt := range _tgt {
_src14 := _src13[i]
if _tgt != _src14 { return false }
}
}
if len(p.TypedefSet) != len(other.TypedefSet) { return false }
for i, _tgt := range p.TypedefSet {
_src15 := other.TypedefSet[i]
if _tgt != _src15 { return false }
}
return true
}
func (p *Containers) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("Containers(%+v)", *p)
}
func (p *Containers) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*fuzztest.Containers",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*Containers)(nil)
func (p *Containers) Validate() error {
return nil
}
// Attributes:
// - Recurse
// - Data
// - Children
//
type RecursiveStruct struct {
Recurse *RecursiveStruct `thrift:"recurse,1" db:"recurse" json:"recurse,omitempty"`
Data int32 `thrift:"data,2" db:"data" json:"data"`
Children []*RecursiveStruct `thrift:"children,3" db:"children" json:"children,omitempty"`
}
func NewRecursiveStruct() *RecursiveStruct {
return &RecursiveStruct{}
}
var RecursiveStruct_Recurse_DEFAULT *RecursiveStruct
func (p *RecursiveStruct) GetRecurse() *RecursiveStruct {
if !p.IsSetRecurse() {
return RecursiveStruct_Recurse_DEFAULT
}
return p.Recurse
}
func (p *RecursiveStruct) GetData() int32 {
return p.Data
}
var RecursiveStruct_Children_DEFAULT []*RecursiveStruct
func (p *RecursiveStruct) GetChildren() []*RecursiveStruct {
return p.Children
}
func (p *RecursiveStruct) IsSetRecurse() bool {
return p.Recurse != nil
}
func (p *RecursiveStruct) IsSetChildren() bool {
return p.Children != nil
}
func (p *RecursiveStruct) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 1:
if fieldTypeId == thrift.STRUCT {
if err := p.ReadField1(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 2:
if fieldTypeId == thrift.I32 {
if err := p.ReadField2(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 3:
if fieldTypeId == thrift.LIST {
if err := p.ReadField3(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *RecursiveStruct) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
p.Recurse = &RecursiveStruct{}
if err := p.Recurse.Read(ctx, iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Recurse), err)
}
return nil
}
func (p *RecursiveStruct) ReadField2(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 2: ", err)
} else {
p.Data = v
}
return nil
}
func (p *RecursiveStruct) ReadField3(ctx context.Context, iprot thrift.TProtocol) error {
_, size, err := iprot.ReadListBegin(ctx)
if err != nil {
return thrift.PrependError("error reading list begin: ", err)
}
tSlice := make([]*RecursiveStruct, 0, size)
p.Children = tSlice
for i := 0; i < size; i++ {
_elem16 := &RecursiveStruct{}
if err := _elem16.Read(ctx, iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem16), err)
}
p.Children = append(p.Children, _elem16)
}
if err := iprot.ReadListEnd(ctx); err != nil {
return thrift.PrependError("error reading list end: ", err)
}
return nil
}
func (p *RecursiveStruct) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "RecursiveStruct"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField1(ctx, oprot); err != nil { return err }
if err := p.writeField2(ctx, oprot); err != nil { return err }
if err := p.writeField3(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *RecursiveStruct) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetRecurse() {
if err := oprot.WriteFieldBegin(ctx, "recurse", thrift.STRUCT, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:recurse: ", p), err)
}
if err := p.Recurse.Write(ctx, oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Recurse), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:recurse: ", p), err)
}
}
return err
}
func (p *RecursiveStruct) writeField2(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "data", thrift.I32, 2); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:data: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.Data)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.data (2) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 2:data: ", p), err)
}
return err
}
func (p *RecursiveStruct) writeField3(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetChildren() {
if err := oprot.WriteFieldBegin(ctx, "children", thrift.LIST, 3); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:children: ", p), err)
}
if err := oprot.WriteListBegin(ctx, thrift.STRUCT, len(p.Children)); err != nil {
return thrift.PrependError("error writing list begin: ", err)
}
for _, v := range p.Children {
if err := v.Write(ctx, oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err)
}
}
if err := oprot.WriteListEnd(ctx); err != nil {
return thrift.PrependError("error writing list end: ", err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 3:children: ", p), err)
}
}
return err
}
func (p *RecursiveStruct) Equals(other *RecursiveStruct) bool {
if p == other {
return true
} else if p == nil || other == nil {
return false
}
if !p.Recurse.Equals(other.Recurse) { return false }
if p.Data != other.Data { return false }
if len(p.Children) != len(other.Children) { return false }
for i, _tgt := range p.Children {
_src17 := other.Children[i]
if !_tgt.Equals(_src17) { return false }
}
return true
}
func (p *RecursiveStruct) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("RecursiveStruct(%+v)", *p)
}
func (p *RecursiveStruct) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*fuzztest.RecursiveStruct",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*RecursiveStruct)(nil)
func (p *RecursiveStruct) Validate() error {
return nil
}
// Attributes:
// - Basic
// - RequiredTest
// - Containers
// - UnionField
// - Recursive
// - Empty
// - FieldIds
// - EnumField
// - EnumMap
// - UserID
// - Data
//
type FuzzTest struct {
Basic *BasicTypes `thrift:"basic,1,required" db:"basic" json:"basic"`
RequiredTest *Requiredness `thrift:"required_test,2,required" db:"required_test" json:"required_test"`
Containers *Containers `thrift:"containers,3,required" db:"containers" json:"containers"`
UnionField *TestUnion `thrift:"union_field,4,required" db:"union_field" json:"union_field"`
Recursive *RecursiveStruct `thrift:"recursive,5" db:"recursive" json:"recursive,omitempty"`
Empty *EmptyStruct `thrift:"empty,6" db:"empty" json:"empty,omitempty"`
FieldIds *FieldIDTest `thrift:"field_ids,7" db:"field_ids" json:"field_ids,omitempty"`
EnumField TestEnum `thrift:"enum_field,8,required" db:"enum_field" json:"enum_field"`
EnumMap map[TestEnum]string `thrift:"enum_map,9" db:"enum_map" json:"enum_map,omitempty"`
UserID UserId `thrift:"user_id,10" db:"user_id" json:"user_id"`
Data BinaryData `thrift:"data,11" db:"data" json:"data"`
}
func NewFuzzTest() *FuzzTest {
return &FuzzTest{}
}
var FuzzTest_Basic_DEFAULT *BasicTypes
func (p *FuzzTest) GetBasic() *BasicTypes {
if !p.IsSetBasic() {
return FuzzTest_Basic_DEFAULT
}
return p.Basic
}
var FuzzTest_RequiredTest_DEFAULT *Requiredness
func (p *FuzzTest) GetRequiredTest() *Requiredness {
if !p.IsSetRequiredTest() {
return FuzzTest_RequiredTest_DEFAULT
}
return p.RequiredTest
}
var FuzzTest_Containers_DEFAULT *Containers
func (p *FuzzTest) GetContainers() *Containers {
if !p.IsSetContainers() {
return FuzzTest_Containers_DEFAULT
}
return p.Containers
}
var FuzzTest_UnionField_DEFAULT *TestUnion
func (p *FuzzTest) GetUnionField() *TestUnion {
if !p.IsSetUnionField() {
return FuzzTest_UnionField_DEFAULT
}
return p.UnionField
}
var FuzzTest_Recursive_DEFAULT *RecursiveStruct
func (p *FuzzTest) GetRecursive() *RecursiveStruct {
if !p.IsSetRecursive() {
return FuzzTest_Recursive_DEFAULT
}
return p.Recursive
}
var FuzzTest_Empty_DEFAULT *EmptyStruct
func (p *FuzzTest) GetEmpty() *EmptyStruct {
if !p.IsSetEmpty() {
return FuzzTest_Empty_DEFAULT
}
return p.Empty
}
var FuzzTest_FieldIds_DEFAULT *FieldIDTest
func (p *FuzzTest) GetFieldIds() *FieldIDTest {
if !p.IsSetFieldIds() {
return FuzzTest_FieldIds_DEFAULT
}
return p.FieldIds
}
func (p *FuzzTest) GetEnumField() TestEnum {
return p.EnumField
}
var FuzzTest_EnumMap_DEFAULT map[TestEnum]string
func (p *FuzzTest) GetEnumMap() map[TestEnum]string {
return p.EnumMap
}
func (p *FuzzTest) GetUserID() UserId {
return p.UserID
}
func (p *FuzzTest) GetData() BinaryData {
return p.Data
}
func (p *FuzzTest) IsSetBasic() bool {
return p.Basic != nil
}
func (p *FuzzTest) IsSetRequiredTest() bool {
return p.RequiredTest != nil
}
func (p *FuzzTest) IsSetContainers() bool {
return p.Containers != nil
}
func (p *FuzzTest) IsSetUnionField() bool {
return p.UnionField != nil
}
func (p *FuzzTest) IsSetRecursive() bool {
return p.Recursive != nil
}
func (p *FuzzTest) IsSetEmpty() bool {
return p.Empty != nil
}
func (p *FuzzTest) IsSetFieldIds() bool {
return p.FieldIds != nil
}
func (p *FuzzTest) IsSetEnumMap() bool {
return p.EnumMap != nil
}
func (p *FuzzTest) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
var issetBasic bool = false;
var issetRequiredTest bool = false;
var issetContainers bool = false;
var issetUnionField bool = false;
var issetEnumField bool = false;
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 1:
if fieldTypeId == thrift.STRUCT {
if err := p.ReadField1(ctx, iprot); err != nil {
return err
}
issetBasic = true
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 2:
if fieldTypeId == thrift.STRUCT {
if err := p.ReadField2(ctx, iprot); err != nil {
return err
}
issetRequiredTest = true
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 3:
if fieldTypeId == thrift.STRUCT {
if err := p.ReadField3(ctx, iprot); err != nil {
return err
}
issetContainers = true
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 4:
if fieldTypeId == thrift.STRUCT {
if err := p.ReadField4(ctx, iprot); err != nil {
return err
}
issetUnionField = true
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 5:
if fieldTypeId == thrift.STRUCT {
if err := p.ReadField5(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 6:
if fieldTypeId == thrift.STRUCT {
if err := p.ReadField6(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 7:
if fieldTypeId == thrift.STRUCT {
if err := p.ReadField7(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 8:
if fieldTypeId == thrift.I32 {
if err := p.ReadField8(ctx, iprot); err != nil {
return err
}
issetEnumField = true
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 9:
if fieldTypeId == thrift.MAP {
if err := p.ReadField9(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 10:
if fieldTypeId == thrift.I64 {
if err := p.ReadField10(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 11:
if fieldTypeId == thrift.STRING {
if err := p.ReadField11(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
if !issetBasic{
return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Basic is not set"))
}
if !issetRequiredTest{
return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field RequiredTest is not set"))
}
if !issetContainers{
return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Containers is not set"))
}
if !issetUnionField{
return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field UnionField is not set"))
}
if !issetEnumField{
return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field EnumField is not set"))
}
return nil
}
func (p *FuzzTest) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
p.Basic = &BasicTypes{}
if err := p.Basic.Read(ctx, iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Basic), err)
}
return nil
}
func (p *FuzzTest) ReadField2(ctx context.Context, iprot thrift.TProtocol) error {
p.RequiredTest = &Requiredness{
OptWithDefault: "test",
ReqWithDefault: true,
}
if err := p.RequiredTest.Read(ctx, iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.RequiredTest), err)
}
return nil
}
func (p *FuzzTest) ReadField3(ctx context.Context, iprot thrift.TProtocol) error {
p.Containers = &Containers{}
if err := p.Containers.Read(ctx, iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Containers), err)
}
return nil
}
func (p *FuzzTest) ReadField4(ctx context.Context, iprot thrift.TProtocol) error {
p.UnionField = &TestUnion{}
if err := p.UnionField.Read(ctx, iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.UnionField), err)
}
return nil
}
func (p *FuzzTest) ReadField5(ctx context.Context, iprot thrift.TProtocol) error {
p.Recursive = &RecursiveStruct{}
if err := p.Recursive.Read(ctx, iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Recursive), err)
}
return nil
}
func (p *FuzzTest) ReadField6(ctx context.Context, iprot thrift.TProtocol) error {
p.Empty = &EmptyStruct{}
if err := p.Empty.Read(ctx, iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Empty), err)
}
return nil
}
func (p *FuzzTest) ReadField7(ctx context.Context, iprot thrift.TProtocol) error {
p.FieldIds = &FieldIDTest{}
if err := p.FieldIds.Read(ctx, iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.FieldIds), err)
}
return nil
}
func (p *FuzzTest) ReadField8(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 8: ", err)
} else {
temp := TestEnum(v)
p.EnumField = temp
}
return nil
}
func (p *FuzzTest) ReadField9(ctx context.Context, iprot thrift.TProtocol) error {
_, _, size, err := iprot.ReadMapBegin(ctx)
if err != nil {
return thrift.PrependError("error reading map begin: ", err)
}
tMap := make(map[TestEnum]string, size)
p.EnumMap = tMap
for i := 0; i < size; i++ {
var _key18 TestEnum
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 0: ", err)
} else {
temp := TestEnum(v)
_key18 = temp
}
var _val19 string
if v, err := iprot.ReadString(ctx); err != nil {
return thrift.PrependError("error reading field 0: ", err)
} else {
_val19 = v
}
p.EnumMap[_key18] = _val19
}
if err := iprot.ReadMapEnd(ctx); err != nil {
return thrift.PrependError("error reading map end: ", err)
}
return nil
}
func (p *FuzzTest) ReadField10(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI64(ctx); err != nil {
return thrift.PrependError("error reading field 10: ", err)
} else {
temp := UserId(v)
p.UserID = temp
}
return nil
}
func (p *FuzzTest) ReadField11(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadBinary(ctx); err != nil {
return thrift.PrependError("error reading field 11: ", err)
} else {
temp := BinaryData(v)
p.Data = temp
}
return nil
}
func (p *FuzzTest) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "FuzzTest"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField1(ctx, oprot); err != nil { return err }
if err := p.writeField2(ctx, oprot); err != nil { return err }
if err := p.writeField3(ctx, oprot); err != nil { return err }
if err := p.writeField4(ctx, oprot); err != nil { return err }
if err := p.writeField5(ctx, oprot); err != nil { return err }
if err := p.writeField6(ctx, oprot); err != nil { return err }
if err := p.writeField7(ctx, oprot); err != nil { return err }
if err := p.writeField8(ctx, oprot); err != nil { return err }
if err := p.writeField9(ctx, oprot); err != nil { return err }
if err := p.writeField10(ctx, oprot); err != nil { return err }
if err := p.writeField11(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *FuzzTest) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "basic", thrift.STRUCT, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:basic: ", p), err)
}
if err := p.Basic.Write(ctx, oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Basic), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:basic: ", p), err)
}
return err
}
func (p *FuzzTest) writeField2(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "required_test", thrift.STRUCT, 2); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:required_test: ", p), err)
}
if err := p.RequiredTest.Write(ctx, oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.RequiredTest), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 2:required_test: ", p), err)
}
return err
}
func (p *FuzzTest) writeField3(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "containers", thrift.STRUCT, 3); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:containers: ", p), err)
}
if err := p.Containers.Write(ctx, oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Containers), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 3:containers: ", p), err)
}
return err
}
func (p *FuzzTest) writeField4(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "union_field", thrift.STRUCT, 4); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:union_field: ", p), err)
}
if err := p.UnionField.Write(ctx, oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.UnionField), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 4:union_field: ", p), err)
}
return err
}
func (p *FuzzTest) writeField5(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetRecursive() {
if err := oprot.WriteFieldBegin(ctx, "recursive", thrift.STRUCT, 5); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 5:recursive: ", p), err)
}
if err := p.Recursive.Write(ctx, oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Recursive), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 5:recursive: ", p), err)
}
}
return err
}
func (p *FuzzTest) writeField6(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetEmpty() {
if err := oprot.WriteFieldBegin(ctx, "empty", thrift.STRUCT, 6); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 6:empty: ", p), err)
}
if err := p.Empty.Write(ctx, oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Empty), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 6:empty: ", p), err)
}
}
return err
}
func (p *FuzzTest) writeField7(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetFieldIds() {
if err := oprot.WriteFieldBegin(ctx, "field_ids", thrift.STRUCT, 7); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 7:field_ids: ", p), err)
}
if err := p.FieldIds.Write(ctx, oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.FieldIds), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 7:field_ids: ", p), err)
}
}
return err
}
func (p *FuzzTest) writeField8(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "enum_field", thrift.I32, 8); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 8:enum_field: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.EnumField)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.enum_field (8) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 8:enum_field: ", p), err)
}
return err
}
func (p *FuzzTest) writeField9(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetEnumMap() {
if err := oprot.WriteFieldBegin(ctx, "enum_map", thrift.MAP, 9); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 9:enum_map: ", p), err)
}
if err := oprot.WriteMapBegin(ctx, thrift.I32, thrift.STRING, len(p.EnumMap)); err != nil {
return thrift.PrependError("error writing map begin: ", err)
}
for k, v := range p.EnumMap {
if err := oprot.WriteI32(ctx, int32(k)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
}
if err := oprot.WriteString(ctx, string(v)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
}
}
if err := oprot.WriteMapEnd(ctx); err != nil {
return thrift.PrependError("error writing map end: ", err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 9:enum_map: ", p), err)
}
}
return err
}
func (p *FuzzTest) writeField10(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "user_id", thrift.I64, 10); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 10:user_id: ", p), err)
}
if err := oprot.WriteI64(ctx, int64(p.UserID)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.user_id (10) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 10:user_id: ", p), err)
}
return err
}
func (p *FuzzTest) writeField11(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "data", thrift.STRING, 11); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 11:data: ", p), err)
}
if err := oprot.WriteBinary(ctx, p.Data); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.data (11) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 11:data: ", p), err)
}
return err
}
func (p *FuzzTest) Equals(other *FuzzTest) bool {
if p == other {
return true
} else if p == nil || other == nil {
return false
}
if !p.Basic.Equals(other.Basic) { return false }
if !p.RequiredTest.Equals(other.RequiredTest) { return false }
if !p.Containers.Equals(other.Containers) { return false }
if !p.UnionField.Equals(other.UnionField) { return false }
if !p.Recursive.Equals(other.Recursive) { return false }
if !p.Empty.Equals(other.Empty) { return false }
if !p.FieldIds.Equals(other.FieldIds) { return false }
if p.EnumField != other.EnumField { return false }
if len(p.EnumMap) != len(other.EnumMap) { return false }
for k, _tgt := range p.EnumMap {
_src20 := other.EnumMap[k]
if _tgt != _src20 { return false }
}
if p.UserID != other.UserID { return false }
if bytes.Compare(p.Data, other.Data) != 0 { return false }
return true
}
func (p *FuzzTest) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("FuzzTest(%+v)", *p)
}
func (p *FuzzTest) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*fuzztest.FuzzTest",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*FuzzTest)(nil)
func (p *FuzzTest) Validate() error {
return nil
}
// Code generated by Thrift Compiler (0.23.0). DO NOT EDIT.
package shared
import (
"bytes"
"context"
"errors"
"fmt"
"iter"
"log/slog"
"time"
thrift "github.com/apache/thrift/lib/go/thrift"
"strings"
"regexp"
)
// (needed to ensure safety because of naive import list construction.)
var _ = bytes.Equal
var _ = context.Background
var _ = errors.New
var _ = fmt.Printf
var _ = iter.Pull[int]
var _ = slog.Log
var _ = time.Now
var _ = thrift.ZERO
// (needed by validator.)
var _ = strings.Contains
var _ = regexp.MatchString
func init() {
}
// Code generated by Thrift Compiler (0.23.0). DO NOT EDIT.
package shared
import (
"bytes"
"context"
"errors"
"fmt"
"iter"
"log/slog"
"time"
thrift "github.com/apache/thrift/lib/go/thrift"
"strings"
"regexp"
)
// (needed to ensure safety because of naive import list construction.)
var _ = bytes.Equal
var _ = context.Background
var _ = errors.New
var _ = fmt.Printf
var _ = iter.Pull[int]
var _ = slog.Log
var _ = time.Now
var _ = thrift.ZERO
// (needed by validator.)
var _ = strings.Contains
var _ = regexp.MatchString
// Attributes:
// - Key
// - Value
//
type SharedStruct struct {
Key int32 `thrift:"key,1" db:"key" json:"key"`
Value string `thrift:"value,2" db:"value" json:"value"`
}
func NewSharedStruct() *SharedStruct {
return &SharedStruct{}
}
func (p *SharedStruct) GetKey() int32 {
return p.Key
}
func (p *SharedStruct) GetValue() string {
return p.Value
}
func (p *SharedStruct) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 1:
if fieldTypeId == thrift.I32 {
if err := p.ReadField1(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 2:
if fieldTypeId == thrift.STRING {
if err := p.ReadField2(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *SharedStruct) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 1: ", err)
} else {
p.Key = v
}
return nil
}
func (p *SharedStruct) ReadField2(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadString(ctx); err != nil {
return thrift.PrependError("error reading field 2: ", err)
} else {
p.Value = v
}
return nil
}
func (p *SharedStruct) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "SharedStruct"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField1(ctx, oprot); err != nil { return err }
if err := p.writeField2(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *SharedStruct) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "key", thrift.I32, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:key: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.Key)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.key (1) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:key: ", p), err)
}
return err
}
func (p *SharedStruct) writeField2(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "value", thrift.STRING, 2); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:value: ", p), err)
}
if err := oprot.WriteString(ctx, string(p.Value)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.value (2) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 2:value: ", p), err)
}
return err
}
func (p *SharedStruct) Equals(other *SharedStruct) bool {
if p == other {
return true
} else if p == nil || other == nil {
return false
}
if p.Key != other.Key { return false }
if p.Value != other.Value { return false }
return true
}
func (p *SharedStruct) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("SharedStruct(%+v)", *p)
}
func (p *SharedStruct) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*shared.SharedStruct",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*SharedStruct)(nil)
func (p *SharedStruct) Validate() error {
return nil
}
type SharedService interface {
// Parameters:
// - Key
//
GetStruct(ctx context.Context, key int32) (_r *SharedStruct, _err error)
}
type SharedServiceClient struct {
c thrift.TClient
meta thrift.ResponseMeta
}
func NewSharedServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *SharedServiceClient {
return &SharedServiceClient{
c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)),
}
}
func NewSharedServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *SharedServiceClient {
return &SharedServiceClient{
c: thrift.NewTStandardClient(iprot, oprot),
}
}
func NewSharedServiceClient(c thrift.TClient) *SharedServiceClient {
return &SharedServiceClient{
c: c,
}
}
func (p *SharedServiceClient) Client_() thrift.TClient {
return p.c
}
func (p *SharedServiceClient) LastResponseMeta_() thrift.ResponseMeta {
return p.meta
}
func (p *SharedServiceClient) SetLastResponseMeta_(meta thrift.ResponseMeta) {
p.meta = meta
}
// Parameters:
// - Key
//
func (p *SharedServiceClient) GetStruct(ctx context.Context, key int32) (_r *SharedStruct, _err error) {
var _args0 SharedServiceGetStructArgs
_args0.Key = key
var _result2 SharedServiceGetStructResult
var _meta1 thrift.ResponseMeta
_meta1, _err = p.Client_().Call(ctx, "getStruct", &_args0, &_result2)
p.SetLastResponseMeta_(_meta1)
if _err != nil {
return
}
if _ret3 := _result2.GetSuccess(); _ret3 != nil {
return _ret3, nil
}
return nil, thrift.NewTApplicationException(thrift.MISSING_RESULT, "getStruct failed: unknown result")
}
type SharedServiceProcessor struct {
processorMap map[string]thrift.TProcessorFunction
handler SharedService
}
func (p *SharedServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) {
p.processorMap[key] = processor
}
func (p *SharedServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) {
processor, ok = p.processorMap[key]
return processor, ok
}
func (p *SharedServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction {
return p.processorMap
}
func NewSharedServiceProcessor(handler SharedService) *SharedServiceProcessor {
self4 := &SharedServiceProcessor{handler:handler, processorMap:make(map[string]thrift.TProcessorFunction)}
self4.processorMap["getStruct"] = &sharedServiceProcessorGetStruct{handler:handler}
return self4
}
func (p *SharedServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
name, _, seqId, err2 := iprot.ReadMessageBegin(ctx)
if err2 != nil { return false, thrift.WrapTException(err2) }
if processor, ok := p.GetProcessorFunction(name); ok {
return processor.Process(ctx, seqId, iprot, oprot)
}
iprot.Skip(ctx, thrift.STRUCT)
iprot.ReadMessageEnd(ctx)
x5 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function " + name)
oprot.WriteMessageBegin(ctx, name, thrift.EXCEPTION, seqId)
x5.Write(ctx, oprot)
oprot.WriteMessageEnd(ctx)
oprot.Flush(ctx)
return false, x5
}
type sharedServiceProcessorGetStruct struct {
handler SharedService
}
func (p *sharedServiceProcessorGetStruct) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
var _write_err6 thrift.TException
args := SharedServiceGetStructArgs{}
if err2 := args.Read(ctx, iprot); err2 != nil {
iprot.ReadMessageEnd(ctx)
x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err2.Error())
oprot.WriteMessageBegin(ctx, "getStruct", thrift.EXCEPTION, seqId)
x.Write(ctx, oprot)
oprot.WriteMessageEnd(ctx)
oprot.Flush(ctx)
return false, thrift.WrapTException(err2)
}
iprot.ReadMessageEnd(ctx)
tickerCancel := func() {}
// Start a goroutine to do server side connectivity check.
if thrift.ServerConnectivityCheckInterval > 0 {
var cancel context.CancelCauseFunc
ctx, cancel = context.WithCancelCause(ctx)
defer cancel(nil)
var tickerCtx context.Context
tickerCtx, tickerCancel = context.WithCancel(context.Background())
defer tickerCancel()
go func(ctx context.Context, cancel context.CancelCauseFunc) {
ticker := time.NewTicker(thrift.ServerConnectivityCheckInterval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
if !iprot.Transport().IsOpen() {
cancel(thrift.ErrAbandonRequest)
return
}
}
}
}(tickerCtx, cancel)
}
result := SharedServiceGetStructResult{}
if retval, err2 := p.handler.GetStruct(ctx, args.Key); err2 != nil {
tickerCancel()
err = thrift.WrapTException(err2)
if errors.Is(err2, thrift.ErrAbandonRequest) {
return false, &thrift.ProcessorError{
WriteError: thrift.WrapTException(err2),
EndpointError: err,
}
}
if errors.Is(err2, context.Canceled) {
if err3 := context.Cause(ctx); errors.Is(err3, thrift.ErrAbandonRequest) {
return false, &thrift.ProcessorError{
WriteError: thrift.WrapTException(err3),
EndpointError: err,
}
}
}
_exc7 := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getStruct: " + err2.Error())
if err2 := oprot.WriteMessageBegin(ctx, "getStruct", thrift.EXCEPTION, seqId); err2 != nil {
_write_err6 = thrift.WrapTException(err2)
}
if err2 := _exc7.Write(ctx, oprot); _write_err6 == nil && err2 != nil {
_write_err6 = thrift.WrapTException(err2)
}
if err2 := oprot.WriteMessageEnd(ctx); _write_err6 == nil && err2 != nil {
_write_err6 = thrift.WrapTException(err2)
}
if err2 := oprot.Flush(ctx); _write_err6 == nil && err2 != nil {
_write_err6 = thrift.WrapTException(err2)
}
if _write_err6 != nil {
return false, &thrift.ProcessorError{
WriteError: _write_err6,
EndpointError: err,
}
}
return true, err
} else {
result.Success = retval
}
tickerCancel()
if err2 := oprot.WriteMessageBegin(ctx, "getStruct", thrift.REPLY, seqId); err2 != nil {
_write_err6 = thrift.WrapTException(err2)
}
if err2 := result.Write(ctx, oprot); _write_err6 == nil && err2 != nil {
_write_err6 = thrift.WrapTException(err2)
}
if err2 := oprot.WriteMessageEnd(ctx); _write_err6 == nil && err2 != nil {
_write_err6 = thrift.WrapTException(err2)
}
if err2 := oprot.Flush(ctx); _write_err6 == nil && err2 != nil {
_write_err6 = thrift.WrapTException(err2)
}
if _write_err6 != nil {
return false, &thrift.ProcessorError{
WriteError: _write_err6,
EndpointError: err,
}
}
return true, err
}
// HELPER FUNCTIONS AND STRUCTURES
// Attributes:
// - Key
//
type SharedServiceGetStructArgs struct {
Key int32 `thrift:"key,1" db:"key" json:"key"`
}
func NewSharedServiceGetStructArgs() *SharedServiceGetStructArgs {
return &SharedServiceGetStructArgs{}
}
func (p *SharedServiceGetStructArgs) GetKey() int32 {
return p.Key
}
func (p *SharedServiceGetStructArgs) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 1:
if fieldTypeId == thrift.I32 {
if err := p.ReadField1(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *SharedServiceGetStructArgs) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 1: ", err)
} else {
p.Key = v
}
return nil
}
func (p *SharedServiceGetStructArgs) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "getStruct_args"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField1(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *SharedServiceGetStructArgs) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "key", thrift.I32, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:key: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.Key)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.key (1) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:key: ", p), err)
}
return err
}
func (p *SharedServiceGetStructArgs) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("SharedServiceGetStructArgs(%+v)", *p)
}
func (p *SharedServiceGetStructArgs) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*shared.SharedServiceGetStructArgs",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*SharedServiceGetStructArgs)(nil)
// Attributes:
// - Success
//
type SharedServiceGetStructResult struct {
Success *SharedStruct `thrift:"success,0" db:"success" json:"success,omitempty"`
}
func NewSharedServiceGetStructResult() *SharedServiceGetStructResult {
return &SharedServiceGetStructResult{}
}
var SharedServiceGetStructResult_Success_DEFAULT *SharedStruct
func (p *SharedServiceGetStructResult) GetSuccess() *SharedStruct {
if !p.IsSetSuccess() {
return SharedServiceGetStructResult_Success_DEFAULT
}
return p.Success
}
func (p *SharedServiceGetStructResult) IsSetSuccess() bool {
return p.Success != nil
}
func (p *SharedServiceGetStructResult) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 0:
if fieldTypeId == thrift.STRUCT {
if err := p.ReadField0(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *SharedServiceGetStructResult) ReadField0(ctx context.Context, iprot thrift.TProtocol) error {
p.Success = &SharedStruct{}
if err := p.Success.Read(ctx, iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Success), err)
}
return nil
}
func (p *SharedServiceGetStructResult) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "getStruct_result"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField0(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *SharedServiceGetStructResult) writeField0(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetSuccess() {
if err := oprot.WriteFieldBegin(ctx, "success", thrift.STRUCT, 0); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err)
}
if err := p.Success.Write(ctx, oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Success), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err)
}
}
return err
}
func (p *SharedServiceGetStructResult) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("SharedServiceGetStructResult(%+v)", *p)
}
func (p *SharedServiceGetStructResult) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*shared.SharedServiceGetStructResult",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*SharedServiceGetStructResult)(nil)
// Code generated by Thrift Compiler (0.23.0). DO NOT EDIT.
package tutorial
import (
"bytes"
"context"
"errors"
"fmt"
"iter"
"log/slog"
"time"
thrift "github.com/apache/thrift/lib/go/thrift"
"strings"
"regexp"
"github.com/apache/thrift/lib/go/test/fuzz/gen-go/shared"
)
// (needed to ensure safety because of naive import list construction.)
var _ = bytes.Equal
var _ = context.Background
var _ = errors.New
var _ = fmt.Printf
var _ = iter.Pull[int]
var _ = slog.Log
var _ = time.Now
var _ = thrift.ZERO
// (needed by validator.)
var _ = strings.Contains
var _ = regexp.MatchString
var _ = shared.GoUnusedProtection__
const INT32CONSTANT = 9853
var MAPCONSTANT map[string]string
func init() {
MAPCONSTANT = map[string]string{
"goodnight": "moon",
"hello": "world",
}
}
// Code generated by Thrift Compiler (0.23.0). DO NOT EDIT.
package tutorial
import (
"bytes"
"context"
"database/sql/driver"
"errors"
"fmt"
"iter"
"log/slog"
"time"
thrift "github.com/apache/thrift/lib/go/thrift"
"strings"
"regexp"
"github.com/apache/thrift/lib/go/test/fuzz/gen-go/shared"
)
// (needed to ensure safety because of naive import list construction.)
var _ = bytes.Equal
var _ = context.Background
var _ = errors.New
var _ = fmt.Printf
var _ = iter.Pull[int]
var _ = slog.Log
var _ = time.Now
var _ = thrift.ZERO
// (needed by validator.)
var _ = strings.Contains
var _ = regexp.MatchString
var _ = shared.GoUnusedProtection__
//You can define enums, which are just 32 bit integers. Values are optional
//and start at 1 if not supplied, C style again.
type Operation int64
const (
Operation_ADD Operation = 1
Operation_SUBTRACT Operation = 2
Operation_MULTIPLY Operation = 3
Operation_DIVIDE Operation = 4
)
var knownOperationValues = []Operation{
Operation_ADD,
Operation_SUBTRACT,
Operation_MULTIPLY,
Operation_DIVIDE,
}
func OperationValues() iter.Seq[Operation] {
return func(yield func(Operation) bool) {
for _, v := range knownOperationValues {
if !yield(v) {
return
}
}
}
}
func (p Operation) String() string {
switch p {
case Operation_ADD: return "ADD"
case Operation_SUBTRACT: return "SUBTRACT"
case Operation_MULTIPLY: return "MULTIPLY"
case Operation_DIVIDE: return "DIVIDE"
}
return "<UNSET>"
}
func OperationFromString(s string) (Operation, error) {
switch s {
case "ADD": return Operation_ADD, nil
case "SUBTRACT": return Operation_SUBTRACT, nil
case "MULTIPLY": return Operation_MULTIPLY, nil
case "DIVIDE": return Operation_DIVIDE, nil
}
return Operation(0), fmt.Errorf("not a valid Operation string")
}
func OperationPtr(v Operation) *Operation { return &v }
func (p Operation) MarshalText() ([]byte, error) {
return []byte(p.String()), nil
}
func (p *Operation) UnmarshalText(text []byte) error {
q, err := OperationFromString(string(text))
if err != nil {
return err
}
*p = q
return nil
}
func (p *Operation) Scan(value interface{}) error {
v, ok := value.(int64)
if !ok {
return errors.New("Scan value is not int64")
}
*p = Operation(v)
return nil
}
func (p *Operation) Value() (driver.Value, error) {
if p == nil {
return nil, nil
}
return int64(*p), nil
}
//Thrift lets you do typedefs to get pretty names for your types. Standard
//C style here.
type MyInteger int32
func MyIntegerPtr(v MyInteger) *MyInteger { return &v }
// Structs are the basic complex data structures. They are comprised of fields
// which each have an integer identifier, a type, a symbolic name, and an
// optional default value.
//
// Fields can be declared "optional", which ensures they will not be included
// in the serialized output if they aren't set. Note that this requires some
// manual management in some languages.
//
// Attributes:
// - Num1
// - Num2
// - Op
// - Comment
//
type Work struct {
Num1 int32 `thrift:"num1,1" db:"num1" json:"num1"`
Num2 int32 `thrift:"num2,2" db:"num2" json:"num2"`
Op Operation `thrift:"op,3" db:"op" json:"op"`
Comment *string `thrift:"comment,4" db:"comment" json:"comment,omitempty"`
}
func NewWork() *Work {
return &Work{}
}
func (p *Work) GetNum1() int32 {
return p.Num1
}
func (p *Work) GetNum2() int32 {
return p.Num2
}
func (p *Work) GetOp() Operation {
return p.Op
}
var Work_Comment_DEFAULT string
func (p *Work) GetComment() string {
if !p.IsSetComment() {
return Work_Comment_DEFAULT
}
return *p.Comment
}
func (p *Work) IsSetComment() bool {
return p.Comment != nil
}
func (p *Work) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 1:
if fieldTypeId == thrift.I32 {
if err := p.ReadField1(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 2:
if fieldTypeId == thrift.I32 {
if err := p.ReadField2(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 3:
if fieldTypeId == thrift.I32 {
if err := p.ReadField3(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 4:
if fieldTypeId == thrift.STRING {
if err := p.ReadField4(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *Work) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 1: ", err)
} else {
p.Num1 = v
}
return nil
}
func (p *Work) ReadField2(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 2: ", err)
} else {
p.Num2 = v
}
return nil
}
func (p *Work) ReadField3(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 3: ", err)
} else {
temp := Operation(v)
p.Op = temp
}
return nil
}
func (p *Work) ReadField4(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadString(ctx); err != nil {
return thrift.PrependError("error reading field 4: ", err)
} else {
p.Comment = &v
}
return nil
}
func (p *Work) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "Work"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField1(ctx, oprot); err != nil { return err }
if err := p.writeField2(ctx, oprot); err != nil { return err }
if err := p.writeField3(ctx, oprot); err != nil { return err }
if err := p.writeField4(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *Work) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "num1", thrift.I32, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:num1: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.Num1)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.num1 (1) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:num1: ", p), err)
}
return err
}
func (p *Work) writeField2(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "num2", thrift.I32, 2); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:num2: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.Num2)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.num2 (2) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 2:num2: ", p), err)
}
return err
}
func (p *Work) writeField3(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "op", thrift.I32, 3); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:op: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.Op)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.op (3) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 3:op: ", p), err)
}
return err
}
func (p *Work) writeField4(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetComment() {
if err := oprot.WriteFieldBegin(ctx, "comment", thrift.STRING, 4); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:comment: ", p), err)
}
if err := oprot.WriteString(ctx, string(*p.Comment)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.comment (4) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 4:comment: ", p), err)
}
}
return err
}
func (p *Work) Equals(other *Work) bool {
if p == other {
return true
} else if p == nil || other == nil {
return false
}
if p.Num1 != other.Num1 { return false }
if p.Num2 != other.Num2 { return false }
if p.Op != other.Op { return false }
if p.Comment != other.Comment {
if p.Comment == nil || other.Comment == nil {
return false
}
if (*p.Comment) != (*other.Comment) { return false }
}
return true
}
func (p *Work) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("Work(%+v)", *p)
}
func (p *Work) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*tutorial.Work",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*Work)(nil)
func (p *Work) Validate() error {
return nil
}
// Structs can also be exceptions, if they are nasty.
//
// Attributes:
// - WhatOp
// - Why
//
type InvalidOperation struct {
WhatOp int32 `thrift:"whatOp,1" db:"whatOp" json:"whatOp"`
Why string `thrift:"why,2" db:"why" json:"why"`
}
func NewInvalidOperation() *InvalidOperation {
return &InvalidOperation{}
}
func (p *InvalidOperation) GetWhatOp() int32 {
return p.WhatOp
}
func (p *InvalidOperation) GetWhy() string {
return p.Why
}
func (p *InvalidOperation) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 1:
if fieldTypeId == thrift.I32 {
if err := p.ReadField1(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 2:
if fieldTypeId == thrift.STRING {
if err := p.ReadField2(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *InvalidOperation) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 1: ", err)
} else {
p.WhatOp = v
}
return nil
}
func (p *InvalidOperation) ReadField2(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadString(ctx); err != nil {
return thrift.PrependError("error reading field 2: ", err)
} else {
p.Why = v
}
return nil
}
func (p *InvalidOperation) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "InvalidOperation"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField1(ctx, oprot); err != nil { return err }
if err := p.writeField2(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *InvalidOperation) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "whatOp", thrift.I32, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:whatOp: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.WhatOp)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.whatOp (1) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:whatOp: ", p), err)
}
return err
}
func (p *InvalidOperation) writeField2(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "why", thrift.STRING, 2); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:why: ", p), err)
}
if err := oprot.WriteString(ctx, string(p.Why)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.why (2) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 2:why: ", p), err)
}
return err
}
func (p *InvalidOperation) Equals(other *InvalidOperation) bool {
if p == other {
return true
} else if p == nil || other == nil {
return false
}
if p.WhatOp != other.WhatOp { return false }
if p.Why != other.Why { return false }
return true
}
func (p *InvalidOperation) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("InvalidOperation(%+v)", *p)
}
func (p *InvalidOperation) Error() string {
return p.String()
}
func (InvalidOperation) TExceptionType() thrift.TExceptionType {
return thrift.TExceptionTypeCompiled
}
var _ thrift.TException = (*InvalidOperation)(nil)
func (p *InvalidOperation) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*tutorial.InvalidOperation",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*InvalidOperation)(nil)
func (p *InvalidOperation) Validate() error {
return nil
}
type Calculator interface {
shared.SharedService
//Ahh, now onto the cool part, defining a service. Services just need a name
//and can optionally inherit from another service using the extends keyword.
// A method definition looks like C code. It has a return type, arguments,
// and optionally a list of exceptions that it may throw. Note that argument
// lists and exception lists are specified using the exact same syntax as
// field lists in struct or exception definitions.
Ping(ctx context.Context) (_err error)
// Parameters:
// - Num1
// - Num2
//
Add(ctx context.Context, num1 int32, num2 int32) (_r int32, _err error)
// Parameters:
// - Logid
// - W
//
Calculate(ctx context.Context, logid int32, w *Work) (_r int32, _err error)
// This method has a oneway modifier. That means the client only makes
// a request and does not listen for any response at all. Oneway methods
// must be void.
Zip(ctx context.Context) (_err error)
}
//Ahh, now onto the cool part, defining a service. Services just need a name
//and can optionally inherit from another service using the extends keyword.
type CalculatorClient struct {
*shared.SharedServiceClient
}
func NewCalculatorClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *CalculatorClient {
return &CalculatorClient{SharedServiceClient: shared.NewSharedServiceClientFactory(t, f)}}
func NewCalculatorClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *CalculatorClient {
return &CalculatorClient{SharedServiceClient: shared.NewSharedServiceClientProtocol(t, iprot, oprot)}
}
func NewCalculatorClient(c thrift.TClient) *CalculatorClient {
return &CalculatorClient{
SharedServiceClient: shared.NewSharedServiceClient(c),
}
}
// A method definition looks like C code. It has a return type, arguments,
// and optionally a list of exceptions that it may throw. Note that argument
// lists and exception lists are specified using the exact same syntax as
// field lists in struct or exception definitions.
func (p *CalculatorClient) Ping(ctx context.Context) (_err error) {
var _args0 CalculatorPingArgs
var _result2 CalculatorPingResult
var _meta1 thrift.ResponseMeta
_meta1, _err = p.Client_().Call(ctx, "ping", &_args0, &_result2)
p.SetLastResponseMeta_(_meta1)
if _err != nil {
return
}
return nil
}
// Parameters:
// - Num1
// - Num2
//
func (p *CalculatorClient) Add(ctx context.Context, num1 int32, num2 int32) (_r int32, _err error) {
var _args3 CalculatorAddArgs
_args3.Num1 = num1
_args3.Num2 = num2
var _result5 CalculatorAddResult
var _meta4 thrift.ResponseMeta
_meta4, _err = p.Client_().Call(ctx, "add", &_args3, &_result5)
p.SetLastResponseMeta_(_meta4)
if _err != nil {
return
}
return _result5.GetSuccess(), nil
}
// Parameters:
// - Logid
// - W
//
func (p *CalculatorClient) Calculate(ctx context.Context, logid int32, w *Work) (_r int32, _err error) {
var _args6 CalculatorCalculateArgs
_args6.Logid = logid
_args6.W = w
var _result8 CalculatorCalculateResult
var _meta7 thrift.ResponseMeta
_meta7, _err = p.Client_().Call(ctx, "calculate", &_args6, &_result8)
p.SetLastResponseMeta_(_meta7)
if _err != nil {
return
}
switch {
case _result8.Ouch!= nil:
return _r, _result8.Ouch
}
return _result8.GetSuccess(), nil
}
// This method has a oneway modifier. That means the client only makes
// a request and does not listen for any response at all. Oneway methods
// must be void.
func (p *CalculatorClient) Zip(ctx context.Context) (_err error) {
var _args9 CalculatorZipArgs
p.SetLastResponseMeta_(thrift.ResponseMeta{})
if _, err := p.Client_().Call(ctx, "zip", &_args9, nil); err != nil {
return err
}
return nil
}
type CalculatorProcessor struct {
*shared.SharedServiceProcessor
}
func NewCalculatorProcessor(handler Calculator) *CalculatorProcessor {
self10 := &CalculatorProcessor{shared.NewSharedServiceProcessor(handler)}
self10.AddToProcessorMap("ping", &calculatorProcessorPing{handler:handler})
self10.AddToProcessorMap("add", &calculatorProcessorAdd{handler:handler})
self10.AddToProcessorMap("calculate", &calculatorProcessorCalculate{handler:handler})
self10.AddToProcessorMap("zip", &calculatorProcessorZip{handler:handler})
return self10
}
type calculatorProcessorPing struct {
handler Calculator
}
func (p *calculatorProcessorPing) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
var _write_err11 thrift.TException
args := CalculatorPingArgs{}
if err2 := args.Read(ctx, iprot); err2 != nil {
iprot.ReadMessageEnd(ctx)
x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err2.Error())
oprot.WriteMessageBegin(ctx, "ping", thrift.EXCEPTION, seqId)
x.Write(ctx, oprot)
oprot.WriteMessageEnd(ctx)
oprot.Flush(ctx)
return false, thrift.WrapTException(err2)
}
iprot.ReadMessageEnd(ctx)
tickerCancel := func() {}
// Start a goroutine to do server side connectivity check.
if thrift.ServerConnectivityCheckInterval > 0 {
var cancel context.CancelCauseFunc
ctx, cancel = context.WithCancelCause(ctx)
defer cancel(nil)
var tickerCtx context.Context
tickerCtx, tickerCancel = context.WithCancel(context.Background())
defer tickerCancel()
go func(ctx context.Context, cancel context.CancelCauseFunc) {
ticker := time.NewTicker(thrift.ServerConnectivityCheckInterval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
if !iprot.Transport().IsOpen() {
cancel(thrift.ErrAbandonRequest)
return
}
}
}
}(tickerCtx, cancel)
}
result := CalculatorPingResult{}
if err2 := p.handler.Ping(ctx); err2 != nil {
tickerCancel()
err = thrift.WrapTException(err2)
if errors.Is(err2, thrift.ErrAbandonRequest) {
return false, &thrift.ProcessorError{
WriteError: thrift.WrapTException(err2),
EndpointError: err,
}
}
if errors.Is(err2, context.Canceled) {
if err3 := context.Cause(ctx); errors.Is(err3, thrift.ErrAbandonRequest) {
return false, &thrift.ProcessorError{
WriteError: thrift.WrapTException(err3),
EndpointError: err,
}
}
}
_exc12 := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing ping: " + err2.Error())
if err2 := oprot.WriteMessageBegin(ctx, "ping", thrift.EXCEPTION, seqId); err2 != nil {
_write_err11 = thrift.WrapTException(err2)
}
if err2 := _exc12.Write(ctx, oprot); _write_err11 == nil && err2 != nil {
_write_err11 = thrift.WrapTException(err2)
}
if err2 := oprot.WriteMessageEnd(ctx); _write_err11 == nil && err2 != nil {
_write_err11 = thrift.WrapTException(err2)
}
if err2 := oprot.Flush(ctx); _write_err11 == nil && err2 != nil {
_write_err11 = thrift.WrapTException(err2)
}
if _write_err11 != nil {
return false, &thrift.ProcessorError{
WriteError: _write_err11,
EndpointError: err,
}
}
return true, err
}
tickerCancel()
if err2 := oprot.WriteMessageBegin(ctx, "ping", thrift.REPLY, seqId); err2 != nil {
_write_err11 = thrift.WrapTException(err2)
}
if err2 := result.Write(ctx, oprot); _write_err11 == nil && err2 != nil {
_write_err11 = thrift.WrapTException(err2)
}
if err2 := oprot.WriteMessageEnd(ctx); _write_err11 == nil && err2 != nil {
_write_err11 = thrift.WrapTException(err2)
}
if err2 := oprot.Flush(ctx); _write_err11 == nil && err2 != nil {
_write_err11 = thrift.WrapTException(err2)
}
if _write_err11 != nil {
return false, &thrift.ProcessorError{
WriteError: _write_err11,
EndpointError: err,
}
}
return true, err
}
type calculatorProcessorAdd struct {
handler Calculator
}
func (p *calculatorProcessorAdd) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
var _write_err13 thrift.TException
args := CalculatorAddArgs{}
if err2 := args.Read(ctx, iprot); err2 != nil {
iprot.ReadMessageEnd(ctx)
x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err2.Error())
oprot.WriteMessageBegin(ctx, "add", thrift.EXCEPTION, seqId)
x.Write(ctx, oprot)
oprot.WriteMessageEnd(ctx)
oprot.Flush(ctx)
return false, thrift.WrapTException(err2)
}
iprot.ReadMessageEnd(ctx)
tickerCancel := func() {}
// Start a goroutine to do server side connectivity check.
if thrift.ServerConnectivityCheckInterval > 0 {
var cancel context.CancelCauseFunc
ctx, cancel = context.WithCancelCause(ctx)
defer cancel(nil)
var tickerCtx context.Context
tickerCtx, tickerCancel = context.WithCancel(context.Background())
defer tickerCancel()
go func(ctx context.Context, cancel context.CancelCauseFunc) {
ticker := time.NewTicker(thrift.ServerConnectivityCheckInterval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
if !iprot.Transport().IsOpen() {
cancel(thrift.ErrAbandonRequest)
return
}
}
}
}(tickerCtx, cancel)
}
result := CalculatorAddResult{}
if retval, err2 := p.handler.Add(ctx, args.Num1, args.Num2); err2 != nil {
tickerCancel()
err = thrift.WrapTException(err2)
if errors.Is(err2, thrift.ErrAbandonRequest) {
return false, &thrift.ProcessorError{
WriteError: thrift.WrapTException(err2),
EndpointError: err,
}
}
if errors.Is(err2, context.Canceled) {
if err3 := context.Cause(ctx); errors.Is(err3, thrift.ErrAbandonRequest) {
return false, &thrift.ProcessorError{
WriteError: thrift.WrapTException(err3),
EndpointError: err,
}
}
}
_exc14 := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing add: " + err2.Error())
if err2 := oprot.WriteMessageBegin(ctx, "add", thrift.EXCEPTION, seqId); err2 != nil {
_write_err13 = thrift.WrapTException(err2)
}
if err2 := _exc14.Write(ctx, oprot); _write_err13 == nil && err2 != nil {
_write_err13 = thrift.WrapTException(err2)
}
if err2 := oprot.WriteMessageEnd(ctx); _write_err13 == nil && err2 != nil {
_write_err13 = thrift.WrapTException(err2)
}
if err2 := oprot.Flush(ctx); _write_err13 == nil && err2 != nil {
_write_err13 = thrift.WrapTException(err2)
}
if _write_err13 != nil {
return false, &thrift.ProcessorError{
WriteError: _write_err13,
EndpointError: err,
}
}
return true, err
} else {
result.Success = &retval
}
tickerCancel()
if err2 := oprot.WriteMessageBegin(ctx, "add", thrift.REPLY, seqId); err2 != nil {
_write_err13 = thrift.WrapTException(err2)
}
if err2 := result.Write(ctx, oprot); _write_err13 == nil && err2 != nil {
_write_err13 = thrift.WrapTException(err2)
}
if err2 := oprot.WriteMessageEnd(ctx); _write_err13 == nil && err2 != nil {
_write_err13 = thrift.WrapTException(err2)
}
if err2 := oprot.Flush(ctx); _write_err13 == nil && err2 != nil {
_write_err13 = thrift.WrapTException(err2)
}
if _write_err13 != nil {
return false, &thrift.ProcessorError{
WriteError: _write_err13,
EndpointError: err,
}
}
return true, err
}
type calculatorProcessorCalculate struct {
handler Calculator
}
func (p *calculatorProcessorCalculate) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
var _write_err15 thrift.TException
args := CalculatorCalculateArgs{}
if err2 := args.Read(ctx, iprot); err2 != nil {
iprot.ReadMessageEnd(ctx)
x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err2.Error())
oprot.WriteMessageBegin(ctx, "calculate", thrift.EXCEPTION, seqId)
x.Write(ctx, oprot)
oprot.WriteMessageEnd(ctx)
oprot.Flush(ctx)
return false, thrift.WrapTException(err2)
}
iprot.ReadMessageEnd(ctx)
tickerCancel := func() {}
// Start a goroutine to do server side connectivity check.
if thrift.ServerConnectivityCheckInterval > 0 {
var cancel context.CancelCauseFunc
ctx, cancel = context.WithCancelCause(ctx)
defer cancel(nil)
var tickerCtx context.Context
tickerCtx, tickerCancel = context.WithCancel(context.Background())
defer tickerCancel()
go func(ctx context.Context, cancel context.CancelCauseFunc) {
ticker := time.NewTicker(thrift.ServerConnectivityCheckInterval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
if !iprot.Transport().IsOpen() {
cancel(thrift.ErrAbandonRequest)
return
}
}
}
}(tickerCtx, cancel)
}
result := CalculatorCalculateResult{}
if retval, err2 := p.handler.Calculate(ctx, args.Logid, args.W); err2 != nil {
tickerCancel()
err = thrift.WrapTException(err2)
switch v := err2.(type) {
case *InvalidOperation:
result.Ouch = v
default:
if errors.Is(err2, thrift.ErrAbandonRequest) {
return false, &thrift.ProcessorError{
WriteError: thrift.WrapTException(err2),
EndpointError: err,
}
}
if errors.Is(err2, context.Canceled) {
if err3 := context.Cause(ctx); errors.Is(err3, thrift.ErrAbandonRequest) {
return false, &thrift.ProcessorError{
WriteError: thrift.WrapTException(err3),
EndpointError: err,
}
}
}
_exc16 := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing calculate: " + err2.Error())
if err2 := oprot.WriteMessageBegin(ctx, "calculate", thrift.EXCEPTION, seqId); err2 != nil {
_write_err15 = thrift.WrapTException(err2)
}
if err2 := _exc16.Write(ctx, oprot); _write_err15 == nil && err2 != nil {
_write_err15 = thrift.WrapTException(err2)
}
if err2 := oprot.WriteMessageEnd(ctx); _write_err15 == nil && err2 != nil {
_write_err15 = thrift.WrapTException(err2)
}
if err2 := oprot.Flush(ctx); _write_err15 == nil && err2 != nil {
_write_err15 = thrift.WrapTException(err2)
}
if _write_err15 != nil {
return false, &thrift.ProcessorError{
WriteError: _write_err15,
EndpointError: err,
}
}
return true, err
}
} else {
result.Success = &retval
}
tickerCancel()
if err2 := oprot.WriteMessageBegin(ctx, "calculate", thrift.REPLY, seqId); err2 != nil {
_write_err15 = thrift.WrapTException(err2)
}
if err2 := result.Write(ctx, oprot); _write_err15 == nil && err2 != nil {
_write_err15 = thrift.WrapTException(err2)
}
if err2 := oprot.WriteMessageEnd(ctx); _write_err15 == nil && err2 != nil {
_write_err15 = thrift.WrapTException(err2)
}
if err2 := oprot.Flush(ctx); _write_err15 == nil && err2 != nil {
_write_err15 = thrift.WrapTException(err2)
}
if _write_err15 != nil {
return false, &thrift.ProcessorError{
WriteError: _write_err15,
EndpointError: err,
}
}
return true, err
}
type calculatorProcessorZip struct {
handler Calculator
}
func (p *calculatorProcessorZip) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
args := CalculatorZipArgs{}
if err2 := args.Read(ctx, iprot); err2 != nil {
iprot.ReadMessageEnd(ctx)
return false, thrift.WrapTException(err2)
}
iprot.ReadMessageEnd(ctx)
tickerCancel := func() {}
_ = tickerCancel
if err2 := p.handler.Zip(ctx); err2 != nil {
tickerCancel()
err = thrift.WrapTException(err2)
}
tickerCancel()
return true, err
}
// HELPER FUNCTIONS AND STRUCTURES
type CalculatorPingArgs struct {
}
func NewCalculatorPingArgs() *CalculatorPingArgs {
return &CalculatorPingArgs{}
}
func (p *CalculatorPingArgs) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *CalculatorPingArgs) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "ping_args"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *CalculatorPingArgs) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("CalculatorPingArgs(%+v)", *p)
}
func (p *CalculatorPingArgs) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*tutorial.CalculatorPingArgs",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*CalculatorPingArgs)(nil)
type CalculatorPingResult struct {
}
func NewCalculatorPingResult() *CalculatorPingResult {
return &CalculatorPingResult{}
}
func (p *CalculatorPingResult) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *CalculatorPingResult) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "ping_result"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *CalculatorPingResult) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("CalculatorPingResult(%+v)", *p)
}
func (p *CalculatorPingResult) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*tutorial.CalculatorPingResult",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*CalculatorPingResult)(nil)
// Attributes:
// - Num1
// - Num2
//
type CalculatorAddArgs struct {
Num1 int32 `thrift:"num1,1" db:"num1" json:"num1"`
Num2 int32 `thrift:"num2,2" db:"num2" json:"num2"`
}
func NewCalculatorAddArgs() *CalculatorAddArgs {
return &CalculatorAddArgs{}
}
func (p *CalculatorAddArgs) GetNum1() int32 {
return p.Num1
}
func (p *CalculatorAddArgs) GetNum2() int32 {
return p.Num2
}
func (p *CalculatorAddArgs) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 1:
if fieldTypeId == thrift.I32 {
if err := p.ReadField1(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 2:
if fieldTypeId == thrift.I32 {
if err := p.ReadField2(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *CalculatorAddArgs) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 1: ", err)
} else {
p.Num1 = v
}
return nil
}
func (p *CalculatorAddArgs) ReadField2(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 2: ", err)
} else {
p.Num2 = v
}
return nil
}
func (p *CalculatorAddArgs) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "add_args"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField1(ctx, oprot); err != nil { return err }
if err := p.writeField2(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *CalculatorAddArgs) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "num1", thrift.I32, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:num1: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.Num1)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.num1 (1) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:num1: ", p), err)
}
return err
}
func (p *CalculatorAddArgs) writeField2(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "num2", thrift.I32, 2); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:num2: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.Num2)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.num2 (2) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 2:num2: ", p), err)
}
return err
}
func (p *CalculatorAddArgs) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("CalculatorAddArgs(%+v)", *p)
}
func (p *CalculatorAddArgs) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*tutorial.CalculatorAddArgs",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*CalculatorAddArgs)(nil)
// Attributes:
// - Success
//
type CalculatorAddResult struct {
Success *int32 `thrift:"success,0" db:"success" json:"success,omitempty"`
}
func NewCalculatorAddResult() *CalculatorAddResult {
return &CalculatorAddResult{}
}
var CalculatorAddResult_Success_DEFAULT int32
func (p *CalculatorAddResult) GetSuccess() int32 {
if !p.IsSetSuccess() {
return CalculatorAddResult_Success_DEFAULT
}
return *p.Success
}
func (p *CalculatorAddResult) IsSetSuccess() bool {
return p.Success != nil
}
func (p *CalculatorAddResult) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 0:
if fieldTypeId == thrift.I32 {
if err := p.ReadField0(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *CalculatorAddResult) ReadField0(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 0: ", err)
} else {
p.Success = &v
}
return nil
}
func (p *CalculatorAddResult) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "add_result"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField0(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *CalculatorAddResult) writeField0(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetSuccess() {
if err := oprot.WriteFieldBegin(ctx, "success", thrift.I32, 0); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(*p.Success)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.success (0) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err)
}
}
return err
}
func (p *CalculatorAddResult) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("CalculatorAddResult(%+v)", *p)
}
func (p *CalculatorAddResult) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*tutorial.CalculatorAddResult",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*CalculatorAddResult)(nil)
// Attributes:
// - Logid
// - W
//
type CalculatorCalculateArgs struct {
Logid int32 `thrift:"logid,1" db:"logid" json:"logid"`
W *Work `thrift:"w,2" db:"w" json:"w"`
}
func NewCalculatorCalculateArgs() *CalculatorCalculateArgs {
return &CalculatorCalculateArgs{}
}
func (p *CalculatorCalculateArgs) GetLogid() int32 {
return p.Logid
}
var CalculatorCalculateArgs_W_DEFAULT *Work
func (p *CalculatorCalculateArgs) GetW() *Work {
if !p.IsSetW() {
return CalculatorCalculateArgs_W_DEFAULT
}
return p.W
}
func (p *CalculatorCalculateArgs) IsSetW() bool {
return p.W != nil
}
func (p *CalculatorCalculateArgs) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 1:
if fieldTypeId == thrift.I32 {
if err := p.ReadField1(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 2:
if fieldTypeId == thrift.STRUCT {
if err := p.ReadField2(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *CalculatorCalculateArgs) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 1: ", err)
} else {
p.Logid = v
}
return nil
}
func (p *CalculatorCalculateArgs) ReadField2(ctx context.Context, iprot thrift.TProtocol) error {
p.W = &Work{}
if err := p.W.Read(ctx, iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.W), err)
}
return nil
}
func (p *CalculatorCalculateArgs) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "calculate_args"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField1(ctx, oprot); err != nil { return err }
if err := p.writeField2(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *CalculatorCalculateArgs) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "logid", thrift.I32, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:logid: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(p.Logid)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.logid (1) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:logid: ", p), err)
}
return err
}
func (p *CalculatorCalculateArgs) writeField2(ctx context.Context, oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin(ctx, "w", thrift.STRUCT, 2); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:w: ", p), err)
}
if err := p.W.Write(ctx, oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.W), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 2:w: ", p), err)
}
return err
}
func (p *CalculatorCalculateArgs) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("CalculatorCalculateArgs(%+v)", *p)
}
func (p *CalculatorCalculateArgs) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*tutorial.CalculatorCalculateArgs",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*CalculatorCalculateArgs)(nil)
// Attributes:
// - Success
// - Ouch
//
type CalculatorCalculateResult struct {
Success *int32 `thrift:"success,0" db:"success" json:"success,omitempty"`
Ouch *InvalidOperation `thrift:"ouch,1" db:"ouch" json:"ouch,omitempty"`
}
func NewCalculatorCalculateResult() *CalculatorCalculateResult {
return &CalculatorCalculateResult{}
}
var CalculatorCalculateResult_Success_DEFAULT int32
func (p *CalculatorCalculateResult) GetSuccess() int32 {
if !p.IsSetSuccess() {
return CalculatorCalculateResult_Success_DEFAULT
}
return *p.Success
}
var CalculatorCalculateResult_Ouch_DEFAULT *InvalidOperation
func (p *CalculatorCalculateResult) GetOuch() *InvalidOperation {
if !p.IsSetOuch() {
return CalculatorCalculateResult_Ouch_DEFAULT
}
return p.Ouch
}
func (p *CalculatorCalculateResult) IsSetSuccess() bool {
return p.Success != nil
}
func (p *CalculatorCalculateResult) IsSetOuch() bool {
return p.Ouch != nil
}
func (p *CalculatorCalculateResult) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 0:
if fieldTypeId == thrift.I32 {
if err := p.ReadField0(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
case 1:
if fieldTypeId == thrift.STRUCT {
if err := p.ReadField1(ctx, iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *CalculatorCalculateResult) ReadField0(ctx context.Context, iprot thrift.TProtocol) error {
if v, err := iprot.ReadI32(ctx); err != nil {
return thrift.PrependError("error reading field 0: ", err)
} else {
p.Success = &v
}
return nil
}
func (p *CalculatorCalculateResult) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
p.Ouch = &InvalidOperation{}
if err := p.Ouch.Read(ctx, iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Ouch), err)
}
return nil
}
func (p *CalculatorCalculateResult) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "calculate_result"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField0(ctx, oprot); err != nil { return err }
if err := p.writeField1(ctx, oprot); err != nil { return err }
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *CalculatorCalculateResult) writeField0(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetSuccess() {
if err := oprot.WriteFieldBegin(ctx, "success", thrift.I32, 0); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 0:success: ", p), err)
}
if err := oprot.WriteI32(ctx, int32(*p.Success)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T.success (0) field write error: ", p), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err)
}
}
return err
}
func (p *CalculatorCalculateResult) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
if p.IsSetOuch() {
if err := oprot.WriteFieldBegin(ctx, "ouch", thrift.STRUCT, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:ouch: ", p), err)
}
if err := p.Ouch.Write(ctx, oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Ouch), err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:ouch: ", p), err)
}
}
return err
}
func (p *CalculatorCalculateResult) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("CalculatorCalculateResult(%+v)", *p)
}
func (p *CalculatorCalculateResult) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*tutorial.CalculatorCalculateResult",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*CalculatorCalculateResult)(nil)
type CalculatorZipArgs struct {
}
func NewCalculatorZipArgs() *CalculatorZipArgs {
return &CalculatorZipArgs{}
}
func (p *CalculatorZipArgs) Read(ctx context.Context, iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
if err != nil {
return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
}
if fieldTypeId == thrift.STOP {
break
}
if err := iprot.Skip(ctx, fieldTypeId); err != nil {
return err
}
if err := iprot.ReadFieldEnd(ctx); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(ctx); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *CalculatorZipArgs) Write(ctx context.Context, oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin(ctx, "zip_args"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
}
if err := oprot.WriteFieldStop(ctx); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(ctx); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *CalculatorZipArgs) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("CalculatorZipArgs(%+v)", *p)
}
func (p *CalculatorZipArgs) LogValue() slog.Value {
if p == nil {
return slog.AnyValue(nil)
}
v := thrift.SlogTStructWrapper{
Type: "*tutorial.CalculatorZipArgs",
Value: p,
}
return slog.AnyValue(v)
}
var _ slog.LogValuer = (*CalculatorZipArgs)(nil)