Method: CloudEvents::Format#encode_data

Defined in:
lib/cloud_events/format.rb

#encode_data(**_kwargs) ⇒ Hash?

Encode an event data object to string format. This is typically called by a protocol binding to serialize the payload (i.e. data attribute and corresponding datacontenttype attribute) of an event as part of "binary content mode" encoding.

Common arguments include:

  • :spec_version (String) The specversion of the event.
  • :data (Object) The payload object from an event's data attribute.
  • :content_type (ContentType) The content type from an event's datacontenttype attribute.

The formatter must first determine whether it is able to interpret the given input. Typically, this is done by inspecting the content_type. If the formatter determines that it is unable to interpret the input, it should return nil. Otherwise, if the formatter determines it can decode the input, it should return a Hash. Common hash keys include:

  • :content (String) The serialized form of the data. This might, for example, be written to an HTTP request body. Care should be taken to set the string's encoding properly. In particular, to output binary data, the encoding should probably be set to ASCII_8BIT.
  • :content_type (ContentType) The content type for the output. This might, for example, be written to the Content-Type header of an HTTP request.

The formatter may also raise a CloudEventsError subclass if it understood the request but determines that the input source is malformed.

Parameters:

  • _kwargs (keywords)

    Arguments

Returns:

  • (Hash)

    if accepting the request and returning a result

  • (nil)

    if declining the request.



198
199
200
# File 'lib/cloud_events/format.rb', line 198

def encode_data **_kwargs
  nil
end