Last active
August 29, 2015 14:13
-
-
Save captncraig/e2bc7e7d1a0cb2c8127b to your computer and use it in GitHub Desktop.
Revisions
-
Craig Peterson revised this gist
Jan 12, 2015 . 2 changed files with 17 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,12 +3,13 @@ type BarServiceProcessor struct { 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) } } @@ -21,19 +22,12 @@ func (p *BarServiceProcessor) Process(iprot, oprot thrift.TProtocol) (success bo 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) { //... } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,12 +2,13 @@ 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 } } @@ -20,12 +21,12 @@ func (p *FooServiceProcessor) Process(iprot, oprot thrift.TProtocol) (success bo 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... } -
Craig Peterson created this gist
Jan 12, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ type BarServiceProcessor struct { *FooServiceProcessor handler BarService } func (p *BarServiceProcessor) GetProcessorFunction(key string) (processor func(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException), ok bool) { switch key { case "ping": return p.Process_Ping, true default: return p.FooServiceProcessor.GetProcessorFunction(key) } } 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 processor, ok := p.GetProcessorFunction(name); ok { return processor(seqId, iprot, oprot) } iprot.Skip(thrift.STRUCT) iprot.ReadMessageEnd() x8 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) x8.Write(oprot) oprot.WriteMessageEnd() oprot.Flush() return false, x8 } func (p *BarServiceProcessor) Process_Ping(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { //... } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ 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 } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ type FooServiceProcessor struct { handler FooService } func (p *FooServiceProcessor) GetProcessorFunction(key string) (processor func(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException), ok bool) { switch key { case "add1": return p.Process_Add1, true default: return nil, false } } 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 processor, ok := p.GetProcessorFunction(name); ok { return processor(seqId, iprot, oprot) } //unchanged... } func (p *FooServiceProcessor) Process_Add1(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { //Body Unaffected } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ 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 } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ namespace * foo service FooService{ i32 add1(1: i32 x) } service BarService extends FooService{ void ping() }