blob: 46153294217fde53a37839d6bbe59e8e5a3adc88 [file] [log] [blame]
khenaidoo59ce9dd2019-11-11 13:05:32 -05001package runtime
2
3import (
4 "io"
5)
6
7// Marshaler defines a conversion between byte sequence and gRPC payloads / fields.
8type 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
khenaidoo26721882021-08-11 17:42:52 -040022// Marshalers that implement contentTypeMarshaler will have their ContentTypeFromMessage method called
23// to set the Content-Type header on the response
24type contentTypeMarshaler interface {
25 // ContentTypeFromMessage returns the Content-Type this marshaler produces from the provided message
26 ContentTypeFromMessage(v interface{}) string
27}
28
khenaidoo59ce9dd2019-11-11 13:05:32 -050029// Decoder decodes a byte sequence
30type Decoder interface {
31 Decode(v interface{}) error
32}
33
34// Encoder encodes gRPC payloads / fields into byte sequence.
35type Encoder interface {
36 Encode(v interface{}) error
37}
38
39// DecoderFunc adapts an decoder function into Decoder.
40type DecoderFunc func(v interface{}) error
41
42// Decode delegates invocations to the underlying function itself.
43func (f DecoderFunc) Decode(v interface{}) error { return f(v) }
44
45// EncoderFunc adapts an encoder function into Encoder
46type EncoderFunc func(v interface{}) error
47
48// Encode delegates invocations to the underlying function itself.
49func (f EncoderFunc) Encode(v interface{}) error { return f(v) }
50
51// Delimited defines the streaming delimiter.
52type Delimited interface {
khenaidoo26721882021-08-11 17:42:52 -040053 // Delimiter returns the record separator for the stream.
khenaidoo59ce9dd2019-11-11 13:05:32 -050054 Delimiter() []byte
55}