class Protocol::HTTP::Body::Wrapper

Wrapping body instance. Typically you’d override ‘#read`.

def self.wrap(message)

@returns [Wrapper | Nil] the wrapped body or `nil`` if the body was `nil`.
@parameter message [Request | Response] the message to wrap.

Wrap the body of the given message in a new instance of this class.
def self.wrap(message)
	if body = message.body
		message.body = self.new(body)
	end
end

def as_json(...)

@returns [Hash] The body as a hash.

Convert the body to a hash suitable for serialization.
def as_json(...)
	{
		class: self.class.name,
		body: @body&.as_json
	}
end

def buffered

Forwards to the wrapped body.
def buffered
	@body.buffered
end

def close(error = nil)

@parameter error [Exception | Nil] The error that caused this stream to be closed, if any.

Close the body.
def close(error = nil)
	@body.close(error)
	
	# It's a no-op:
	# super
end

def discard

Forwards to the wrapped body.
def discard
	@body.discard
end

def empty?

Forwards to the wrapped body.
def empty?
	@body.empty?
end

def initialize(body)

@parameter body [Readable] The body to wrap.

Initialize the wrapper with the given body.
def initialize(body)
	@body = body
end

def inspect

@returns [String] a string representation of the wrapped body.

Inspect the wrapped body. The wrapper, by default, is transparent.
def inspect
	@body.inspect
end

def length

Forwards to the wrapped body.
def length
	@body.length
end

def read

Forwards to the wrapped body.
def read
	@body.read
end

def ready?

Forwards to the wrapped body.
def ready?
	@body.ready?
end

def rewind

Forwards to the wrapped body.
def rewind
	@body.rewind
end

def rewindable?

Forwards to the wrapped body.
def rewindable?
	@body.rewindable?
end

def to_json(...)

@returns [String] The body as JSON.

Convert the body to JSON.
def to_json(...)
	as_json.to_json(...)
end