Documentation ¶
Index ¶
Constants ¶
const ( // MediaTypeProtobuf is used to indicate that the event is in protobuf // encoding. Using a non-standard name to guard against any breaking changes // in the official protobuf schema before it becomes 1.0. The short SHA // identifies the commit where protobuf was added to the specification. MediaTypeProtobuf = "application/cloudevents+protobuf-ad5f142" // MediaTypeProtobufJSON is a non-standard encoding that uses the protobuf // JSON encoding rather than binary. This is useful for maintaining human // readability of messages. MediaTypeProtobufJSON = "application/cloudevents+protobuf+json-ad5f142" )
const ( // ContentTypeProtobuf indicates that the data attribute is a protobuf // message. ContentTypeProtobuf = "application/protobuf-ad5f142" )
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode converts an encoded protobuf message back into the message type (out). The message must be type/wire compatible with whatever was given to Encode. This method will assume that the encoded value was encoded by this package which wraps the content in an any type but will fall back to directly unmarshalling the bytes into the message if that fails.
func Encode ¶
Encode a protobuf message to bytes. This implementations wraps the given message in an any type before marshaling. This is done because using the any type is a requirement when using the protobuf message format but the type information required to build an any is only available here, before encoding. Wrapping the message in an any allows the protobuf format to detect the encoding and unmarshal the bytes without knowing the underlying type information. The Decode method provided by this package does the inverse so that most users of the SDK are unaware that this happens.
Like the official datacodec implementations, this one returns the given value as-is if it is already a byte slice. Additionally, if the value is an any message already then we preserve it as is since this is the equivalent case for protobuf where the value is already encoded.
Types ¶
type FormatProtobuf ¶
type FormatProtobuf struct{}
func (FormatProtobuf) MediaType ¶
func (FormatProtobuf) MediaType() string
type FormatProtobufJSON ¶
type FormatProtobufJSON struct{}
func (FormatProtobufJSON) Marshal ¶
func (FormatProtobufJSON) Marshal(e *event.Event) ([]byte, error)
func (FormatProtobufJSON) MediaType ¶
func (FormatProtobufJSON) MediaType() string