khenaidoo | 59ce9dd | 2019-11-11 13:05:32 -0500 | [diff] [blame] | 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 | ContentType() string |
| 20 | } |
| 21 | |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame^] | 22 | // Marshalers that implement contentTypeMarshaler will have their ContentTypeFromMessage method called |
| 23 | // to set the Content-Type header on the response |
| 24 | type contentTypeMarshaler interface { |
| 25 | // ContentTypeFromMessage returns the Content-Type this marshaler produces from the provided message |
| 26 | ContentTypeFromMessage(v interface{}) string |
| 27 | } |
| 28 | |
khenaidoo | 59ce9dd | 2019-11-11 13:05:32 -0500 | [diff] [blame] | 29 | // Decoder decodes a byte sequence |
| 30 | type Decoder interface { |
| 31 | Decode(v interface{}) error |
| 32 | } |
| 33 | |
| 34 | // Encoder encodes gRPC payloads / fields into byte sequence. |
| 35 | type Encoder interface { |
| 36 | Encode(v interface{}) error |
| 37 | } |
| 38 | |
| 39 | // DecoderFunc adapts an decoder function into Decoder. |
| 40 | type DecoderFunc func(v interface{}) error |
| 41 | |
| 42 | // Decode delegates invocations to the underlying function itself. |
| 43 | func (f DecoderFunc) Decode(v interface{}) error { return f(v) } |
| 44 | |
| 45 | // EncoderFunc adapts an encoder function into Encoder |
| 46 | type EncoderFunc func(v interface{}) error |
| 47 | |
| 48 | // Encode delegates invocations to the underlying function itself. |
| 49 | func (f EncoderFunc) Encode(v interface{}) error { return f(v) } |
| 50 | |
| 51 | // Delimited defines the streaming delimiter. |
| 52 | type Delimited interface { |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame^] | 53 | // Delimiter returns the record separator for the stream. |
khenaidoo | 59ce9dd | 2019-11-11 13:05:32 -0500 | [diff] [blame] | 54 | Delimiter() []byte |
| 55 | } |