mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-07 05:47:36 +00:00
Support for Golang GRPC (Experimental) (#4082)
* support for grpc golang * refactored grpc go generator * added grpc-go test and refactored * refactored idl_gen_grpc.cpp * fixed grpc generate method name * refactored flatc and fixed line length issue * added codec to go lib and fixed formatting issues * fixed spacing issues
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
bc2ec7119b
commit
a31ddd2bb3
106
tests/MyGame/Example/MonsterStorage_grpc.go
Normal file
106
tests/MyGame/Example/MonsterStorage_grpc.go
Normal file
@@ -0,0 +1,106 @@
|
||||
//Generated by gRPC Go plugin
|
||||
//If you make any local changes, they will be lost
|
||||
//source: monster_test
|
||||
|
||||
package Example
|
||||
|
||||
import "github.com/google/flatbuffers/go"
|
||||
|
||||
import (
|
||||
context "golang.org/x/net/context"
|
||||
grpc "google.golang.org/grpc"
|
||||
)
|
||||
|
||||
// Client API for MonsterStorage service
|
||||
type MonsterStorageClient interface{
|
||||
Store(ctx context.Context, in *flatbuffers.Builder,
|
||||
opts... grpc.CallOption) (* Stat, error)
|
||||
Retrieve(ctx context.Context, in *flatbuffers.Builder,
|
||||
opts... grpc.CallOption) (* Monster, error)
|
||||
}
|
||||
|
||||
type monsterStorageClient struct {
|
||||
cc *grpc.ClientConn
|
||||
}
|
||||
|
||||
func NewMonsterStorageClient(cc *grpc.ClientConn) MonsterStorageClient {
|
||||
return &monsterStorageClient{cc}
|
||||
}
|
||||
|
||||
func (c *monsterStorageClient) Store(ctx context.Context, in *flatbuffers.Builder,
|
||||
opts... grpc.CallOption) (* Stat, error) {
|
||||
out := new(Stat)
|
||||
err := grpc.Invoke(ctx, "/Example.MonsterStorage/Store", in, out, c.cc, opts...)
|
||||
if err != nil { return nil, err }
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *monsterStorageClient) Retrieve(ctx context.Context, in *flatbuffers.Builder,
|
||||
opts... grpc.CallOption) (* Monster, error) {
|
||||
out := new(Monster)
|
||||
err := grpc.Invoke(ctx, "/Example.MonsterStorage/Retrieve", in, out, c.cc, opts...)
|
||||
if err != nil { return nil, err }
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for MonsterStorage service
|
||||
type MonsterStorageServer interface {
|
||||
Store(context.Context, *Monster) (*flatbuffers.Builder, error)
|
||||
Retrieve(context.Context, *Stat) (*flatbuffers.Builder, error)
|
||||
}
|
||||
|
||||
func RegisterMonsterStorageServer(s *grpc.Server, srv MonsterStorageServer) {
|
||||
s.RegisterService(&_MonsterStorage_serviceDesc, srv)
|
||||
}
|
||||
|
||||
func _MonsterStorage_Store_Handler(srv interface{}, ctx context.Context,
|
||||
dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(Monster)
|
||||
if err := dec(in); err != nil { return nil, err }
|
||||
if interceptor == nil { return srv.(MonsterStorageServer).Store(ctx, in) }
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/Example.MonsterStorage/Store",
|
||||
}
|
||||
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(MonsterStorageServer).Store(ctx, req.(* Monster))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
|
||||
func _MonsterStorage_Retrieve_Handler(srv interface{}, ctx context.Context,
|
||||
dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(Stat)
|
||||
if err := dec(in); err != nil { return nil, err }
|
||||
if interceptor == nil { return srv.(MonsterStorageServer).Retrieve(ctx, in) }
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/Example.MonsterStorage/Retrieve",
|
||||
}
|
||||
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(MonsterStorageServer).Retrieve(ctx, req.(* Stat))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
|
||||
var _MonsterStorage_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "Example.MonsterStorage",
|
||||
HandlerType: (*MonsterStorageServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "Store",
|
||||
Handler: _MonsterStorage_Store_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Retrieve",
|
||||
Handler: _MonsterStorage_Retrieve_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user