Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
write-stream.inline.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #ifndef IMPALA_EXEC_OUTPUT_BUFFER_INLINE_H
17 #define IMPALA_EXEC_OUTPUT_BUFFER_INLINE_H
18 
19 #include "exec/write-stream.h"
20 #include "exec/read-write-util.h"
21 
22 #include <stdlib.h>
23 
24 #include "common/names.h"
25 
26 namespace impala {
27 
28 inline int WriteStream::WriteByte(uint8_t val) {
29  return WriteByte(static_cast<char>(val));
30 }
31 
32 inline int WriteStream::WriteByte(char val) {
33  return WriteBytes(1, &val);
34 }
35 
36 inline int WriteStream::WriteVLong(int64_t val) {
37  uint8_t buf[ReadWriteUtil::MAX_VINT_LEN];
38  int size = ReadWriteUtil::PutVLong(val, buf);
39  return WriteBytes(size, buf);
40 }
41 
42 inline int WriteStream::WriteVInt(int32_t val) {
43  uint8_t buf[ReadWriteUtil::MAX_VINT_LEN];
44  int size = ReadWriteUtil::PutVInt(val, buf);
45  return WriteBytes(size, buf);
46 }
47 
48 inline int WriteStream::WriteInt(uint32_t val) {
49  uint8_t buf[sizeof(int32_t)];
50  ReadWriteUtil::PutInt(static_cast<uint8_t*>(buf), val);
51  return WriteBytes(sizeof(int32_t), buf);
52 }
53 
54 inline int WriteStream::WriteZInt(int32_t val) {
55  uint8_t buf[ReadWriteUtil::MAX_ZINT_LEN];
56  int len = ReadWriteUtil::PutZInt(val, buf);
57  return WriteBytes(len, buf);
58 }
59 
60 inline int WriteStream::WriteZLong(int64_t val) {
61  uint8_t buf[ReadWriteUtil::MAX_ZLONG_LEN];
62  int len = ReadWriteUtil::PutZLong(val, buf);
63  return WriteBytes(len, buf);
64 }
65 
66 inline int WriteStream::WriteBytes(int length, const uint8_t* buf) {
67  return WriteBytes(length, reinterpret_cast<const char*>(buf));
68 }
69 
70 inline int WriteStream::WriteBytes(int length, const char* buf) {
71  len_ += length;
72  buffer_.write(buf, length);
73  return length;
74 }
75 
76 inline int WriteStream::WriteText(int length, const uint8_t* buf) {
77  int l = length;
78  l += WriteVInt(length);
79  if (length > 0) WriteBytes(length, buf);
80  return l;
81 }
82 
84  return WriteVInt(0);
85 }
86 
87 inline int WriteStream::WriteBoolean(bool b) {
88  uint8_t val = b ? 1 : 0;
89  return WriteBytes(1, &val);
90 }
91 
92 inline string WriteStream::String() {
93  return buffer_.str();
94 }
95 
96 inline size_t WriteStream::Size() {
97  return len_;
98 }
99 
100 inline void WriteStream::Clear() {
101  len_ = 0;
102  buffer_.str("");
103 }
104 
105 } // namespace impala
106 #endif
int WriteZLong(int64_t val)
int WriteBytes(int length, const uint8_t *buf)
Writes bytes to the buffer, returns the number of bytes written.
static const int MAX_ZINT_LEN
Maximum lengths for Zigzag encodings.
static int PutZInt(int32_t integer, uint8_t *buf)
Put a zigzag encoded integer into a buffer and return its length.
std::stringstream buffer_
TODO consider making this like the parquet writer to avoid extra copy.
Definition: write-stream.h:60
int WriteEmptyText()
Writes an empty string to the buffer (encoded as 1 byte)
int WriteInt(uint32_t val)
static void PutInt(uint8_t *buf, uint16_t integer)
static int64_t PutVLong(int64_t val, uint8_t *buf)
int WriteVInt(int32_t val)
int WriteZInt(int32_t val)
Writes a zig-zag encoded integer.
int WriteBoolean(bool val)
static const int MAX_ZLONG_LEN
int WriteByte(uint8_t val)
int WriteText(int32_t len, const uint8_t *buf)
Writes the length as a VLong follows by the byte string.
std::string String()
returns the contents of this stream as a string
int WriteVLong(int64_t val)
static int64_t PutVInt(int32_t val, uint8_t *buf)
static const int MAX_VINT_LEN
Maximum length for Writeable VInt.
static int PutZLong(int64_t longint, uint8_t *buf)
Put a zigzag encoded long integer into a buffer and return its length.