Class ByteBufResponseWriter
- All Implemented Interfaces:
ResponseWriter
The class provides specific methods for the RESP3 types. In cases where the response object type is unknown or heterogeneous during runtime, there is a generic method.
During serialization, the class introspects the registry for a serializer capable of handling the object before proceeding. Utilizing a specific method reduces the number of candidates to check. The generic method verifies all serializers in the registry and short circuits after the first match. However, this could cause many checks until the correct serializer. Give preference to specific methods.
The method throws an exception when an object does not have a serializer.
- Since:
- 15.0
- Author:
- José Bolina
-
Field Summary
Fields inherited from interface org.infinispan.server.resp.serialization.ResponseWriter
ARRAY_BULK_STRING, ARRAY_DOUBLE, ARRAY_INTEGER, BULK_STRING, BULK_STRING_BYTES, CUSTOM, DOUBLE, INTEGER, MAP_BULK_STRING_KV, OK, SET_BULK_STRING, SIMPLE_STRING, UNKNOWN
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
array
(Collection<?> collection, Resp3Type contentType) Serializes a collection in the array format with elements of a specified type.<T> void
array
(Collection<T> collection, JavaObjectSerializer<T> serializer) Serializes the collection by delegating the serialization of the elements to the provided serializer.void
Serializes a collection in the array format.void
booleans
(boolean value) Serializes a boolean value in the RESP3 format.void
Serializes a double-precision floating point into the doubles format.void
emptySet()
Serializes a set in the RESP3 set format.void
error
(CharSequence value) Serializes an error message in the RESP3 format.void
Serializes the exception message in the RESP3 error format.void
Serializes a 64-bit number in the integer format.void
Serializes a map in the RESP3 map format.void
Serializes a map in the RESP3 map format with key and values of the same specified type.void
Serializes a map in the RESP3 map format with keys and values of a specified format.void
nulls()
Writes the null value.void
ok()
Serializes a simple string with the"OK"
content.void
Serializes a simple string with the"QUEUED"
content.void
Generic method to serialize an object of unknown type.void
Serializes a set in the RESP3 set format with elements of a specified type.void
simpleString
(CharSequence value) Serializes a char sequence in a simple string format.void
string
(byte[] value) Serializes the binary blob in a bulk string format.void
string
(CharSequence value) Serializes a char sequence in a bulk string format.<T> void
write
(JavaObjectSerializer<T> serializer) Invokes the callback to write a response with the serializer.<T> void
write
(T object, JavaObjectSerializer<T> serializer) Writes an object utilizing the specific serializer.void
writeNumericPrefix
(byte symbol, long number, int additionalWidth) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.infinispan.server.resp.serialization.ResponseWriter
customError, indexOutOfRange, minOrMaxNotAValidFloat, minOrMaxNotAValidStringRange, mustBePositive, mustBePositive, nanOrInfinity, noSuchKey, syntaxError, transactionAborted, unauthorized, unknownCommand, valueNotAValidFloat, valueNotInteger, writeNumericPrefix, wrongArgumentCount, wrongArgumentNumber, wrongType
-
Constructor Details
-
ByteBufResponseWriter
-
-
Method Details
-
nulls
public void nulls()Writes the null value.- Specified by:
nulls
in interfaceResponseWriter
-
ok
public void ok()Serializes a simple string with the"OK"
content.- Specified by:
ok
in interfaceResponseWriter
-
queued
Serializes a simple string with the"QUEUED"
content.- Specified by:
queued
in interfaceResponseWriter
- Parameters:
ignore
- Content to ignore.
-
simpleString
Serializes a char sequence in a simple string format.- Specified by:
simpleString
in interfaceResponseWriter
- Parameters:
value
- The ASCII string to serialize.- See Also:
-
string
Serializes a char sequence in a bulk string format.- Specified by:
string
in interfaceResponseWriter
- Parameters:
value
- The string to serialize.- See Also:
-
string
public void string(byte[] value) Serializes the binary blob in a bulk string format.- Specified by:
string
in interfaceResponseWriter
- Parameters:
value
- The binary blob to serialize.- See Also:
-
integers
Serializes a 64-bit number in the integer format.- Specified by:
integers
in interfaceResponseWriter
- Parameters:
value
- Number to serialize.- See Also:
-
doubles
Serializes a double-precision floating point into the doubles format.- Specified by:
doubles
in interfaceResponseWriter
- Parameters:
value
- The floating point to serialize.- Throws:
IllegalStateException
- in case no serializer is found for the object.- See Also:
-
booleans
public void booleans(boolean value) Serializes a boolean value in the RESP3 format.- Specified by:
booleans
in interfaceResponseWriter
- Parameters:
value
- Boolean value to serialize.- See Also:
-
arrayEmpty
public void arrayEmpty()Serializes a collection in the array format.- Specified by:
arrayEmpty
in interfaceResponseWriter
- Throws:
IllegalStateException
- in case no serializer is found for the object.- See Also:
-
array
Serializes the collection by delegating the serialization of the elements to the provided serializer.- Specified by:
array
in interfaceResponseWriter
- Type Parameters:
T
- The type of the elements in the collection and the serializer handles.- Parameters:
collection
- Collection of elements to serialize.serializer
- Serializer for a single element in the collection.- See Also:
-
array
Serializes a collection in the array format with elements of a specified type.- Specified by:
array
in interfaceResponseWriter
- Parameters:
collection
- Collection of heterogeneous values to serialize.contentType
- The type of elements contained by the sequence.- Throws:
IllegalStateException
- in case no serializer is found for the object.- See Also:
-
emptySet
public void emptySet()Serializes a set in the RESP3 set format.- Specified by:
emptySet
in interfaceResponseWriter
- Throws:
IllegalStateException
- in case no serializer is found for the object.- See Also:
-
set
Serializes a set in the RESP3 set format with elements of a specified type.- Specified by:
set
in interfaceResponseWriter
- Parameters:
set
- Set of heterogeneous values to serialize.contentType
- The type of elements contained by the set.- Throws:
IllegalStateException
- in case no serializer is found for the object.- See Also:
-
map
Serializes a map in the RESP3 map format.- Specified by:
map
in interfaceResponseWriter
- Parameters:
value
- A map with heterogeneous key-value tuples to serialize.- Throws:
IllegalStateException
- in case no serializer is found for the object.- See Also:
-
map
Serializes a map in the RESP3 map format with key and values of the same specified type.- Specified by:
map
in interfaceResponseWriter
- Parameters:
value
- A map with heterogeneous key-value tuples to serialize.contentType
- The type of key and value elements.- Throws:
IllegalStateException
- in case no serializer is found for the object.- See Also:
-
map
Serializes a map in the RESP3 map format with keys and values of a specified format.- Specified by:
map
in interfaceResponseWriter
- Parameters:
value
- A map with heterogeneous key-value tuples to serialize.keyType
- The type of keys in the map.valueType
- The type of values in the map.- Throws:
IllegalStateException
- in case no serializer is found for the object.- See Also:
-
error
Serializes an error message in the RESP3 format.The first character in the error message must be the
'-'
symbol.- Specified by:
error
in interfaceResponseWriter
- Parameters:
value
- An ASCII char sequence with the error message.- Throws:
IllegalStateException
- in case no serializer is found for the object.- See Also:
-
error
Serializes the exception message in the RESP3 error format.- Specified by:
error
in interfaceResponseWriter
- Parameters:
t
- The throwable to serialize.- See Also:
-
write
Writes an object utilizing the specific serializer.Implementors do not need to check for nullability in the implementation. Null response values are handled by native RESP3 serializers before passing the serialization ahead.
- Specified by:
write
in interfaceResponseWriter
- Type Parameters:
T
- The type of the object.- Parameters:
object
- The element to serialize.serializer
- The serializer to utilize.
-
write
Invokes the callback to write a response with the serializer.- Specified by:
write
in interfaceResponseWriter
- Parameters:
serializer
- Serializer to write.
-
serialize
Generic method to serialize an object of unknown type.This method searches all serializers available in the registry.
- Specified by:
serialize
in interfaceResponseWriter
- Parameters:
object
- The object to serialize in RESP3 format.- Throws:
IllegalStateException
- in case no serializer is found for the object.
-
writeNumericPrefix
public void writeNumericPrefix(byte symbol, long number, int additionalWidth) - Specified by:
writeNumericPrefix
in interfaceResponseWriter
-