class CloudEvents::Event::Opaque

This object represents opaque event data that arrived in structured content mode but was not in a recognized format. It may represent a single event or a batch of events.

The event data is retained in a form that can be reserialized (in a structured cotent mode in the same format) but cannot otherwise be inspected.

This object is immutable, and Ractor-shareable on Ruby 3.

Attributes

content[R]

The opaque serialized event data

@return [String]

content_type[R]

The content type, or `nil` if there is no content type.

@return [CloudEvents::ContentType,nil]

Public Class Methods

new(content, content_type, batch: nil) click to toggle source

Create an opaque object wrapping the given content and a content type.

@param content [String] The opaque serialized event data. @param content_type [CloudEvents::ContentType,nil] The content type,

or `nil` if there is no content type.

@param batch [boolean] Whether this represents a batch. If set to `nil`

or not provided, the value will be inferred from the content type
if possible, or otherwise set to `nil` indicating not known.
# File lib/cloud_events/event/opaque.rb, line 27
def initialize content, content_type, batch: nil
  @content = content.freeze
  @content_type = content_type
  if batch.nil? && content_type&.media_type == "application"
    case content_type.subtype_base
    when "cloudevents"
      batch = false
    when "cloudevents-batch"
      batch = true
    end
  end
  @batch = batch
  freeze
end

Public Instance Methods

==(other) click to toggle source

@private

# File lib/cloud_events/event/opaque.rb, line 66
def == other
  Opaque === other &&
    @content == other.content &&
    @content_type == other.content_type &&
    @batch == other.batch?
end
Also aliased as: eql?
batch?() click to toggle source

Whether this represents a batch, or `nil` if not known.

@return [boolean,nil]

# File lib/cloud_events/event/opaque.rb, line 61
def batch?
  @batch
end
eql?(other)
Alias for: ==
hash() click to toggle source

@private

# File lib/cloud_events/event/opaque.rb, line 75
def hash
  @content.hash ^ @content_type.hash ^ @batch.hash
end