Class GridRedisProtocolParser
- java.lang.Object
-
- org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser
-
public class GridRedisProtocolParser extends Object
Parser to decode/encode Redis protocol (RESP) requests.
-
-
Field Summary
Fields Modifier and Type Field Description static intERROR_INTError while reading int.
-
Constructor Summary
Constructors Constructor Description GridRedisProtocolParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanensureArrayStart(ByteBuffer buf)Checks first byte isARRAY.static ByteBuffernil()Creates Nil response.static ByteBufferoKString()static StringreadBulkStr(ByteBuffer buf)Reads a bulk string.static intreadInt(ByteBuffer buf)Counts elements in buffer.static ByteBuffertoArray(Collection<Object> vals)Converts a resultant collection response to an array.static ByteBuffertoArray(Map<Object,Object> vals)Converts a resultant map response to an array.static ByteBuffertoBulkString(Object val)Converts a resultant object to a bulk string.static ByteBuffertoGenericError(String errMsg)Creates a generic error response.static ByteBuffertoInteger(int integer)Converts an integer result to a RESP integer.static ByteBuffertoInteger(String integer)Converts an integer result to a RESP integer.static ByteBuffertoOrderedArray(Map<Object,Object> vals, List<?> origin)Converts a resultant map response to an array, the order of elements in the resulting array is defined by the order of elements in theorigincollection.static ByteBuffertoSimpleString(byte[] b)Creates a simple string data as aByteBuffer.static ByteBuffertoSimpleString(String val)Converts a simple string data to aByteBuffer.static ByteBuffertoTypeError(String errMsg)Creates an error response on operation against the wrong data type.
-
-
-
Field Detail
-
ERROR_INT
public static final int ERROR_INT
Error while reading int.-1used to mark null array.- See Also:
NIL, Constant Field Values
-
-
Method Detail
-
ensureArrayStart
public static boolean ensureArrayStart(ByteBuffer buf) throws IgniteCheckedException
Checks first byte isARRAY.- Parameters:
buf- Buffer.- Returns:
Falseif no data available in buffer.- Throws:
IgniteCheckedException- If failed.
-
readBulkStr
public static String readBulkStr(ByteBuffer buf) throws IgniteCheckedException
Reads a bulk string.- Parameters:
buf- Buffer.- Returns:
- Bulk string.
- Throws:
IgniteCheckedException- If failed.
-
readInt
public static int readInt(ByteBuffer buf) throws IgniteCheckedException
Counts elements in buffer.- Parameters:
buf- Buffer.- Returns:
- Count of elements.
- Throws:
IgniteCheckedException
-
toSimpleString
public static ByteBuffer toSimpleString(String val)
Converts a simple string data to aByteBuffer.- Parameters:
val- String to be converted to a simple string.- Returns:
- Redis simple string.
-
toSimpleString
public static ByteBuffer toSimpleString(byte[] b)
Creates a simple string data as aByteBuffer.- Parameters:
b- Bytes for a simple string.- Returns:
- Redis simple string.
-
oKString
public static ByteBuffer oKString()
- Returns:
- Standard OK string.
-
toGenericError
public static ByteBuffer toGenericError(String errMsg)
Creates a generic error response.- Parameters:
errMsg- Error message.- Returns:
- Error response.
-
toTypeError
public static ByteBuffer toTypeError(String errMsg)
Creates an error response on operation against the wrong data type.- Parameters:
errMsg- Error message.- Returns:
- Error response.
-
toInteger
public static ByteBuffer toInteger(String integer)
Converts an integer result to a RESP integer.- Parameters:
integer- Integer result.- Returns:
- REDIS integer.
-
toInteger
public static ByteBuffer toInteger(int integer)
Converts an integer result to a RESP integer.- Parameters:
integer- Integer result.- Returns:
- REDIS integer.
-
nil
public static ByteBuffer nil()
Creates Nil response.- Returns:
- Nil response.
-
toBulkString
public static ByteBuffer toBulkString(Object val)
Converts a resultant object to a bulk string.- Parameters:
val- Object.- Returns:
- Bulk string.
-
toArray
public static ByteBuffer toArray(Map<Object,Object> vals)
Converts a resultant map response to an array.- Parameters:
vals- Map.- Returns:
- Array response.
-
toOrderedArray
public static ByteBuffer toOrderedArray(Map<Object,Object> vals, List<?> origin)
Converts a resultant map response to an array, the order of elements in the resulting array is defined by the order of elements in theorigincollection.- Parameters:
vals- Map.origin- List that defines the order of the resulting array.- Returns:
- Array response.
-
toArray
public static ByteBuffer toArray(Collection<Object> vals)
Converts a resultant collection response to an array.- Parameters:
vals- Array elements.- Returns:
- Array response.
-
-