blob: b1dfc37af9b9f61125d6b3544f614bd48984ef15 [file] [log] [blame]
Abhay Kumara2ae5992025-11-10 14:02:24 +00001package 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 // 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
25type Decoder interface {
26 Decode(v interface{}) error
27}
28
29// Encoder encodes gRPC payloads / fields into byte sequence.
30type Encoder interface {
31 Encode(v interface{}) error
32}
33
34// DecoderFunc adapts an decoder function into Decoder.
35type DecoderFunc func(v interface{}) error
36
37// Decode delegates invocations to the underlying function itself.
38func (f DecoderFunc) Decode(v interface{}) error { return f(v) }
39
40// EncoderFunc adapts an encoder function into Encoder
41type EncoderFunc func(v interface{}) error
42
43// Encode delegates invocations to the underlying function itself.
44func (f EncoderFunc) Encode(v interface{}) error { return f(v) }
45
46// Delimited defines the streaming delimiter.
47type Delimited interface {
48 // Delimiter returns the record separator for the stream.
49 Delimiter() []byte
50}
51
52// StreamContentType defines the streaming content type.
53type StreamContentType interface {
54 // StreamContentType returns the content type for a stream. This shares the
55 // same behaviour as for `Marshaler.ContentType`, but is called, if present,
56 // in the case of a streamed response.
57 StreamContentType(v interface{}) string
58}