1 // Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
2 // This Source Code Form is subject to the terms of the Mozilla Public
3 // License, v. 2.0. If a copy of the MPL was not distributed with this
4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 
6 #ifndef VSOMEIP_V3_SERIALIZER_HPP
7 #define VSOMEIP_V3_SERIALIZER_HPP
8 
9 #include <vector>
10 
11 #include <vsomeip/export.hpp>
12 #include <vsomeip/primitive_types.hpp>
13 
14 namespace vsomeip_v3 {
15 
16 class serializable;
17 
18 class  VSOMEIP_IMPORT_EXPORT serializer {
19 public:
20     serializer(std::uint32_t _buffer_shrink_threshold);
21     virtual ~serializer();
22 
23     bool serialize(const serializable *_from);
24 
25     bool serialize(const uint8_t _value);
26     bool serialize(const uint16_t _value);
27     bool serialize(const uint32_t _value, bool _omit_last_byte = false);
28     bool serialize(const uint8_t *_data, uint32_t _length);
29     bool serialize(const std::vector<byte_t> &_data);
30 
31     virtual const uint8_t * get_data() const;
32     virtual uint32_t get_capacity() const;
33     virtual uint32_t get_size() const;
34 
35     virtual void set_data(uint8_t *_data, uint32_t _capacity);
36 
37     virtual void reset();
38 
39 #ifdef VSOMEIP_DEBUGGING
40     virtual void show();
41 #endif
42 private:
43     std::vector<byte_t> data_;
44     std::uint32_t shrink_count_;
45     std::uint32_t buffer_shrink_threshold_;
46 };
47 
48 } // namespace vsomeip_v3
49 
50 #endif // VSOMEIP_V3_SERIALIZER_IMPL_HPP
51