Function redis_protocol::resp3_frame_to_resp2[][src]

pub fn resp3_frame_to_resp2(
    frame: Resp3Frame
) -> Result<Resp2Frame, RedisProtocolError>
Expand description

Utility function for converting RESP3 frames back to RESP2 frames.

RESP2 has no concept of attributes, maps, blob errors, or certain other frames. The following policy is used for translating new RESP3 frames back to RESP2:

  • Push - If the Push frame corresponds to a pubsub message then it’s converted to an array, otherwise an error is returned.
  • BlobError - An error is returned since the inner bytes might not be a UTF8 string, or they might be too large for a RESP2 SimpleError.
  • BigNumber - This is converted to a RESP2 BulkString
  • Boolean - This is converted to a BulkString with values of true or false. The associated resp2_frame_to_resp3 function will convert back to Boolean from these values.
  • Double - The inner floating point value is converted to a String and sent as a BulkString.
  • VerbatimString - The inner data is sent as a BulkString. The format is discarded.
  • Set - The inner data is sent as an Array.
  • Map - An error is returned. RESP2 has no concept of a map.
  • Hello - An error is returned. If the caller wants to send Hello it needs to be encoded manually.
  • ChunkedString - An error is returned. RESP2 has no concept of streaming strings.

Calling this with any RESP3 frame with attributes will result in an error.

As seen above the conversion from RESP3 to RESP2 is lossy and error-prone, so callers are encouraged to use resp2_frame_to_resp3 instead by exposing the RESP3 interface up the stack even if RESP2 decoding functions are used.