Codec marshals structs (typically generated from a schema) to and from bytes.
| 33 | |
| 34 | // Codec marshals structs (typically generated from a schema) to and from bytes. |
| 35 | type Codec interface { |
| 36 | // Name returns the name of the Codec. |
| 37 | // |
| 38 | // This may be used as part of the Content-Type within HTTP. For example, |
| 39 | // with gRPC this is the content subtype, so "application/grpc+proto" will |
| 40 | // map to the Codec with name "proto". |
| 41 | // |
| 42 | // Names must not be empty. |
| 43 | Name() string |
| 44 | // Marshal marshals the given message. |
| 45 | // |
| 46 | // Marshal may expect a specific type of message, and will error if this type |
| 47 | // is not given. |
| 48 | Marshal(any) ([]byte, error) |
| 49 | // Unmarshal unmarshals the given message. |
| 50 | // |
| 51 | // Unmarshal may expect a specific type of message, and will error if this |
| 52 | // type is not given. |
| 53 | Unmarshal([]byte, any) error |
| 54 | } |
| 55 | |
| 56 | // marshalAppender is an extension to Codec for appending to a byte slice. |
| 57 | type marshalAppender interface { |
no outgoing calls
no test coverage detected