Blink DB Documentation v1.0.0
Blink DB Documentation
Loading...
Searching...
No Matches
RespEncoder Class Reference

Static Public Member Functions

static std::string simpleString (const std::string &str)
 Converts a simple string to RESP format.
static std::string error (const std::string &message)
 Converts an error message to RESP format.
static std::string integer (int value)
 Used to encode an integer to RESP format.
static std::string bulkString (const std::string &str, const bool isNull)
 Converts a bulk string to RESP format.
static std::string simpleString (const std::string &str)
 Converts a simple string to RESP format.
static std::string error (const std::string &message)
 Converts an error message to RESP format.
static std::string integer (int value)
 Used to encode an integer to RESP format.
static std::string bulkString (const std::string &str, const bool isNull)
 Converts a bulk string to RESP format.

Member Function Documentation

◆ bulkString() [1/2]

std::string RespEncoder::bulkString ( const std::string & str,
const bool isNull )
inlinestatic

Converts a bulk string to RESP format.

Parameters
strthe string to be sent
isNulltrue if the string is null
Returns
std::string

The string is prefixed with a '$' character, followed by the length of the string, and suffixed with a CRLF sequence. If the string is null, it is represented as "$-1\r\n". If the string is empty, it is represented as "$0\r\n\r\n". This is the standard format for bulk strings in RESP. For example, the string "Hello" would be converted to "$5\r\nHello\r\n", and a null string would be converted to "$-1\r\n".

Note
The function handles both null and empty strings appropriately.
The function uses CRLF (Carriage Return Line Feed) as the line

◆ bulkString() [2/2]

std::string RespEncoder::bulkString ( const std::string & str,
const bool isNull )
inlinestatic

Converts a bulk string to RESP format.

Parameters
strthe string to be sent
isNulltrue if the string is null
Returns
std::string

The string is prefixed with a '$' character, followed by the length of the string, and suffixed with a CRLF sequence. If the string is null, it is represented as "$-1\r\n". If the string is empty, it is represented as "$0\r\n\r\n". This is the standard format for bulk strings in RESP. For example, the string "Hello" would be converted to "$5\r\nHello\r\n", and a null string would be converted to "$-1\r\n".

Note
The function handles both null and empty strings appropriately.
The function uses CRLF (Carriage Return Line Feed) as the line

◆ error() [1/2]

std::string RespEncoder::error ( const std::string & message)
inlinestatic

Converts an error message to RESP format.

Parameters
messagethe message to be sent
Returns
std::string respresentation of the error message

The message is prefixed with a '-' character and suffixed with a CRLF sequence. This is the standard format for error messages in RESP. For example, the message "Error occurred" would be converted to "-Error occurred\r\n".

◆ error() [2/2]

std::string RespEncoder::error ( const std::string & message)
inlinestatic

Converts an error message to RESP format.

Parameters
messagethe message to be sent
Returns
std::string respresentation of the error message

The message is prefixed with a '-' character and suffixed with a CRLF sequence. This is the standard format for error messages in RESP. For example, the message "Error occurred" would be converted to "-Error occurred\r\n".

◆ integer() [1/2]

std::string RespEncoder::integer ( int value)
inlinestatic

Used to encode an integer to RESP format.

Parameters
valuethe integer to be sent
Returns
std::string respresentation of the integer

The integer is prefixed with a ':' character and suffixed with a CRLF sequence. This is the standard format for integers in RESP. For example, the integer 42 would be converted to ":42\r\n".

◆ integer() [2/2]

std::string RespEncoder::integer ( int value)
inlinestatic

Used to encode an integer to RESP format.

Parameters
valuethe integer to be sent
Returns
std::string respresentation of the integer

The integer is prefixed with a ':' character and suffixed with a CRLF sequence. This is the standard format for integers in RESP. For example, the integer 42 would be converted to ":42\r\n".

◆ simpleString() [1/2]

std::string RespEncoder::simpleString ( const std::string & str)
inlinestatic

Converts a simple string to RESP format.

Parameters
strthe string to be sent
Returns
std::string respresentation of the string

The string is prefixed with a '+' character and suffixed with a CRLF sequence. This is the standard format for simple strings in RESP. For example, the string "Hello" would be converted to "+Hello\r\n".

◆ simpleString() [2/2]

std::string RespEncoder::simpleString ( const std::string & str)
inlinestatic

Converts a simple string to RESP format.

Parameters
strthe string to be sent
Returns
std::string respresentation of the string

The string is prefixed with a '+' character and suffixed with a CRLF sequence. This is the standard format for simple strings in RESP. For example, the string "Hello" would be converted to "+Hello\r\n".


The documentation for this class was generated from the following files: