...

Source file src/github.com/google/flatbuffers/go/grpc.go

Documentation: github.com/google/flatbuffers/go

     1  package flatbuffers
     2  
     3  // Codec implements gRPC-go Codec which is used to encode and decode messages.
     4  var Codec = "flatbuffers"
     5  
     6  // FlatbuffersCodec defines the interface gRPC uses to encode and decode messages.  Note
     7  // that implementations of this interface must be thread safe; a Codec's
     8  // methods can be called from concurrent goroutines.
     9  type FlatbuffersCodec struct{}
    10  
    11  // Marshal returns the wire format of v.
    12  func (FlatbuffersCodec) Marshal(v interface{}) ([]byte, error) {
    13  	return v.(*Builder).FinishedBytes(), nil
    14  }
    15  
    16  // Unmarshal parses the wire format into v.
    17  func (FlatbuffersCodec) Unmarshal(data []byte, v interface{}) error {
    18  	v.(flatbuffersInit).Init(data, GetUOffsetT(data))
    19  	return nil
    20  }
    21  
    22  // String  old gRPC Codec interface func
    23  func (FlatbuffersCodec) String() string {
    24  	return Codec
    25  }
    26  
    27  // Name returns the name of the Codec implementation. The returned string
    28  // will be used as part of content type in transmission.  The result must be
    29  // static; the result cannot change between calls.
    30  //
    31  // add Name() for ForceCodec interface
    32  func (FlatbuffersCodec) Name() string {
    33  	return Codec
    34  }
    35  
    36  type flatbuffersInit interface {
    37  	Init(data []byte, i UOffsetT)
    38  }
    39  

View as plain text