// Autogenerated by Thrift Compiler (0.9.2)
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
package add
import (
"bytes"
"fmt"
"github.com/apache/thrift/lib/go/thrift"
)
// (needed to ensure safety because of naive import list construction.)
var _ = thrift.ZERO
var _ = fmt.Printf
var _ = bytes.Equal
type AddService interface {
// Parameters:
// - A
// - B
Sum(a int64, b int64) (r *SumReply, err error)
// Parameters:
// - A
// - B
Concat(a string, b string) (r *ConcatReply, err error)
}
type AddServiceClient struct {
Transport thrift.TTransport
ProtocolFactory thrift.TProtocolFactory
InputProtocol thrift.TProtocol
OutputProtocol thrift.TProtocol
SeqId int32
}
func NewAddServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *AddServiceClient {
return &AddServiceClient{Transport: t,
ProtocolFactory: f,
InputProtocol: f.GetProtocol(t),
OutputProtocol: f.GetProtocol(t),
SeqId: 0,
}
}
func NewAddServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *AddServiceClient {
return &AddServiceClient{Transport: t,
ProtocolFactory: nil,
InputProtocol: iprot,
OutputProtocol: oprot,
SeqId: 0,
}
}
// Parameters:
// - A
// - B
func (p *AddServiceClient) Sum(a int64, b int64) (r *SumReply, err error) {
if err = p.sendSum(a, b); err != nil {
return
}
return p.recvSum()
}
func (p *AddServiceClient) sendSum(a int64, b int64) (err error) {
oprot := p.OutputProtocol
if oprot == nil {
oprot = p.ProtocolFactory.GetProtocol(p.Transport)
p.OutputProtocol = oprot
}
p.SeqId++
if err = oprot.WriteMessageBegin("Sum", thrift.CALL, p.SeqId); err != nil {
return
}
args := SumArgs{
A: a,
B: b,
}
if err = args.Write(oprot); err != nil {
return
}
if err = oprot.WriteMessageEnd(); err != nil {
return
}
return oprot.Flush()
}
func (p *AddServiceClient) recvSum() (value *SumReply, err error) {
iprot := p.InputProtocol
if iprot == nil {
iprot = p.ProtocolFactory.GetProtocol(p.Transport)
p.InputProtocol = iprot
}
_, mTypeId, seqId, err := iprot.ReadMessageBegin()
if err != nil {
return
}
if mTypeId == thrift.EXCEPTION {
error0 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception")
var error1 error
error1, err = error0.Read(iprot)
if err != nil {
return
}
if err = iprot.ReadMessageEnd(); err != nil {
return
}
err = error1
return
}
if p.SeqId != seqId {
err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "Sum failed: out of sequence response")
return
}
result := SumResult{}
if err = result.Read(iprot); err != nil {
return
}
if err = iprot.ReadMessageEnd(); err != nil {
return
}
value = result.GetSuccess()
return
}
// Parameters:
// - A
// - B
func (p *AddServiceClient) Concat(a string, b string) (r *ConcatReply, err error) {
if err = p.sendConcat(a, b); err != nil {
return
}
return p.recvConcat()
}
func (p *AddServiceClient) sendConcat(a string, b string) (err error) {
oprot := p.OutputProtocol
if oprot == nil {
oprot = p.ProtocolFactory.GetProtocol(p.Transport)
p.OutputProtocol = oprot
}
p.SeqId++
if err = oprot.WriteMessageBegin("Concat", thrift.CALL, p.SeqId); err != nil {
return
}
args := ConcatArgs{
A: a,
B: b,
}
if err = args.Write(oprot); err != nil {
return
}
if err = oprot.WriteMessageEnd(); err != nil {
return
}
return oprot.Flush()
}
func (p *AddServiceClient) recvConcat() (value *ConcatReply, err error) {
iprot := p.InputProtocol
if iprot == nil {
iprot = p.ProtocolFactory.GetProtocol(p.Transport)
p.InputProtocol = iprot
}
_, mTypeId, seqId, err := iprot.ReadMessageBegin()
if err != nil {
return
}
if mTypeId == thrift.EXCEPTION {
error2 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception")
var error3 error
error3, err = error2.Read(iprot)
if err != nil {
return
}
if err = iprot.ReadMessageEnd(); err != nil {
return
}
err = error3
return
}
if p.SeqId != seqId {
err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "Concat failed: out of sequence response")
return
}
result := ConcatResult{}
if err = result.Read(iprot); err != nil {
return
}
if err = iprot.ReadMessageEnd(); err != nil {
return
}
value = result.GetSuccess()
return
}
type AddServiceProcessor struct {
processorMap map[string]thrift.TProcessorFunction
handler AddService
}
func (p *AddServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) {
p.processorMap[key] = processor
}
func (p *AddServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) {
processor, ok = p.processorMap[key]
return processor, ok
}
func (p *AddServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction {
return p.processorMap
}
func NewAddServiceProcessor(handler AddService) *AddServiceProcessor {
self4 := &AddServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)}
self4.processorMap["Sum"] = &addServiceProcessorSum{handler: handler}
self4.processorMap["Concat"] = &addServiceProcessorConcat{handler: handler}
return self4
}
func (p *AddServiceProcessor) Process(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(seqId, iprot, oprot)
}
iprot.Skip(thrift.STRUCT)
iprot.ReadMessageEnd()
x5 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name)
oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId)
x5.Write(oprot)
oprot.WriteMessageEnd()
oprot.Flush()
return false, x5
}
type addServiceProcessorSum struct {
handler AddService
}
func (p *addServiceProcessorSum) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
args := SumArgs{}
if err = args.Read(iprot); err != nil {
iprot.ReadMessageEnd()
x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error())
oprot.WriteMessageBegin("Sum", thrift.EXCEPTION, seqId)
x.Write(oprot)
oprot.WriteMessageEnd()
oprot.Flush()
return false, err
}
iprot.ReadMessageEnd()
result := SumResult{}
var retval *SumReply
var err2 error
if retval, err2 = p.handler.Sum(args.A, args.B); err2 != nil {
x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Sum: "+err2.Error())
oprot.WriteMessageBegin("Sum", thrift.EXCEPTION, seqId)
x.Write(oprot)
oprot.WriteMessageEnd()
oprot.Flush()
return true, err2
} else {
result.Success = retval
}
if err2 = oprot.WriteMessageBegin("Sum", 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(); err == nil && err2 != nil {
err = err2
}
if err != nil {
return
}
return true, err
}
type addServiceProcessorConcat struct {
handler AddService
}
func (p *addServiceProcessorConcat) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
args := ConcatArgs{}
if err = args.Read(iprot); err != nil {
iprot.ReadMessageEnd()
x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error())
oprot.WriteMessageBegin("Concat", thrift.EXCEPTION, seqId)
x.Write(oprot)
oprot.WriteMessageEnd()
oprot.Flush()
return false, err
}
iprot.ReadMessageEnd()
result := ConcatResult{}
var retval *ConcatReply
var err2 error
if retval, err2 = p.handler.Concat(args.A, args.B); err2 != nil {
x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Concat: "+err2.Error())
oprot.WriteMessageBegin("Concat", thrift.EXCEPTION, seqId)
x.Write(oprot)
oprot.WriteMessageEnd()
oprot.Flush()
return true, err2
} else {
result.Success = retval
}
if err2 = oprot.WriteMessageBegin("Concat", 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(); err == nil && err2 != nil {
err = err2
}
if err != nil {
return
}
return true, err
}
// HELPER FUNCTIONS AND STRUCTURES
type SumArgs struct {
A int64 `thrift:"a,1" json:"a"`
B int64 `thrift:"b,2" json:"b"`
}
func NewSumArgs() *SumArgs {
return &SumArgs{}
}
func (p *SumArgs) GetA() int64 {
return p.A
}
func (p *SumArgs) GetB() int64 {
return p.B
}
func (p *SumArgs) Read(iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(); err != nil {
return fmt.Errorf("%T read error: %s", p, err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
if err != nil {
return fmt.Errorf("%T field %d read error: %s", p, fieldId, err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 1:
if err := p.ReadField1(iprot); err != nil {
return err
}
case 2:
if err := p.ReadField2(iprot); 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 fmt.Errorf("%T read struct end error: %s", p, err)
}
return nil
}
func (p *SumArgs) ReadField1(iprot thrift.TProtocol) error {
if v, err := iprot.ReadI64(); err != nil {
return fmt.Errorf("error reading field 1: %s", err)
} else {
p.A = v
}
return nil
}
func (p *SumArgs) ReadField2(iprot thrift.TProtocol) error {
if v, err := iprot.ReadI64(); err != nil {
return fmt.Errorf("error reading field 2: %s", err)
} else {
p.B = v
}
return nil
}
func (p *SumArgs) Write(oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin("Sum_args"); err != nil {
return fmt.Errorf("%T write struct begin error: %s", p, err)
}
if err := p.writeField1(oprot); err != nil {
return err
}
if err := p.writeField2(oprot); err != nil {
return err
}
if err := oprot.WriteFieldStop(); err != nil {
return fmt.Errorf("write field stop error: %s", err)
}
if err := oprot.WriteStructEnd(); err != nil {
return fmt.Errorf("write struct stop error: %s", err)
}
return nil
}
func (p *SumArgs) writeField1(oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin("a", thrift.I64, 1); err != nil {
return fmt.Errorf("%T write field begin error 1:a: %s", p, err)
}
if err := oprot.WriteI64(int64(p.A)); err != nil {
return fmt.Errorf("%T.a (1) field write error: %s", p, err)
}
if err := oprot.WriteFieldEnd(); err != nil {
return fmt.Errorf("%T write field end error 1:a: %s", p, err)
}
return err
}
func (p *SumArgs) writeField2(oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin("b", thrift.I64, 2); err != nil {
return fmt.Errorf("%T write field begin error 2:b: %s", p, err)
}
if err := oprot.WriteI64(int64(p.B)); err != nil {
return fmt.Errorf("%T.b (2) field write error: %s", p, err)
}
if err := oprot.WriteFieldEnd(); err != nil {
return fmt.Errorf("%T write field end error 2:b: %s", p, err)
}
return err
}
func (p *SumArgs) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("SumArgs(%+v)", *p)
}
type SumResult struct {
Success *SumReply `thrift:"success,0" json:"success"`
}
func NewSumResult() *SumResult {
return &SumResult{}
}
var SumResult_Success_DEFAULT *SumReply
func (p *SumResult) GetSuccess() *SumReply {
if !p.IsSetSuccess() {
return SumResult_Success_DEFAULT
}
return p.Success
}
func (p *SumResult) IsSetSuccess() bool {
return p.Success != nil
}
func (p *SumResult) Read(iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(); err != nil {
return fmt.Errorf("%T read error: %s", p, err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
if err != nil {
return fmt.Errorf("%T field %d read error: %s", p, fieldId, err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 0:
if err := p.ReadField0(iprot); 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 fmt.Errorf("%T read struct end error: %s", p, err)
}
return nil
}
func (p *SumResult) ReadField0(iprot thrift.TProtocol) error {
p.Success = &SumReply{}
if err := p.Success.Read(iprot); err != nil {
return fmt.Errorf("%T error reading struct: %s", p.Success, err)
}
return nil
}
func (p *SumResult) Write(oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin("Sum_result"); err != nil {
return fmt.Errorf("%T write struct begin error: %s", p, err)
}
if err := p.writeField0(oprot); err != nil {
return err
}
if err := oprot.WriteFieldStop(); err != nil {
return fmt.Errorf("write field stop error: %s", err)
}
if err := oprot.WriteStructEnd(); err != nil {
return fmt.Errorf("write struct stop error: %s", err)
}
return nil
}
func (p *SumResult) writeField0(oprot thrift.TProtocol) (err error) {
if p.IsSetSuccess() {
if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil {
return fmt.Errorf("%T write field begin error 0:success: %s", p, err)
}
if err := p.Success.Write(oprot); err != nil {
return fmt.Errorf("%T error writing struct: %s", p.Success, err)
}
if err := oprot.WriteFieldEnd(); err != nil {
return fmt.Errorf("%T write field end error 0:success: %s", p, err)
}
}
return err
}
func (p *SumResult) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("SumResult(%+v)", *p)
}
type ConcatArgs struct {
A string `thrift:"a,1" json:"a"`
B string `thrift:"b,2" json:"b"`
}
func NewConcatArgs() *ConcatArgs {
return &ConcatArgs{}
}
func (p *ConcatArgs) GetA() string {
return p.A
}
func (p *ConcatArgs) GetB() string {
return p.B
}
func (p *ConcatArgs) Read(iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(); err != nil {
return fmt.Errorf("%T read error: %s", p, err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
if err != nil {
return fmt.Errorf("%T field %d read error: %s", p, fieldId, err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 1:
if err := p.ReadField1(iprot); err != nil {
return err
}
case 2:
if err := p.ReadField2(iprot); 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 fmt.Errorf("%T read struct end error: %s", p, err)
}
return nil
}
func (p *ConcatArgs) ReadField1(iprot thrift.TProtocol) error {
if v, err := iprot.ReadString(); err != nil {
return fmt.Errorf("error reading field 1: %s", err)
} else {
p.A = v
}
return nil
}
func (p *ConcatArgs) ReadField2(iprot thrift.TProtocol) error {
if v, err := iprot.ReadString(); err != nil {
return fmt.Errorf("error reading field 2: %s", err)
} else {
p.B = v
}
return nil
}
func (p *ConcatArgs) Write(oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin("Concat_args"); err != nil {
return fmt.Errorf("%T write struct begin error: %s", p, err)
}
if err := p.writeField1(oprot); err != nil {
return err
}
if err := p.writeField2(oprot); err != nil {
return err
}
if err := oprot.WriteFieldStop(); err != nil {
return fmt.Errorf("write field stop error: %s", err)
}
if err := oprot.WriteStructEnd(); err != nil {
return fmt.Errorf("write struct stop error: %s", err)
}
return nil
}
func (p *ConcatArgs) writeField1(oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin("a", thrift.STRING, 1); err != nil {
return fmt.Errorf("%T write field begin error 1:a: %s", p, err)
}
if err := oprot.WriteString(string(p.A)); err != nil {
return fmt.Errorf("%T.a (1) field write error: %s", p, err)
}
if err := oprot.WriteFieldEnd(); err != nil {
return fmt.Errorf("%T write field end error 1:a: %s", p, err)
}
return err
}
func (p *ConcatArgs) writeField2(oprot thrift.TProtocol) (err error) {
if err := oprot.WriteFieldBegin("b", thrift.STRING, 2); err != nil {
return fmt.Errorf("%T write field begin error 2:b: %s", p, err)
}
if err := oprot.WriteString(string(p.B)); err != nil {
return fmt.Errorf("%T.b (2) field write error: %s", p, err)
}
if err := oprot.WriteFieldEnd(); err != nil {
return fmt.Errorf("%T write field end error 2:b: %s", p, err)
}
return err
}
func (p *ConcatArgs) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("ConcatArgs(%+v)", *p)
}
type ConcatResult struct {
Success *ConcatReply `thrift:"success,0" json:"success"`
}
func NewConcatResult() *ConcatResult {
return &ConcatResult{}
}
var ConcatResult_Success_DEFAULT *ConcatReply
func (p *ConcatResult) GetSuccess() *ConcatReply {
if !p.IsSetSuccess() {
return ConcatResult_Success_DEFAULT
}
return p.Success
}
func (p *ConcatResult) IsSetSuccess() bool {
return p.Success != nil
}
func (p *ConcatResult) Read(iprot thrift.TProtocol) error {
if _, err := iprot.ReadStructBegin(); err != nil {
return fmt.Errorf("%T read error: %s", p, err)
}
for {
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
if err != nil {
return fmt.Errorf("%T field %d read error: %s", p, fieldId, err)
}
if fieldTypeId == thrift.STOP {
break
}
switch fieldId {
case 0:
if err := p.ReadField0(iprot); 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 fmt.Errorf("%T read struct end error: %s", p, err)
}
return nil
}
func (p *ConcatResult) ReadField0(iprot thrift.TProtocol) error {
p.Success = &ConcatReply{}
if err := p.Success.Read(iprot); err != nil {
return fmt.Errorf("%T error reading struct: %s", p.Success, err)
}
return nil
}
func (p *ConcatResult) Write(oprot thrift.TProtocol) error {
if err := oprot.WriteStructBegin("Concat_result"); err != nil {
return fmt.Errorf("%T write struct begin error: %s", p, err)
}
if err := p.writeField0(oprot); err != nil {
return err
}
if err := oprot.WriteFieldStop(); err != nil {
return fmt.Errorf("write field stop error: %s", err)
}
if err := oprot.WriteStructEnd(); err != nil {
return fmt.Errorf("write struct stop error: %s", err)
}
return nil
}
func (p *ConcatResult) writeField0(oprot thrift.TProtocol) (err error) {
if p.IsSetSuccess() {
if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil {
return fmt.Errorf("%T write field begin error 0:success: %s", p, err)
}
if err := p.Success.Write(oprot); err != nil {
return fmt.Errorf("%T error writing struct: %s", p.Success, err)
}
if err := oprot.WriteFieldEnd(); err != nil {
return fmt.Errorf("%T write field end error 0:success: %s", p, err)
}
}
return err
}
func (p *ConcatResult) String() string {
if p == nil {
return "<nil>"
}
return fmt.Sprintf("ConcatResult(%+v)", *p)
}