SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
HeaderBufferInfo.cc
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 
8 
9 
10 namespace SWC { namespace Comm {
11 
12 
13 
15  if(_enc != Core::Encoder::Type::PLAIN &&
16  encoder == Core::Encoder::Type::PLAIN &&
17  data.size > 32) { // at least size if encoder not encrypt-type
18 
19  int err = Error::OK;
20  size_t len_enc = 0;
21  DynamicBuffer output;
22  Core::Encoder::encode(err, _enc, data.base, data.size,
23  &len_enc, output, 0, true);
24  if(len_enc) {
25  encoder = _enc;
26  size_plain = data.size;
27  data.set(output);
28  }
29  }
30 
31  size = data.size;
32  chksum = Core::checksum32(data.base, data.size);
33 }
34 
35 void BufferInfo::decode(int& err, StaticBuffer& data) const {
36  if(size_plain) {
37  StaticBuffer decoded_buf(static_cast<size_t>(size_plain));
39  err, encoder,
40  data.base, data.size,
41  decoded_buf.base, size_plain
42  );
43  if(!err)
44  data.set(decoded_buf);
45  }
46 }
47 
48 void BufferInfo::print(std::ostream& out) const {
49  out << " Buffer(sz=" << size
50  << " enc=" << Core::Encoder::to_string(encoder)
51  << " szplain=" << size_plain
52  << " chk=" << chksum << ')';
53 }
54 
55 
56 }}
SWC::Comm::BufferInfo::size_plain
uint32_t size_plain
Buffer set if Encoder not PLAIN.
Definition: HeaderBufferInfo.h:68
SWC::Comm::BufferInfo::encode
SWC_CAN_INLINE void encode(uint8_t **bufp) const
Definition: HeaderBufferInfo.h:44
data
T data
Definition: BitFieldInt.h:1
SWC::Core::Encoder::Type
Type
Definition: Encoder.h:28
SWC::Comm::BufferInfo::chksum
uint32_t chksum
Buffer checksum.
Definition: HeaderBufferInfo.h:69
SWC::Comm::BufferInfo::encoder
Core::Encoder::Type encoder
Buffer Encoder.
Definition: HeaderBufferInfo.h:70
SWC::Error::OK
@ OK
Definition: Error.h:45
SWC::Comm::BufferInfo::size
uint32_t size
Buffer size.
Definition: HeaderBufferInfo.h:67
SWC::Core::Encoder::decode
void decode(int &err, Type encoder, const uint8_t *src, size_t sz_enc, uint8_t *dst, size_t sz)
Definition: Encoder.cc:99
SWC::Core::Buffer::base
value_type * base
Definition: Buffer.h:131
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Core::BufferDyn< StaticBuffer >
SWC::Core::Buffer
Definition: Buffer.h:18
SWC::Comm::BufferInfo::decode
SWC_CAN_INLINE void decode(const uint8_t **bufp, size_t *remainp)
Definition: HeaderBufferInfo.h:53
SWC::Core::checksum32
uint32_t checksum32(const uint8_t *data8, size_t len8) noexcept SWC_ATTRIBS((SWC_ATTRIB_O3))
Definition: Checksum.h:55
HeaderBufferInfo.h
SWC::Comm::BufferInfo::print
void print(std::ostream &out) const
Definition: HeaderBufferInfo.cc:48
SWC::Core::Encoder::to_string
const char *SWC_CONST_FUNC to_string(Type typ) noexcept
Definition: Encoder.cc:31
SWC::Core::Encoder::encode
void encode(int &err, Type encoder, const uint8_t *src, size_t src_sz, size_t *sz_enc, DynamicBuffer &output, uint32_t reserve, bool no_plain_out=false, bool ok_more=false)
Definition: Encoder.cc:222