Skip to content

Commit

Permalink
Add GetThriftMetadata to thrift.Processor
Browse files Browse the repository at this point in the history
Summary: Add GetThriftMetadata to thrift.Processor

Reviewed By: codyohl, podtserkovskiy

Differential Revision: D64175681

fbshipit-source-id: f9a64d7a6e1e9f2dfef69dafae2283acc37fbff2
  • Loading branch information
awalterschulze authored and facebook-github-bot committed Oct 11, 2024
1 parent dd0d50d commit 7ee3988
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions thrift/lib/go/thrift/header_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/facebook/fbthrift/thrift/lib/go/thrift/types"
"github.com/facebook/fbthrift/thrift/lib/thrift/metadata"
)

type headerServerTestProcessor struct {
Expand All @@ -33,6 +34,10 @@ func (t *headerServerTestProcessor) ProcessorFunctionMap() map[string]types.Proc
return map[string]types.ProcessorFunction{"test": &headerServerTestProcessorFunction{&testProcessorFunction{}, t.requests}}
}

func (t *headerServerTestProcessor) GetThriftMetadata() *metadata.ThriftMetadata {
return nil
}

type headerServerTestProcessorFunction struct {
types.ProcessorFunction
requests chan<- *MyTestStruct
Expand Down
5 changes: 5 additions & 0 deletions thrift/lib/go/thrift/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"

"github.com/facebook/fbthrift/thrift/lib/go/thrift/types"
"github.com/facebook/fbthrift/thrift/lib/thrift/metadata"
)

// Interceptor is a function that runs before the actual method. It is passed
Expand Down Expand Up @@ -60,6 +61,10 @@ func (p *interceptorProcessor) ProcessorFunctionMap() map[string]types.Processor
return mi
}

func (p *interceptorProcessor) GetThriftMetadata() *metadata.ThriftMetadata {
return p.Processor.GetThriftMetadata()
}

type interceptorProcessorFunction struct {
interceptor Interceptor
methodName string
Expand Down
2 changes: 2 additions & 0 deletions thrift/lib/go/thrift/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"

"github.com/facebook/fbthrift/thrift/lib/go/thrift/types"
"github.com/facebook/fbthrift/thrift/lib/thrift/metadata"
)

// Processor exposes access to processor functions which
Expand All @@ -37,6 +38,7 @@ type Processor interface {
// sent which explains that no processor function exists with the specified
// name on this server.
ProcessorFunctionMap() map[string]types.ProcessorFunction
GetThriftMetadata() *metadata.ThriftMetadata
}

func errorType(err error) string {
Expand Down
19 changes: 19 additions & 0 deletions thrift/lib/go/thrift/processor_composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package thrift

import (
"github.com/facebook/fbthrift/thrift/lib/go/thrift/types"
"github.com/facebook/fbthrift/thrift/lib/thrift/metadata"
)

// CompositeProcessor is a serial Processor can report what functions it has
Expand All @@ -31,12 +32,14 @@ type CompositeProcessor interface {
// server as long as their functions carry distinct names
type compositeProcessor struct {
serviceProcessorMap map[string]types.ProcessorFunction
metadata *metadata.ThriftMetadata
}

// NewCompositeProcessor creates a new CompositeProcessor
func NewCompositeProcessor() CompositeProcessor {
return &compositeProcessor{
serviceProcessorMap: make(map[string]types.ProcessorFunction),
metadata: metadata.NewThriftMetadata(),
}
}

Expand All @@ -49,6 +52,18 @@ func (p *compositeProcessor) Include(processor Processor) {
for name, tfunc := range processor.ProcessorFunctionMap() {
p.serviceProcessorMap[name] = tfunc
}
for name, v := range processor.GetThriftMetadata().GetEnums() {
p.metadata.Enums[name] = v
}
for name, v := range processor.GetThriftMetadata().GetStructs() {
p.metadata.Structs[name] = v
}
for name, v := range processor.GetThriftMetadata().GetExceptions() {
p.metadata.Exceptions[name] = v
}
for name, v := range processor.GetThriftMetadata().GetServices() {
p.metadata.Services[name] = v
}
}

// GetProcessorFunction multiplexes redirects to the appropriate Processor
Expand All @@ -61,3 +76,7 @@ func (p *compositeProcessor) GetProcessorFunction(name string) types.ProcessorFu
func (p *compositeProcessor) ProcessorFunctionMap() map[string]types.ProcessorFunction {
return p.serviceProcessorMap
}

func (p *compositeProcessor) GetThriftMetadata() *metadata.ThriftMetadata {
return p.metadata
}
5 changes: 5 additions & 0 deletions thrift/lib/go/thrift/rocket_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"github.com/facebook/fbthrift/thrift/lib/go/thrift/types"
"github.com/facebook/fbthrift/thrift/lib/thrift/metadata"
)

type rocketServerTestProcessor struct {
Expand All @@ -34,6 +35,10 @@ func (t *rocketServerTestProcessor) ProcessorFunctionMap() map[string]types.Proc
return map[string]types.ProcessorFunction{"test": &rocketServerTestProcessorFunction{&testProcessorFunction{}, t.requests}}
}

func (t *rocketServerTestProcessor) GetThriftMetadata() *metadata.ThriftMetadata {
return nil
}

type rocketServerTestProcessorFunction struct {
types.ProcessorFunction
requests chan<- *MyTestStruct
Expand Down
5 changes: 5 additions & 0 deletions thrift/lib/go/thrift/rocket_upgrade_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"maps"

"github.com/facebook/fbthrift/thrift/lib/go/thrift/types"
"github.com/facebook/fbthrift/thrift/lib/thrift/metadata"
)

type rocketUpgradeProcessor struct {
Expand All @@ -43,6 +44,10 @@ func (r *rocketUpgradeProcessor) ProcessorFunctionMap() map[string]types.Process
return mr
}

func (r *rocketUpgradeProcessor) GetThriftMetadata() *metadata.ThriftMetadata {
return r.processor.GetThriftMetadata()
}

type rocketUpgradeProcessorFunction struct {
upgraded *bool
}
Expand Down
5 changes: 5 additions & 0 deletions thrift/lib/go/thrift/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"

"github.com/facebook/fbthrift/thrift/lib/go/thrift/types"
"github.com/facebook/fbthrift/thrift/lib/thrift/metadata"
)

// TestSimpleServer is a simple tests that simple sends an empty message to a server and receives an empty result.
Expand Down Expand Up @@ -66,6 +67,10 @@ func (t *testProcessor) ProcessorFunctionMap() map[string]types.ProcessorFunctio
return map[string]types.ProcessorFunction{"test": &testProcessorFunction{}}
}

func (t *testProcessor) GetThriftMetadata() *metadata.ThriftMetadata {
return nil
}

type testProcessorFunction struct{}

func (p *testProcessorFunction) Read(prot types.Decoder) (types.Struct, types.Exception) {
Expand Down

0 comments on commit 7ee3988

Please sign in to comment.