MySQL 9.1.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
ImmutableStringWithLength Class Reference

The variant with length (ImmutableStringWithLength) stores the length as a Varint128 (similar to protobuf), immediately followed by the string itself. More...

#include <immutable_string.h>

Public Member Functions

 ImmutableStringWithLength ()=default
 
 ImmutableStringWithLength (const char *encoded)
 
std::string_view Decode () const
 
bool operator== (ImmutableStringWithLength other) const
 Compares full contents (data/size). More...
 

Static Public Member Functions

static ImmutableStringWithLength Encode (const char *data, size_t length, char **dst)
 Encode the given string as an ImmutableStringWithLength, and returns a new object pointing to it. More...
 
static size_t RequiredBytesForEncode (size_t length)
 Calculates an upper bound on the space required for encoding a string of the given length. More...
 

Private Attributes

const char * m_ptr = nullptr
 

Detailed Description

The variant with length (ImmutableStringWithLength) stores the length as a Varint128 (similar to protobuf), immediately followed by the string itself.

(There is no zero termination.) This saves space over using e.g. a fixed size_t as length, since most strings are short. This is used for keys in the hash join buffer, but would be applicable other places as well.

Constructor & Destructor Documentation

◆ ImmutableStringWithLength() [1/2]

ImmutableStringWithLength::ImmutableStringWithLength ( )
default

◆ ImmutableStringWithLength() [2/2]

ImmutableStringWithLength::ImmutableStringWithLength ( const char *  encoded)
inlineexplicit

Member Function Documentation

◆ Decode()

std::string_view ImmutableStringWithLength::Decode ( ) const
inline

◆ Encode()

ImmutableStringWithLength ImmutableStringWithLength::Encode ( const char *  data,
size_t  length,
char **  dst 
)
inlinestatic

Encode the given string as an ImmutableStringWithLength, and returns a new object pointing to it.

*dst must contain at least the number of bytes returned by RequiredBytesForEncode.

“dst” is moved to one byte past the end of the written stream.

◆ operator==()

bool ImmutableStringWithLength::operator== ( ImmutableStringWithLength  other) const
inline

Compares full contents (data/size).

◆ RequiredBytesForEncode()

static size_t ImmutableStringWithLength::RequiredBytesForEncode ( size_t  length)
inlinestatic

Calculates an upper bound on the space required for encoding a string of the given length.

Member Data Documentation

◆ m_ptr

const char* ImmutableStringWithLength::m_ptr = nullptr
private

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