client-cpp  0.10.0
LogRecord.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2016 CyberVision, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LOGRECORD_HPP_
18 #define LOGRECORD_HPP_
19 
20 #include <vector>
21 #include <cstdint>
22 
23 #include "kaa/log/gen/LogDefinitions.hpp"
26 
27 namespace kaa {
28 
29 class LogRecord {
30 public:
31  LogRecord(const KaaUserLogRecord& record)
32  {
33  AvroByteArrayConverter<KaaUserLogRecord> converter; // TODO: make converter thread local when it would be possible
34  converter.toByteArray(record, encodedRecord_);
35  }
36 
37  LogRecord(const std::uint8_t *data, size_t size)
38  {
39  if (!data || !size) {
40  throw KaaException("Null serialized log data");
41  }
42 
43  encodedRecord_.assign(data, data + size);
44  }
45 
46  std::vector<std::uint8_t>& getData() { return encodedRecord_; }
47 
48  std::vector<std::uint8_t>&& getRvalueData(){ return std::move(encodedRecord_); }
49 
50  std::size_t getSize() const { return encodedRecord_.size(); }
51 
52 private:
53  std::vector<std::uint8_t> encodedRecord_;
54 };
55 
56 } // namespace kaa
57 
58 #endif /* LOGRECORD_HPP_ */
std::size_t getSize() const
Definition: LogRecord.hpp:50
SharedDataBuffer toByteArray(const T &datum)
LogRecord(const std::uint8_t *data, size_t size)
Definition: LogRecord.hpp:37
LogRecord(const KaaUserLogRecord &record)
Definition: LogRecord.hpp:31
std::vector< std::uint8_t > && getRvalueData()
Definition: LogRecord.hpp:48
std::vector< std::uint8_t > & getData()
Definition: LogRecord.hpp:46