Class WrappedMessage

java.lang.Object
org.infinispan.protostream.WrappedMessage

public final class WrappedMessage extends Object
A wrapper for messages, enums or primitive types that encodes the type of the inner object/value and also helps keep track of where the message ends. The need for this wrapper stems from two particular design choices in the Protocol Buffers encoding.

1. The Protocol Buffers encoding format does not contain any description of the message type that follows next in the data stream, unlike for example the Java serialization format which provides information about classes that are saved in a Serialization stream in the form of class descriptors which contain the fully qualified name of the class being serialized. The Protocol Buffers client is expected to know what message type he is expecting to read from the stream. This knowledge exists in most cases, statically, so this encoding scheme saves a lot of space by not including redundant type descriptors in the stream by default. For all other use cases where data types are dynamic you are on your own, but WrappedMessage is here to help you.

2. The Protocol Buffer wire format is also not self-delimiting, so when reading a message we see just a stream of fields and we are not able to determine when the fields of the current message end and the next message starts. The protocol assumes that the whole contents of the stream is to be interpreted as a single message. If that's not the case, then the user must provide his own way of delimiting messages either by using message start/stop markers or by prefixing each message with its size or any other equivalent mechanism. WrappedMessage relies on an int32 size prefix.

So wherever you cannot statically decide what message type you'll be using and need to defer this until runtime, just use WrappedMessage.

Since:
1.0