Skip to content

Instantly share code, notes, and snippets.

@captncraig
Last active August 29, 2015 14:13
Show Gist options
  • Save captncraig/e2bc7e7d1a0cb2c8127b to your computer and use it in GitHub Desktop.
Save captncraig/e2bc7e7d1a0cb2c8127b to your computer and use it in GitHub Desktop.
Thrift Go Generator Changes
type BarServiceProcessor struct {
*FooServiceProcessor
handler BarService
}
func (p *BarServiceProcessor) runProcessorFunction(key string, seqId int32, iprot, oprot thrift.TProtocol) (found, ok bool, err thrift.TException) {
switch key {
case "ping":
ok, err = p.Process_Ping(seqId, iprot, oprot)
return true, ok, err
default:
return p.FooServiceProcessor.runProcessorFunction(key, seqId, iprot, oprot)
}
}
func NewBarServiceProcessor(handler BarService) *BarServiceProcessor {
return &BarServiceProcessor{NewFooServiceProcessor(handler), handler}
}
func (p *BarServiceProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
name, _, seqId, err := iprot.ReadMessageBegin()
if err != nil {
return false, err
}
if found, ok, err := p.runProcessorFunction(name, seqId, iprot, oprot); found {
return ok, err
}
//same not found stuff
}
func (p *BarServiceProcessor) Process_Ping(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
//...
}
type BarServiceProcessor struct {
*FooServiceProcessor
}
func NewBarServiceProcessor(handler BarService) *BarServiceProcessor {
self7 := &BarServiceProcessor{NewFooServiceProcessor(handler)}
self7.AddToProcessorMap("ping", &barServiceProcessorPing{handler: handler})
return self7
}
type barServiceProcessorPing struct {
handler BarService
}
func (p *barServiceProcessorPing) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
//Body Unaffected
}
namespace * foo
service FooService{
i32 add1(1: i32 x)
}
service BarService extends FooService{
void ping()
}
type FooServiceProcessor struct {
handler FooService
}
func (p *FooServiceProcessor) runProcessorFunction(key string, seqId int32, iprot, oprot thrift.TProtocol) (found, ok bool, err thrift.TException) {
switch key {
case "add1":
ok, err = p.Process_Add1(seqId, iprot, oprot)
return true, ok, err
default:
return false, false, nil
}
}
func NewFooServiceProcessor(handler FooService) *FooServiceProcessor {
return &FooServiceProcessor{handler: handler}
}
func (p *FooServiceProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
name, _, seqId, err := iprot.ReadMessageBegin()
if err != nil {
return false, err
}
if found, ok, err := p.runProcessorFunction(name, seqId, iprot, oprot); found {
return ok, err
}
//same not found stuff
}
func (p *FooServiceProcessor) Process_Add1(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
//same body...
}
type FooServiceProcessor struct {
processorMap map[string]thrift.TProcessorFunction
handler FooService
}
func (p *FooServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) {
p.processorMap[key] = processor
}
func (p *FooServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) {
processor, ok = p.processorMap[key]
return processor, ok
}
func (p *FooServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction {
return p.processorMap
}
func NewFooServiceProcessor(handler FooService) *FooServiceProcessor {
self2 := &FooServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)}
self2.processorMap["add1"] = &fooServiceProcessorAdd1{handler: handler}
return self2
}
func (p *FooServiceProcessor) 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)
}
//unchanged...
}
type fooServiceProcessorAdd1 struct {
handler FooService
}
func (p *fooServiceProcessorAdd1) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
//Body Unaffected
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment