...

Source file src/github.com/grpc-ecosystem/grpc-gateway/v2/runtime/marshaler.go

Documentation: github.com/grpc-ecosystem/grpc-gateway/v2/runtime

     1  package runtime
     2  
     3  import (
     4  	"io"
     5  )
     6  
     7  // Marshaler defines a conversion between byte sequence and gRPC payloads / fields.
     8  type Marshaler interface {
     9  	// Marshal marshals "v" into byte sequence.
    10  	Marshal(v interface{}) ([]byte, error)
    11  	// Unmarshal unmarshals "data" into "v".
    12  	// "v" must be a pointer value.
    13  	Unmarshal(data []byte, v interface{}) error
    14  	// NewDecoder returns a Decoder which reads byte sequence from "r".
    15  	NewDecoder(r io.Reader) Decoder
    16  	// NewEncoder returns an Encoder which writes bytes sequence into "w".
    17  	NewEncoder(w io.Writer) Encoder
    18  	// ContentType returns the Content-Type which this marshaler is responsible for.
    19  	// The parameter describes the type which is being marshalled, which can sometimes
    20  	// affect the content type returned.
    21  	ContentType(v interface{}) string
    22  }
    23  
    24  // Decoder decodes a byte sequence
    25  type Decoder interface {
    26  	Decode(v interface{}) error
    27  }
    28  
    29  // Encoder encodes gRPC payloads / fields into byte sequence.
    30  type Encoder interface {
    31  	Encode(v interface{}) error
    32  }
    33  
    34  // DecoderFunc adapts an decoder function into Decoder.
    35  type DecoderFunc func(v interface{}) error
    36  
    37  // Decode delegates invocations to the underlying function itself.
    38  func (f DecoderFunc) Decode(v interface{}) error { return f(v) }
    39  
    40  // EncoderFunc adapts an encoder function into Encoder
    41  type EncoderFunc func(v interface{}) error
    42  
    43  // Encode delegates invocations to the underlying function itself.
    44  func (f EncoderFunc) Encode(v interface{}) error { return f(v) }
    45  
    46  // Delimited defines the streaming delimiter.
    47  type Delimited interface {
    48  	// Delimiter returns the record separator for the stream.
    49  	Delimiter() []byte
    50  }
    51  

View as plain text