Storage Engine API
mongo::KeyString::TypeBits Class Reference

Encodes info needed to restore the original BSONTypes from a KeyString. More...

#include <key_string.h>

Detailed Description

Encodes info needed to restore the original BSONTypes from a KeyString.

They cannot be stored in place since we don't want them to affect the ordering (1 and 1.0 compare as equal).

Classes

class  Reader
 

Public Member Functions

 MONGO_STATIC_ASSERT_MSG (kMaxTypeBitsPerDecimal *kMaxDecimalsPerKey< kMaxBytesNeeded *8UL, "encoding needs change to contain all type bits for worst case key")
 
 TypeBits (Version version)
 
void resetFromBuffer (BufReader *reader)
 If there are no bytes remaining, assumes AllZeros. More...
 
bool isAllZeros () const
 If true, no bits have been set to one. More...
 
const uint8_t * getBuffer () const
 These methods return a buffer and size which encodes all of the type bits in this instance. More...
 
size_t getSize () const
 
void reset ()
 
void appendString ()
 
void appendSymbol ()
 
void appendNumberDouble ()
 
void appendNumberInt ()
 
void appendNumberLong ()
 
void appendNumberDecimal ()
 
void appendZero (uint8_t zeroType)
 
void appendDecimalZero (uint32_t whichZero)
 
void appendDecimalExponent (uint8_t storedExponentBits)
 

Static Public Member Functions

static TypeBits fromBuffer (Version version, BufReader *reader)
 

Public Attributes

const Version version
 

Static Public Attributes

static const uint8_t kMaxBytesNeeded = 127
 
static const uint32_t kMaxKeyBytes = 1024
 
static const uint32_t kMaxTypeBitsPerDecimal = 17
 
static const uint32_t kBytesForTypeAndEmptyKey = 2
 
static const uint32_t kMaxDecimalsPerKey
 
static const uint8_t kStoredDecimalExponentBits = 6
 
static const uint32_t kStoredDecimalExponentMask = (1U << kStoredDecimalExponentBits) - 1
 
static const uint8_t kString = 0x0
 
static const uint8_t kSymbol = 0x1
 
static const uint8_t kInt = 0x0
 
static const uint8_t kLong = 0x1
 
static const uint8_t kDouble = 0x2
 
static const uint8_t kDecimal = 0x3
 
static const uint8_t kSpecialZeroPrefix = 0x3
 
static const uint8_t kNegativeDoubleZero = 0x3
 
static const uint8_t kV0NegativeDoubleZero = 0x3
 
static const uint8_t kV1NegativeDoubleZero = 0x18
 
static const uint8_t kUnusedEncoding = 0x19
 
static const uint8_t kDecimalZero0xxx = 0x1a
 
static const uint8_t kDecimalZero1xxx = 0x1b
 
static const uint8_t kDecimalZero2xxx = 0x1c
 
static const uint8_t kDecimalZero3xxx = 0x1d
 
static const uint8_t kDecimalZero4xxx = 0x1e
 
static const uint8_t kDecimalZero5xxx = 0x1f
 

Private Member Functions

uint8_t getSizeByte () const
 size only includes data bytes, not the size byte itself. More...
 
void setSizeByte (uint8_t size)
 
void appendBit (uint8_t oneOrZero)
 

Private Attributes

size_t _curBit
 
bool _isAllZeros
 
uint8_t _buf [1+kMaxBytesNeeded]
 

Constructor & Destructor Documentation

◆ TypeBits()

mongo::KeyString::TypeBits::TypeBits ( Version  version)
inlineexplicit

Member Function Documentation

◆ appendBit()

void mongo::KeyString::TypeBits::appendBit ( uint8_t  oneOrZero)
private

◆ appendDecimalExponent()

void mongo::KeyString::TypeBits::appendDecimalExponent ( uint8_t  storedExponentBits)

◆ appendDecimalZero()

void mongo::KeyString::TypeBits::appendDecimalZero ( uint32_t  whichZero)

◆ appendNumberDecimal()

void mongo::KeyString::TypeBits::appendNumberDecimal ( )
inline

◆ appendNumberDouble()

void mongo::KeyString::TypeBits::appendNumberDouble ( )
inline

◆ appendNumberInt()

void mongo::KeyString::TypeBits::appendNumberInt ( )
inline

◆ appendNumberLong()

void mongo::KeyString::TypeBits::appendNumberLong ( )
inline

◆ appendString()

void mongo::KeyString::TypeBits::appendString ( )
inline

◆ appendSymbol()

void mongo::KeyString::TypeBits::appendSymbol ( )
inline

◆ appendZero()

void mongo::KeyString::TypeBits::appendZero ( uint8_t  zeroType)

◆ fromBuffer()

static TypeBits mongo::KeyString::TypeBits::fromBuffer ( Version  version,
BufReader *  reader 
)
inlinestatic

◆ getBuffer()

const uint8_t* mongo::KeyString::TypeBits::getBuffer ( ) const
inline

These methods return a buffer and size which encodes all of the type bits in this instance.

Encoded format: Case 1 (first byte has high bit set to 1): Remaining bits of first byte encode number of follow-up bytes that are data bytes. Note that _buf is always maintained in this format but these methods may return one of the other formats, if possible, by skipping over the first byte.

Case 2 (first byte is 0x0): This encodes the "AllZeros" state which represents an infinite stream of bits set to 0. Callers may optionally encode this case as an empty buffer if they have another way to mark the end of the buffer. There are no follow-up bytes.

Case 3 (first byte isn't 0x0 but has high bit set to 0): The first byte is the only data byte. This can represent any 7-bit sequence or an 8-bit sequence if the 8th bit is 0, since the 8th bit is the same as the bit that is 1 if the first byte is the size byte. There are no follow-up bytes.

Within data bytes (ie everything excluding the size byte if there is one), bits are packed in from low to high.

◆ getSize()

size_t mongo::KeyString::TypeBits::getSize ( ) const
inline

◆ getSizeByte()

uint8_t mongo::KeyString::TypeBits::getSizeByte ( ) const
inlineprivate

size only includes data bytes, not the size byte itself.

◆ isAllZeros()

bool mongo::KeyString::TypeBits::isAllZeros ( ) const
inline

If true, no bits have been set to one.

This is true if no bits have been set at all.

◆ MONGO_STATIC_ASSERT_MSG()

mongo::KeyString::TypeBits::MONGO_STATIC_ASSERT_MSG ( )

◆ reset()

void mongo::KeyString::TypeBits::reset ( )
inline

◆ resetFromBuffer()

void mongo::KeyString::TypeBits::resetFromBuffer ( BufReader *  reader)

If there are no bytes remaining, assumes AllZeros.

Otherwise, reads bytes out of the BufReader in the format described on the getBuffer() method.

◆ setSizeByte()

void mongo::KeyString::TypeBits::setSizeByte ( uint8_t  size)
inlineprivate

Member Data Documentation

◆ _buf

uint8_t mongo::KeyString::TypeBits::_buf[1+kMaxBytesNeeded]
private

◆ _curBit

size_t mongo::KeyString::TypeBits::_curBit
private

◆ _isAllZeros

bool mongo::KeyString::TypeBits::_isAllZeros
private

◆ kBytesForTypeAndEmptyKey

const uint32_t mongo::KeyString::TypeBits::kBytesForTypeAndEmptyKey = 2
static

◆ kDecimal

const uint8_t mongo::KeyString::TypeBits::kDecimal = 0x3
static

◆ kDecimalZero0xxx

const uint8_t mongo::KeyString::TypeBits::kDecimalZero0xxx = 0x1a
static

◆ kDecimalZero1xxx

const uint8_t mongo::KeyString::TypeBits::kDecimalZero1xxx = 0x1b
static

◆ kDecimalZero2xxx

const uint8_t mongo::KeyString::TypeBits::kDecimalZero2xxx = 0x1c
static

◆ kDecimalZero3xxx

const uint8_t mongo::KeyString::TypeBits::kDecimalZero3xxx = 0x1d
static

◆ kDecimalZero4xxx

const uint8_t mongo::KeyString::TypeBits::kDecimalZero4xxx = 0x1e
static

◆ kDecimalZero5xxx

const uint8_t mongo::KeyString::TypeBits::kDecimalZero5xxx = 0x1f
static

◆ kDouble

const uint8_t mongo::KeyString::TypeBits::kDouble = 0x2
static

◆ kInt

const uint8_t mongo::KeyString::TypeBits::kInt = 0x0
static

◆ kLong

const uint8_t mongo::KeyString::TypeBits::kLong = 0x1
static

◆ kMaxBytesNeeded

const uint8_t mongo::KeyString::TypeBits::kMaxBytesNeeded = 127
static

◆ kMaxDecimalsPerKey

const uint32_t mongo::KeyString::TypeBits::kMaxDecimalsPerKey
static
Initial value:
=
kMaxKeyBytes / (sizeof(Decimal128::Value) + kBytesForTypeAndEmptyKey)

◆ kMaxKeyBytes

const uint32_t mongo::KeyString::TypeBits::kMaxKeyBytes = 1024
static

◆ kMaxTypeBitsPerDecimal

const uint32_t mongo::KeyString::TypeBits::kMaxTypeBitsPerDecimal = 17
static

◆ kNegativeDoubleZero

const uint8_t mongo::KeyString::TypeBits::kNegativeDoubleZero = 0x3
static

◆ kSpecialZeroPrefix

const uint8_t mongo::KeyString::TypeBits::kSpecialZeroPrefix = 0x3
static

◆ kStoredDecimalExponentBits

const uint8_t mongo::KeyString::TypeBits::kStoredDecimalExponentBits = 6
static

◆ kStoredDecimalExponentMask

const uint32_t mongo::KeyString::TypeBits::kStoredDecimalExponentMask = (1U << kStoredDecimalExponentBits) - 1
static

◆ kString

const uint8_t mongo::KeyString::TypeBits::kString = 0x0
static

◆ kSymbol

const uint8_t mongo::KeyString::TypeBits::kSymbol = 0x1
static

◆ kUnusedEncoding

const uint8_t mongo::KeyString::TypeBits::kUnusedEncoding = 0x19
static

◆ kV0NegativeDoubleZero

const uint8_t mongo::KeyString::TypeBits::kV0NegativeDoubleZero = 0x3
static

◆ kV1NegativeDoubleZero

const uint8_t mongo::KeyString::TypeBits::kV1NegativeDoubleZero = 0x18
static

◆ version

const Version mongo::KeyString::TypeBits::version

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