Skip to content

Instantly share code, notes, and snippets.

@vndee
Last active December 3, 2024 15:22
Show Gist options
  • Save vndee/24d5c9b85e21509c06ddb6d94ca66392 to your computer and use it in GitHub Desktop.
Save vndee/24d5c9b85e21509c06ddb6d94ca66392 to your computer and use it in GitHub Desktop.
class RESPObject:
"""
Base class for RESP data types.
Each RESP object maintains both its logical value and metadata about its
wire format representation, enabling efficient parsing and serialization.
"""
type: RESPObjectType
value: Any
bytes_length: int # Length of actual data in bytes
serialized_bytes_length: int # Length including protocol overhead (\r\n etc.)
class RESPSimpleString(RESPObject):
def __init__(self, value: str):
self.type = RESPObjectType.SIMPLE_STRING
self.value = value
class RESPBulkString(RESPObject):
def __init__(self, value: Optional[str], bytes_length: Optional[int] = None):
self.type = RESPObjectType.BULK_STRING
self.value = value
self.bytes_length = bytes_length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment