Skip to content

Instantly share code, notes, and snippets.

@PureWhiteWu

PureWhiteWu/old.go

Created Oct 14, 2020
Embed
What would you like to do?
使用人工智能优化 Golang 编译器 —— 旧生成代码
// Code generated by x. DO NOT EDIT.
package x
import (
"fmt"
"github.com/apache/thrift/lib/go/thrift"
"context"
)
type Example struct {
Data1 [][]int64 `thrift:"data1,1" json:"data1"`
Data2 map[int64][]int8 `thrift:"data2,2" json:"data2"`
Data3 []map[int64]int8 `thrift:"data3,3" json:"data3"`
}
func NewExample() *Example {
return &Example{}
}
func (p *Example) GetData1() [][]int64 {
return p.Data1
}
func (p *Example) SetData1(val [][]int64) {
p.Data1 = val
}
func (p *Example) GetData2() map[int64][]int8 {
return p.Data2
}
func (p *Example) SetData2(val map[int64][]int8) {
p.Data2 = val
}
func (p *Example) GetData3() []map[int64]int8 {
return p.Data3
}
func (p *Example) SetData3(val []map[int64]int8) {
p.Data3 = val
}
func (p *Example) Read(iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
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(iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(fieldTypeId); err != nil {
return err
}
}
case 2:
if fieldTypeId == thrift.MAP {
if err := p.ReadField2(iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(fieldTypeId); err != nil {
return err
}
}
case 3:
if fieldTypeId == thrift.LIST {
if err := p.ReadField3(iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *Example) ReadField1(iprot thrift.TProtocol) (err error) {
var _val1 [][]int64
_, size, err := iprot.ReadListBegin()
if err != nil {
return thrift.PrependError("error reading list begin: ", err)
}
_val1 = make([][]int64, 0, size)
for i := 0; i < size; i++ {
var _val2 []int64
_, size, err := iprot.ReadListBegin()
if err != nil {
return thrift.PrependError("error reading list begin: ", err)
}
_val2 = make([]int64, 0, size)
for i := 0; i < size; i++ {
var _val3 int64
if _val3, err = iprot.ReadI64(); err != nil {
return thrift.PrependError("error reading field 1: ", err)
}
_val2 = append(_val2, _val3)
}
if err := iprot.ReadListEnd(); err != nil {
return thrift.PrependError("error reading list end: ", err)
}
_val1 = append(_val1, _val2)
}
if err := iprot.ReadListEnd(); err != nil {
return thrift.PrependError("error reading list end: ", err)
}
p.Data1 = _val1
return nil
}
func (p *Example) ReadField2(iprot thrift.TProtocol) (err error) {
var _val1 map[int64][]int8
_, _, size, err := iprot.ReadMapBegin()
if err != nil {
return thrift.PrependError("error reading map begin: ", err)
}
_val1 = make(map[int64][]int8, size)
for i := 0; i < size; i++ {
var _key2 int64
if _key2, err = iprot.ReadI64(); err != nil {
return thrift.PrependError("error reading field 2: ", err)
}
var _val3 []int8
_, size, err := iprot.ReadListBegin()
if err != nil {
return thrift.PrependError("error reading list begin: ", err)
}
_val3 = make([]int8, 0, size)
for i := 0; i < size; i++ {
var _val4 int8
if _val4, err = iprot.ReadByte(); err != nil {
return thrift.PrependError("error reading field 2: ", err)
}
_val3 = append(_val3, _val4)
}
if err := iprot.ReadListEnd(); err != nil {
return thrift.PrependError("error reading list end: ", err)
}
_val1[_key2] = _val3
}
if err := iprot.ReadMapEnd(); err != nil {
return thrift.PrependError("error reading map end: ", err)
}
p.Data2 = _val1
return nil
}
func (p *Example) ReadField3(iprot thrift.TProtocol) (err error) {
var _val1 []map[int64]int8
_, size, err := iprot.ReadListBegin()
if err != nil {
return thrift.PrependError("error reading list begin: ", err)
}
_val1 = make([]map[int64]int8, 0, size)
for i := 0; i < size; i++ {
var _val2 map[int64]int8
_, _, size, err := iprot.ReadMapBegin()
if err != nil {
return thrift.PrependError("error reading map begin: ", err)
}
_val2 = make(map[int64]int8, size)
for i := 0; i < size; i++ {
var _key3 int64
if _key3, err = iprot.ReadI64(); err != nil {
return thrift.PrependError("error reading field 3: ", err)
}
var _val4 int8
if _val4, err = iprot.ReadByte(); err != nil {
return thrift.PrependError("error reading field 3: ", err)
}
_val2[_key3] = _val4
}
if err := iprot.ReadMapEnd(); err != nil {
return thrift.PrependError("error reading map end: ", err)
}
_val1 = append(_val1, _val2)
}
if err := iprot.ReadListEnd(); err != nil {
return thrift.PrependError("error reading list end: ", err)
}
p.Data3 = _val1
return nil
}
func (p *Example) Write(oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin("Example"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField1(oprot); err != nil {
return err
}
if err := p.writeField2(oprot); err != nil {
return err
}
if err := p.writeField3(oprot); err != nil {
return err
}
}
if err := oprot.WriteFieldStop(); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *Example) writeField1(oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin("data1", thrift.LIST, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:data1: ", p), err)
}
if err := oprot.WriteListBegin(thrift.LIST, len(p.Data1)); err != nil {
return thrift.PrependError("error writing list begin: ", err)
}
for _, v := range p.Data1 {
if err := oprot.WriteListBegin(thrift.I64, len(v)); err != nil {
return thrift.PrependError("error writing list begin: ", err)
}
for _, v := range v {
if err := oprot.WriteI64(int64(v)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
}
}
if err := oprot.WriteListEnd(); err != nil {
return thrift.PrependError("error writing list end: ", err)
}
}
if err := oprot.WriteListEnd(); err != nil {
return thrift.PrependError("error writing list end: ", err)
}
if err := oprot.WriteFieldEnd(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:data1: ", p), err)
}
return err
}
func (p *Example) writeField2(oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin("data2", thrift.MAP, 2); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:data2: ", p), err)
}
if err := oprot.WriteMapBegin(thrift.I64, thrift.LIST, len(p.Data2)); err != nil {
return thrift.PrependError("error writing map begin: ", err)
}
for k, v := range p.Data2 {
if err := oprot.WriteI64(int64(k)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
}
if err := oprot.WriteListBegin(thrift.BYTE, len(v)); err != nil {
return thrift.PrependError("error writing list begin: ", err)
}
for _, v := range v {
if err := oprot.WriteByte(int8(v)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
}
}
if err := oprot.WriteListEnd(); err != nil {
return thrift.PrependError("error writing list end: ", err)
}
}
if err := oprot.WriteMapEnd(); err != nil {
return thrift.PrependError("error writing map end: ", err)
}
if err := oprot.WriteFieldEnd(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 2:data2: ", p), err)
}
return err
}
func (p *Example) writeField3(oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin("data3", thrift.LIST, 3); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:data3: ", p), err)
}
if err := oprot.WriteListBegin(thrift.MAP, len(p.Data3)); err != nil {
return thrift.PrependError("error writing list begin: ", err)
}
for _, v := range p.Data3 {
if err := oprot.WriteMapBegin(thrift.I64, thrift.BYTE, len(v)); err != nil {
return thrift.PrependError("error writing map begin: ", err)
}
for k, v := range v {
if err := oprot.WriteI64(int64(k)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
}
if err := oprot.WriteByte(int8(v)); err != nil {
return thrift.PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
}
}
if err := oprot.WriteMapEnd(); err != nil {
return thrift.PrependError("error writing map end: ", err)
}
}
if err := oprot.WriteListEnd(); err != nil {
return thrift.PrependError("error writing list end: ", err)
}
if err := oprot.WriteFieldEnd(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 3:data3: ", p), err)
}
return err
}
type Serialize interface {
Method(ctx context.Context, req *Example) (r *Example, err error)
}
type SerializeClient struct {
c thrift.TClient
}
func NewSerializeClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *SerializeClient {
return &SerializeClient{
c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)),
}
}
func NewSerializeClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *SerializeClient {
return &SerializeClient{
c: thrift.NewTStandardClient(iprot, oprot),
}
}
func NewSerializeClient(c thrift.TClient) *SerializeClient {
return &SerializeClient{
c: c,
}
}
func (p *SerializeClient) Client_() thrift.TClient {
return p.c
}
func (p *SerializeClient) Method(ctx context.Context, req *Example) (r *Example, err error) {
var _args SerializeMethodArgs
_args.Req = req
var _result SerializeMethodResult
if err = p.Client_().Call(ctx, "Method", &_args, &_result); err != nil {
return
}
return _result.GetSuccess(), nil
}
type SerializeProcessor struct {
processorMap map[string]thrift.TProcessorFunction
handler Serialize
}
func (p *SerializeProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) {
p.processorMap[key] = processor
}
func (p *SerializeProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) {
processor, ok = p.processorMap[key]
return processor, ok
}
func (p *SerializeProcessor) ProcessorMap() map[string]thrift.TProcessorFunction {
return p.processorMap
}
func NewSerializeProcessor(handler Serialize) *SerializeProcessor {
self := &SerializeProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)}
self.AddToProcessorMap("Method", &serializeProcessorMethod{handler: handler})
return self
}
func (p *SerializeProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
name, _, seqId, err := iprot.ReadMessageBegin()
if err != nil {
return false, err
}
if processor, ok := p.GetProcessorFunction(name); ok {
return processor.Process(ctx, seqId, iprot, oprot)
}
iprot.Skip(thrift.STRUCT)
iprot.ReadMessageEnd()
x := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name)
oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId)
x.Write(oprot)
oprot.WriteMessageEnd()
oprot.Flush(ctx)
return false, x
}
type serializeProcessorMethod struct {
handler Serialize
}
func (p *serializeProcessorMethod) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
args := SerializeMethodArgs{}
if err = args.Read(iprot); err != nil {
iprot.ReadMessageEnd()
x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error())
oprot.WriteMessageBegin("Method", thrift.EXCEPTION, seqId)
x.Write(oprot)
oprot.WriteMessageEnd()
oprot.Flush(ctx)
return false, err
}
iprot.ReadMessageEnd()
var err2 error
result := SerializeMethodResult{}
var retval *Example
if retval, err2 = p.handler.Method(ctx, args.Req); err2 != nil {
x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Method: "+err2.Error())
oprot.WriteMessageBegin("Method", thrift.EXCEPTION, seqId)
x.Write(oprot)
oprot.WriteMessageEnd()
oprot.Flush(ctx)
return true, err2
} else {
result.Success = retval
}
if err2 = oprot.WriteMessageBegin("Method", thrift.REPLY, seqId); err2 != nil {
err = err2
}
if err2 = result.Write(oprot); err == nil && err2 != nil {
err = err2
}
if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil {
err = err2
}
if err2 = oprot.Flush(ctx); err == nil && err2 != nil {
err = err2
}
if err != nil {
return
}
return true, err
}
type SerializeMethodArgs struct {
Req *Example `thrift:"req,1" json:"req"`
}
func NewSerializeMethodArgs() *SerializeMethodArgs {
return &SerializeMethodArgs{}
}
var SerializeMethodArgs_Req_DEFAULT *Example
func (p *SerializeMethodArgs) GetReq() *Example {
if !p.IsSetReq() {
return SerializeMethodArgs_Req_DEFAULT
}
return p.Req
}
func (p *SerializeMethodArgs) SetReq(val *Example) {
p.Req = val
}
func (p *SerializeMethodArgs) IsSetReq() bool {
return p.Req != nil
}
func (p *SerializeMethodArgs) Read(iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
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(iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *SerializeMethodArgs) ReadField1(iprot thrift.TProtocol) (err error) {
var _val1 *Example
_val1 = NewExample()
if err := _val1.Read(iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _val1), err)
}
p.Req = _val1
return nil
}
func (p *SerializeMethodArgs) Write(oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin("Method_args"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField1(oprot); err != nil {
return err
}
}
if err := oprot.WriteFieldStop(); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *SerializeMethodArgs) writeField1(oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin("req", thrift.STRUCT, 1); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:req: ", p), err)
}
if err := p.Req.Write(oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Req), err)
}
if err := oprot.WriteFieldEnd(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 1:req: ", p), err)
}
return err
}
func (p *SerializeMethodArgs) GetFirstArgument() interface{} {
return p.Req
}
type SerializeMethodResult struct {
Success *Example `thrift:"success,0" json:"success,omitempty"`
}
func NewSerializeMethodResult() *SerializeMethodResult {
return &SerializeMethodResult{}
}
var SerializeMethodResult_Success_DEFAULT *Example
func (p *SerializeMethodResult) GetSuccess() *Example {
if !p.IsSetSuccess() {
return SerializeMethodResult_Success_DEFAULT
}
return p.Success
}
func (p *SerializeMethodResult) SetSuccess(x interface{}) {
p.Success = x.(*Example)
}
func (p *SerializeMethodResult) IsSetSuccess() bool {
return p.Success != nil
}
func (p *SerializeMethodResult) Read(iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
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(iprot); err != nil {
return err
}
} else {
if err := iprot.Skip(fieldTypeId); err != nil {
return err
}
}
default:
if err := iprot.Skip(fieldTypeId); err != nil {
return err
}
}
if err := iprot.ReadFieldEnd(); err != nil {
return err
}
}
if err := iprot.ReadStructEnd(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
}
return nil
}
func (p *SerializeMethodResult) ReadField0(iprot thrift.TProtocol) (err error) {
var _val1 *Example
_val1 = NewExample()
if err := _val1.Read(iprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _val1), err)
}
p.Success = _val1
return nil
}
func (p *SerializeMethodResult) Write(oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin("Method_result"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
}
if p != nil {
if err := p.writeField0(oprot); err != nil {
return err
}
}
if err := oprot.WriteFieldStop(); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
func (p *SerializeMethodResult) writeField0(oprot thrift.TProtocol) (err error) {
if p.IsSetSuccess() {
if err := oprot.WriteFieldBegin("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(oprot); err != nil {
return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Success), err)
}
if err := oprot.WriteFieldEnd(); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write field end error 0:success: ", p), err)
}
}
return err
}
func (p *SerializeMethodResult) GetResult() interface{} {
return p.Success
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.