public final class CompositeMetadata extends Object implements Iterable<CompositeMetadata.Entry>
Iterable
wrapper around a ByteBuf
that exposes metadata entry information at
each decoding step. This is only possible on frame types used to initiate interactions, if the
SETUP metadata mime type was WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA
.
This allows efficient incremental decoding of the entries (without moving the source's ByteBuf.readerIndex()
). The buffer is assumed to contain just enough bytes to
represent one or more entries (mime type compressed or not). The decoding stops when the buffer
reaches 0 readable bytes, and fails if it contains bytes but not enough to correctly decode an
entry.
A note on future-proofness: it is possible to come across a compressed mime type that this
implementation doesn't recognize. This is likely to be due to the use of a byte id that is merely
reserved in this implementation, but maps to a WellKnownMimeType
in the implementation
that encoded the metadata. This can be detected by detecting that an entry is a CompositeMetadata.ReservedMimeTypeEntry
. In this case CompositeMetadata.Entry.getMimeType()
will return null
. The
encoded id can be retrieved using CompositeMetadata.ReservedMimeTypeEntry.getType()
. The byte and content
buffer should be kept around and re-encoded using CompositeMetadataFlyweight.encodeAndAddMetadata(CompositeByteBuf, ByteBufAllocator, byte,
ByteBuf)
in case passing that entry through is required.
Modifier and Type | Class and Description |
---|---|
static interface |
CompositeMetadata.Entry
An entry in the
CompositeMetadata . |
static class |
CompositeMetadata.ExplicitMimeTimeEntry
An
CompositeMetadata.Entry backed by an explicitly declared MIME type. |
static class |
CompositeMetadata.ReservedMimeTypeEntry
An
CompositeMetadata.Entry backed by a WellKnownMimeType entry, but one that is not understood by
this implementation. |
static class |
CompositeMetadata.WellKnownMimeTypeEntry
An
CompositeMetadata.Entry backed by a WellKnownMimeType . |
Constructor and Description |
---|
CompositeMetadata(ByteBuf source,
boolean retainSlices) |
Modifier and Type | Method and Description |
---|---|
Iterator<CompositeMetadata.Entry> |
iterator()
An
Iterator that lazily decodes CompositeMetadata.Entry in this composite metadata. |
Stream<CompositeMetadata.Entry> |
stream()
Turn this
CompositeMetadata into a sequential Stream . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public CompositeMetadata(ByteBuf source, boolean retainSlices)
public Stream<CompositeMetadata.Entry> stream()
CompositeMetadata
into a sequential Stream
.Stream
public Iterator<CompositeMetadata.Entry> iterator()
Iterator
that lazily decodes CompositeMetadata.Entry
in this composite metadata.iterator
in interface Iterable<CompositeMetadata.Entry>
Iterator