marshaler.go 1.5 KB

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