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 TypeMethodDescriptionvoidarray(Collection<?> collection, Resp3Type contentType) Serializes a collection in the array format with elements of a specified type.<T> voidarray(Collection<T> collection, JavaObjectSerializer<T> serializer) Serializes the collection by delegating the serialization of the elements to the provided serializer.voidSerializes a collection in the array format.voidbooleans(boolean value) Serializes a boolean value in the RESP3 format.voidSerializes a double-precision floating point into the doubles format.voidemptySet()Serializes a set in the RESP3 set format.voiderror(CharSequence value) Serializes an error message in the RESP3 format.voidSerializes the exception message in the RESP3 error format.voidSerializes a 64-bit number in the integer format.voidSerializes a map in the RESP3 map format.voidSerializes a map in the RESP3 map format with key and values of the same specified type.voidSerializes a map in the RESP3 map format with keys and values of a specified format.voidnulls()Writes the null value.voidok()Serializes a simple string with the"OK"content.voidSerializes a simple string with the"QUEUED"content.voidGeneric method to serialize an object of unknown type.voidSerializes a set in the RESP3 set format with elements of a specified type.voidsimpleString(CharSequence value) Serializes a char sequence in a simple string format.voidstring(byte[] value) Serializes the binary blob in a bulk string format.voidstring(CharSequence value) Serializes a char sequence in a bulk string format.<T> voidwrite(JavaObjectSerializer<T> serializer) Invokes the callback to write a response with the serializer.<T> voidwrite(T object, JavaObjectSerializer<T> serializer) Writes an object utilizing the specific serializer.voidwriteNumericPrefix(byte symbol, long number, int additionalWidth) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
nullsin interfaceResponseWriter
-
ok
public void ok()Serializes a simple string with the"OK"content.- Specified by:
okin interfaceResponseWriter
-
queued
Serializes a simple string with the"QUEUED"content.- Specified by:
queuedin interfaceResponseWriter- Parameters:
ignore- Content to ignore.
-
simpleString
Serializes a char sequence in a simple string format.- Specified by:
simpleStringin interfaceResponseWriter- Parameters:
value- The ASCII string to serialize.- See Also:
-
string
Serializes a char sequence in a bulk string format.- Specified by:
stringin 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:
stringin interfaceResponseWriter- Parameters:
value- The binary blob to serialize.- See Also:
-
integers
Serializes a 64-bit number in the integer format.- Specified by:
integersin interfaceResponseWriter- Parameters:
value- Number to serialize.- See Also:
-
doubles
Serializes a double-precision floating point into the doubles format.- Specified by:
doublesin 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:
booleansin interfaceResponseWriter- Parameters:
value- Boolean value to serialize.- See Also:
-
arrayEmpty
public void arrayEmpty()Serializes a collection in the array format.- Specified by:
arrayEmptyin 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:
arrayin 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:
arrayin 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:
emptySetin 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:
setin 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:
mapin 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:
mapin 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:
mapin 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:
errorin 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:
errorin 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:
writein 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:
writein 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:
serializein 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:
writeNumericPrefixin interfaceResponseWriter
-