0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SerializedCellsWriter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Hypertable. If not, see <http://www.gnu.org/licenses/>
18  */
19 
20 #ifndef HYPERTABLE_SERIALIZEDCELLSWRITER_H
21 #define HYPERTABLE_SERIALIZEDCELLSWRITER_H
22 
23 #include "Common/DynamicBuffer.h"
24 
25 #include "Hypertable/Lib/Cell.h"
26 #include "Hypertable/Lib/KeySpec.h"
27 
28 #include "SerializedCellsFlag.h"
29 
30 namespace Hypertable {
31 
33  public:
34 
35  SerializedCellsWriter(int32_t size, bool grow = false)
36  : m_buf(size), m_finalized(false), m_grow(grow),
38 
39  bool add(Cell &cell) {
40  return add(cell.row_key, cell.column_family, cell.column_qualifier,
41  cell.timestamp, cell.value, cell.value_len, cell.flag);
42  }
43 
44  bool add(const char *row, const char *column_family,
45  const char *column_qualifier, int64_t timestamp,
46  const char *value, int32_t value_length,
47  int cell_flag) {
48  return add(row, column_family, column_qualifier, timestamp,
49  (const void *)value, value_length, (uint8_t)cell_flag);
50  }
51 
52  bool add(const char *row, const char *column_family,
53  const char *column_qualifier, int64_t timestamp,
54  const void *value, int32_t value_length,
55  uint8_t cell_flag = FLAG_INSERT);
56 
57  void finalize(uint8_t flag) {
58  if (m_grow)
59  m_buf.ensure(m_buf.empty() ? 5 : 1);
60  if (m_buf.empty())
63  m_finalized = true;
64  }
65 
66  uint8_t *get_buffer() { return m_buf.base; }
67  uint8_t *get_buffer() const { return m_buf.base; }
68  int32_t get_buffer_length() { return m_buf.fill(); }
69  int32_t get_buffer_length() const { return m_buf.fill(); }
70 
71  void get_buffer(const uint8_t **bufp, int32_t *lenp) {
72  if (!m_finalized)
74  *bufp = m_buf.base;
75  *lenp = m_buf.fill();
76  }
77 
78  bool empty() { return m_buf.empty(); }
79 
80  void clear();
81 
82  private:
85  bool m_grow;
88  };
89 
90 }
91 
92 #endif // HYPERTABLE_SERIALIZEDCELLSWRITER_H
bool empty() const
Returns true if the buffer is empty.
Definition: DynamicBuffer.h:73
static const uint32_t FLAG_INSERT
Definition: KeySpec.h:47
const char * column_qualifier
Definition: Cell.h:68
uint8_t * ptr
Pointer to the end of the used part of the buffer.
A dynamic, resizable and reference counted memory buffer.
Definition: DynamicBuffer.h:42
SerializedCellsWriter(int32_t size, bool grow=false)
A dynamic, resizable memory buffer.
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
const char * row_key
Definition: Cell.h:66
void get_buffer(const uint8_t **bufp, int32_t *lenp)
Hypertable definitions
bool add(const char *row, const char *column_family, const char *column_qualifier, int64_t timestamp, const char *value, int32_t value_length, int cell_flag)
const char * column_family
Definition: Cell.h:67
uint8_t * base
Pointer to the allocated memory buffer.
size_t fill() const
Returns the size of the used portion.
Definition: DynamicBuffer.h:70
uint32_t value_len
Definition: Cell.h:72
uint8_t flag
Definition: Cell.h:73
Encapsulates decomposed key and value.
Definition: Cell.h:32
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
const uint8_t * value
Definition: Cell.h:71
int64_t timestamp
Definition: Cell.h:69