mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-27 17:08:07 +00:00
[go]add Name() for ForceCodec interface (#5486)
* add Name() for ForceCodec interface // ForceCodec returns a CallOption that will set the given Codec to be // used for all request and response messages for a call. The result of calling // String() will be used as the content-subtype in a case-insensitive manner. // * Update grpc.go
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
a2485d4ecc
commit
3030449348
15
go/grpc.go
15
go/grpc.go
@@ -3,21 +3,36 @@ package flatbuffers
|
|||||||
// Codec implements gRPC-go Codec which is used to encode and decode messages.
|
// Codec implements gRPC-go Codec which is used to encode and decode messages.
|
||||||
var Codec = "flatbuffers"
|
var Codec = "flatbuffers"
|
||||||
|
|
||||||
|
// FlatbuffersCodec defines the interface gRPC uses to encode and decode messages. Note
|
||||||
|
// that implementations of this interface must be thread safe; a Codec's
|
||||||
|
// methods can be called from concurrent goroutines.
|
||||||
type FlatbuffersCodec struct{}
|
type FlatbuffersCodec struct{}
|
||||||
|
|
||||||
|
// Marshal returns the wire format of v.
|
||||||
func (FlatbuffersCodec) Marshal(v interface{}) ([]byte, error) {
|
func (FlatbuffersCodec) Marshal(v interface{}) ([]byte, error) {
|
||||||
return v.(*Builder).FinishedBytes(), nil
|
return v.(*Builder).FinishedBytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unmarshal parses the wire format into v.
|
||||||
func (FlatbuffersCodec) Unmarshal(data []byte, v interface{}) error {
|
func (FlatbuffersCodec) Unmarshal(data []byte, v interface{}) error {
|
||||||
v.(flatbuffersInit).Init(data, GetUOffsetT(data))
|
v.(flatbuffersInit).Init(data, GetUOffsetT(data))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String old gRPC Codec interface func
|
||||||
func (FlatbuffersCodec) String() string {
|
func (FlatbuffersCodec) String() string {
|
||||||
return Codec
|
return Codec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Name returns the name of the Codec implementation. The returned string
|
||||||
|
// will be used as part of content type in transmission. The result must be
|
||||||
|
// static; the result cannot change between calls.
|
||||||
|
//
|
||||||
|
// add Name() for ForceCodec interface
|
||||||
|
func (FlatbuffersCodec) Name() string {
|
||||||
|
return Codec
|
||||||
|
}
|
||||||
|
|
||||||
type flatbuffersInit interface {
|
type flatbuffersInit interface {
|
||||||
Init(data []byte, i UOffsetT)
|
Init(data []byte, i UOffsetT)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user