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
WrappedMessageis 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.
WrappedMessagerelies on anint32size 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
- Author:
- anistor@redhat.com
-
-
Field Summary
Fields Modifier and Type Field Description static StringCONTAINER_SIZE_CONTEXT_PARAMstatic StringPROTO_FILEFull path of the message-wrapping.proto resource file in classpath.static intPROTOBUF_TYPE_IDThe type id of WrappedMessage itself.static StringPROTOBUF_TYPE_NAMEThe fully qualified Protobuf type name of this message.static intWRAPPED_BOOLA wrapped bool.static intWRAPPED_BYTEA wrapped byte (marshalled as int32).static intWRAPPED_BYTESA wrapped bytes.static intWRAPPED_CHARA wrapped char (marshalled as int32).static intWRAPPED_CONTAINER_MESSAGEstatic intWRAPPED_CONTAINER_SIZEThe (optional) number of repeated elements.static intWRAPPED_CONTAINER_TYPE_IDstatic intWRAPPED_CONTAINER_TYPE_NAMEstatic intWRAPPED_DATE_MILLISA wrapped java.util.Date (marshalled as int64).static intWRAPPED_DESCRIPTOR_FULL_NAMEDeprecated.UseWRAPPED_TYPE_NAMEinstead.static intWRAPPED_DESCRIPTOR_IDDeprecated.UseWRAPPED_TYPE_IDinstead.static intWRAPPED_DESCRIPTOR_TYPE_IDDeprecated.UseWRAPPED_TYPE_IDinstead.static intWRAPPED_DOUBLEA wrapped double.static intWRAPPED_EMPTYA flag indicating and empty/null message.static intWRAPPED_ENUMThe enum value.static intWRAPPED_FIXED32A wrapped fixed32.static intWRAPPED_FIXED64A wrapped fixed64.static intWRAPPED_FLOATA wrapped float.static intWRAPPED_INSTANT_NANOSThe nanoseconds of the java.time.Instant.static intWRAPPED_INSTANT_SECONDSA wrapped java.time.Instant (marshalled as int64 (seconds) and an int32 (nanos)).static intWRAPPED_INT32A wrapped int32.static intWRAPPED_INT64A wrapped int64.static intWRAPPED_MESSAGEA byte array containing the encoded message.static intWRAPPED_SFIXED32A wrapped sfixed32.static intWRAPPED_SFIXED64A wrapped sfixed64.static intWRAPPED_SHORTA wrapped short (marshalled as int32).static intWRAPPED_SINT32A wrapped sint32.static intWRAPPED_SINT64A wrapped sint64.static intWRAPPED_STRINGA wrapped string.static intWRAPPED_TYPE_IDThe (optional) numeric type id of the wrapped message or enum.static intWRAPPED_TYPE_NAMEThe name of the fully qualified message or enum type name, when the wrapped object is a message or enum.static intWRAPPED_UINT32A wrapped uint32.static intWRAPPED_UINT64A wrapped uint64.
-
Constructor Summary
Constructors Constructor Description WrappedMessage(Object value)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)ObjectgetValue()Returns the wrapped value, which is either a primitive, an enum, or a message.inthashCode()StringtoString()
-
-
-
Field Detail
-
PROTOBUF_TYPE_NAME
public static final String PROTOBUF_TYPE_NAME
The fully qualified Protobuf type name of this message. This type is defined in message-wrapping.proto.- See Also:
- Constant Field Values
-
PROTOBUF_TYPE_ID
public static final int PROTOBUF_TYPE_ID
The type id of WrappedMessage itself.- See Also:
- Constant Field Values
-
PROTO_FILE
public static final String PROTO_FILE
Full path of the message-wrapping.proto resource file in classpath.- See Also:
- Constant Field Values
-
WRAPPED_DOUBLE
public static final int WRAPPED_DOUBLE
A wrapped double.- See Also:
- Constant Field Values
-
WRAPPED_FLOAT
public static final int WRAPPED_FLOAT
A wrapped float.- See Also:
- Constant Field Values
-
WRAPPED_INT64
public static final int WRAPPED_INT64
A wrapped int64.- See Also:
- Constant Field Values
-
WRAPPED_UINT64
public static final int WRAPPED_UINT64
A wrapped uint64.- See Also:
- Constant Field Values
-
WRAPPED_INT32
public static final int WRAPPED_INT32
A wrapped int32.- See Also:
- Constant Field Values
-
WRAPPED_FIXED64
public static final int WRAPPED_FIXED64
A wrapped fixed64.- See Also:
- Constant Field Values
-
WRAPPED_FIXED32
public static final int WRAPPED_FIXED32
A wrapped fixed32.- See Also:
- Constant Field Values
-
WRAPPED_BOOL
public static final int WRAPPED_BOOL
A wrapped bool.- See Also:
- Constant Field Values
-
WRAPPED_STRING
public static final int WRAPPED_STRING
A wrapped string.- See Also:
- Constant Field Values
-
WRAPPED_CHAR
public static final int WRAPPED_CHAR
A wrapped char (marshalled as int32).- See Also:
- Constant Field Values
-
WRAPPED_SHORT
public static final int WRAPPED_SHORT
A wrapped short (marshalled as int32).- See Also:
- Constant Field Values
-
WRAPPED_BYTE
public static final int WRAPPED_BYTE
A wrapped byte (marshalled as int32).- See Also:
- Constant Field Values
-
WRAPPED_DATE_MILLIS
public static final int WRAPPED_DATE_MILLIS
A wrapped java.util.Date (marshalled as int64).- See Also:
- Constant Field Values
-
WRAPPED_INSTANT_SECONDS
public static final int WRAPPED_INSTANT_SECONDS
A wrapped java.time.Instant (marshalled as int64 (seconds) and an int32 (nanos)).- See Also:
- Constant Field Values
-
WRAPPED_INSTANT_NANOS
public static final int WRAPPED_INSTANT_NANOS
The nanoseconds of the java.time.Instant.- See Also:
- Constant Field Values
-
WRAPPED_BYTES
public static final int WRAPPED_BYTES
A wrapped bytes.- See Also:
- Constant Field Values
-
WRAPPED_UINT32
public static final int WRAPPED_UINT32
A wrapped uint32.- See Also:
- Constant Field Values
-
WRAPPED_SFIXED32
public static final int WRAPPED_SFIXED32
A wrapped sfixed32.- See Also:
- Constant Field Values
-
WRAPPED_SFIXED64
public static final int WRAPPED_SFIXED64
A wrapped sfixed64.- See Also:
- Constant Field Values
-
WRAPPED_SINT32
public static final int WRAPPED_SINT32
A wrapped sint32.- See Also:
- Constant Field Values
-
WRAPPED_SINT64
public static final int WRAPPED_SINT64
A wrapped sint64.- See Also:
- Constant Field Values
-
WRAPPED_TYPE_NAME
public static final int WRAPPED_TYPE_NAME
The name of the fully qualified message or enum type name, when the wrapped object is a message or enum.- See Also:
- Constant Field Values
-
WRAPPED_DESCRIPTOR_FULL_NAME
@Deprecated public static final int WRAPPED_DESCRIPTOR_FULL_NAME
Deprecated.UseWRAPPED_TYPE_NAMEinstead. This will be removed in ver. 5.- See Also:
- Constant Field Values
-
WRAPPED_MESSAGE
public static final int WRAPPED_MESSAGE
A byte array containing the encoded message.- See Also:
- Constant Field Values
-
WRAPPED_ENUM
public static final int WRAPPED_ENUM
The enum value.- See Also:
- Constant Field Values
-
WRAPPED_TYPE_ID
public static final int WRAPPED_TYPE_ID
The (optional) numeric type id of the wrapped message or enum. This is an alternative toWRAPPED_TYPE_NAME.- See Also:
- Constant Field Values
-
WRAPPED_DESCRIPTOR_TYPE_ID
@Deprecated public static final int WRAPPED_DESCRIPTOR_TYPE_ID
Deprecated.UseWRAPPED_TYPE_IDinstead. This will be removed in ver. 5.- See Also:
- Constant Field Values
-
WRAPPED_DESCRIPTOR_ID
@Deprecated public static final int WRAPPED_DESCRIPTOR_ID
Deprecated.UseWRAPPED_TYPE_IDinstead. This will be removed in ver. 5.- See Also:
- Constant Field Values
-
WRAPPED_EMPTY
public static final int WRAPPED_EMPTY
A flag indicating and empty/null message.- See Also:
- Constant Field Values
-
WRAPPED_CONTAINER_SIZE
public static final int WRAPPED_CONTAINER_SIZE
The (optional) number of repeated elements.- See Also:
- Constant Field Values
-
WRAPPED_CONTAINER_TYPE_NAME
public static final int WRAPPED_CONTAINER_TYPE_NAME
- See Also:
- Constant Field Values
-
WRAPPED_CONTAINER_TYPE_ID
public static final int WRAPPED_CONTAINER_TYPE_ID
- See Also:
- Constant Field Values
-
WRAPPED_CONTAINER_MESSAGE
public static final int WRAPPED_CONTAINER_MESSAGE
- See Also:
- Constant Field Values
-
CONTAINER_SIZE_CONTEXT_PARAM
public static final String CONTAINER_SIZE_CONTEXT_PARAM
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
WrappedMessage
public WrappedMessage(Object value)
-
-
Method Detail
-
getValue
public Object getValue()
Returns the wrapped value, which is either a primitive, an enum, or a message. The value can benullalso.
-
-