Documentation
¶
Index ¶
- func IsNonDeterministicSerialization(codec Codec) bool
- func Marshal(codec Codec, v any) ([]byte, error)
- func Unmarshal(codec Codec, data []byte, v any) error
- type Codec
- type InputPayload
- type NonDeterministicSerializer
- type OutputPayload
- type PayloadCodec
- type RestateMarshaler
- type RestateUnmarshaler
- type Void
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNonDeterministicSerialization ¶ added in v0.24.0
IsNonDeterministicSerialization returns true if the codec may produce non-deterministic output. This is true for ProtoJSONCodec (protojson does not guarantee deterministic output) and any codec implementing NonDeterministicSerializer that returns true from IsNonDeterministic().
func Marshal ¶
Marshal converts its input v into []byte using the codec, respecting RestateMarshaler implementors
Types ¶
type Codec ¶
Codec is a mechanism for serialising and deserialising a wide range of types. Care should be taken to ensure that only valid types are passed to a codec, eg proto.Message for ProtoCodec. Codecs *must* marshal deterministically, such that a round trip of []byte -> any -> []byte leaves the bytes unchanged.
type InputPayload ¶
type InputPayload struct {
Required bool `json:"required"`
ContentType *string `json:"contentType,omitempty"`
JsonSchema interface{} `json:"jsonSchema,omitempty"`
}
InputPayload is provided to Restate upon handler discovery, to teach the ingress how to validate incoming request bodies.
func InputPayloadFor ¶
func InputPayloadFor(codec PayloadCodec, i any) *InputPayload
InputPayloadFor determines the InputPayload for the type stored in i, respecting RestateUnmarshaler implementors
type NonDeterministicSerializer ¶ added in v0.24.0
type NonDeterministicSerializer interface {
IsNonDeterministic() bool
}
NonDeterministicSerializer is an interface that codecs can implement to indicate they may produce non-deterministic output for the same input.
type OutputPayload ¶
type OutputPayload struct {
ContentType *string `json:"contentType,omitempty"`
SetContentTypeIfEmpty bool `json:"setContentTypeIfEmpty"`
JsonSchema interface{} `json:"jsonSchema,omitempty"`
}
OutputPayload is provided to Restate upon handler discovery, to teach the ingress how to annotate outgoing response bodies.
func OutputPayloadFor ¶
func OutputPayloadFor(codec PayloadCodec, o any) *OutputPayload
OutputPayloadFor determines the OutputPayload for the type stored in o, respecting RestateMarshaler implementors
type PayloadCodec ¶
type PayloadCodec interface {
InputPayload(i any) *InputPayload
OutputPayload(o any) *OutputPayload
Codec
}
PayloadCodec is implemented by a Codec that can also be used in handlers, and so must provide a InputPayload and OutputPayload i and o are zero values of the input/output types, which the codec may use to influence its response.
var ( // BinaryCodec marshals []byte and unmarshals into *[]byte // In handlers, it uses a content type of application/octet-stream BinaryCodec PayloadCodec = binaryCodec{} // ProtoCodec marshals proto.Message and unmarshals into proto.Message or pointers to types that implement proto.Message // In handlers, it uses a content-type of application/proto ProtoCodec PayloadCodec = protoCodec{} // ProtoJSONCodec marshals proto.Message and unmarshals into proto.Message or pointers to types that implement proto.Message // It uses the protojson package to marshal and unmarshal // In handlers, it uses a content-type of application/json ProtoJSONCodec PayloadCodec = protoJSONCodec{} // JSONCodec marshals any json.Marshallable type and unmarshals into any json.Unmarshallable type // In handlers, it uses a content-type of application/json JSONCodec PayloadCodec = jsonCodec{ // contains filtered or unexported fields } )
func JSONCodecWithCustomSchemaGenerator ¶ added in v0.16.0
func JSONCodecWithCustomSchemaGenerator(genJsonSchema func(v any) interface{}) PayloadCodec
type RestateMarshaler ¶
type RestateMarshaler interface {
RestateMarshal(codec Codec) ([]byte, error)
OutputPayload(codec Codec) *OutputPayload
}
RestateMarshaler can be implemented by types that want to control their own marshaling Marshaling *must* be deterministic
type RestateUnmarshaler ¶
type RestateUnmarshaler interface {
RestateUnmarshal(codec Codec, data []byte) error
InputPayload(codec Codec) *InputPayload
}
RestateUnmarshaler can be implemented by types that want to control their own unmarshaling
type Void ¶
type Void struct{}
Void is a placeholder to signify 'no value' where a type is otherwise needed It implements RestateMarshaler and RestateUnmarshaler to ensure that no marshaling or unmarshaling ever happens on this type.
func (Void) InputPayload ¶
func (v Void) InputPayload(codec Codec) *InputPayload
func (Void) OutputPayload ¶
func (v Void) OutputPayload(codec Codec) *OutputPayload