0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
StringDecompressorPrefix.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; version 3 of the
9  * 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 this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
27 #ifndef Common_StringDecompressorPrefix_h
28 #define Common_StringDecompressorPrefix_h
29 
30 #include "String.h"
31 
32 namespace Hypertable {
33 
42  public:
45  : m_compressed_len(0) {
46  }
47 
49  virtual void reset() {
50  m_last_string.clear();
51  m_compressed_len = 0;
52  }
53 
60  virtual const uint8_t *add(const uint8_t *next_base) {
61  String str;
62  const uint8_t *next_ptr = next_base;
63  size_t prefix_len = Serialization::decode_vi32(&next_ptr);
64  str = m_last_string.substr(0, prefix_len);
65  size_t suffix_len = strlen((const char *)next_ptr);
66  str.append((const char *)next_ptr);
68  const uint8_t *next = next_ptr + suffix_len + 1;
69  m_compressed_len = (size_t)(next - next_base);
70  return (next_ptr + suffix_len + 1);
71  }
72 
74  virtual size_t length() const {
75  return m_compressed_len;
76  }
77 
79  virtual size_t length_uncompressed() const {
80  return m_last_string.size();
81  }
82 
84  virtual void load(String &str) const {
85  str = m_last_string;
86  }
87 
88  private:
91 
94  };
95 
98 }
99 
100 #endif // Common_StringDecompressorPrefix_h
virtual size_t length() const
Returns the length of the compressed string.
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
A class to decompress prefix-compressed strings.
Po::typed_value< String > * str(String *v=0)
Definition: Properties.h:166
virtual const uint8_t * add(const uint8_t *next_base)
Adds (and decompresses) a compressed string.
size_t m_compressed_len
Length of the compressed string.
virtual void reset()
Resets and clears the internal state.
String m_last_string
The uncompressed string; use load to retrieve it.
StringDecompressorPrefix()
Constructor; creates a new decompressor.
Hypertable definitions
virtual void load(String &str) const
Returns the uncompressed string.
A String class based on std::string.
uint32_t decode_vi32(const uint8_t **bufp, size_t *remainp)
Decode a variable length encoded integer up to 32-bit.
virtual size_t length_uncompressed() const
Returns the length of the uncompressed string.