0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
KeyDecompressorPrefix.cc
Go to the documentation of this file.
1 
22 #include "Common/Compat.h"
23 #include "Common/Serialization.h"
24 
25 #include "KeyDecompressorPrefix.h"
26 
27 using namespace Hypertable;
28 
29 
31  m_bufs[0].clear();
32  m_bufs[1].clear();
33  m_current_base = 0;
35  m_first = false;
36 }
37 
38 const uint8_t *KeyDecompressorPrefix::add(const uint8_t *next_base) {
39  int current = m_first ? 0 : 1;
40  int next = m_first ? 1 : 0;
41  const uint8_t *next_ptr;
42  SerializedKey serkey(next_base);
43  size_t next_length = serkey.decode_length(&next_ptr);
44  uint8_t control = *next_ptr++;
45  size_t remaining = next_length - 1;
46  uint32_t matching = Serialization::decode_vi32(&next_ptr, &remaining);
47 
48  HT_ASSERT(matching <= m_bufs[current].fill());
49  m_bufs[next].clear();
50  m_bufs[next].ensure(8+matching+remaining);
51 
52  Serialization::encode_vi32(&m_bufs[next].ptr, 1+matching+remaining);
53  *(m_bufs[next].ptr)++ = control;
54  if (matching)
55  memcpy(m_bufs[next].ptr, m_current_base, matching);
56  m_current_base = m_bufs[next].ptr;
57  m_bufs[next].ptr += matching;
58  m_bufs[next].add_unchecked(next_ptr, remaining);
60  m_first = !m_first;
61  return next_ptr + remaining;
62 }
63 
64 
66  return m_serialized_key < serialized_key;
67 }
68 
69 
72 }
uint8_t * ptr
Pointer to the end of the used part of the buffer.
#define HT_ASSERT(_e_)
Definition: Logger.h:396
const uint8_t * add(const uint8_t *ptr) override
Compatibility Macros for C/C++.
bool load(const SerializedKey &key)
Parses the opaque key and loads the components into the member variables.
Definition: Key.cc:158
Functions to serialize/deserialize primitives to/from a memory buffer.
const uint8_t * ptr
The pointer to the serialized data.
Definition: ByteString.h:121
Hypertable definitions
void encode_vi32(uint8_t **bufp, uint32_t val)
Encode a integer (up to 32-bit) in variable length encoding.
void clear()
Clears the buffer.
size_t decode_length(const uint8_t **dptr) const
Retrieves the decoded length and returns a pointer to the string.
Definition: ByteString.h:83
Provides access to internal components of opaque key.
Definition: Key.h:40
uint8_t * base
Pointer to the allocated memory buffer.
void ensure(size_t len)
Ensure space for additional data Will grow the space to 1.5 of the needed space with existing data un...
Definition: DynamicBuffer.h:82
uint32_t decode_vi32(const uint8_t **bufp, size_t *remainp)
Decode a variable length encoded integer up to 32-bit.
uint8_t * add_unchecked(const void *data, size_t len)
Adds additional data without boundary checks.
bool less_than(SerializedKey serialized_key) override