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_DESERIALIZER_HPP 7 #define VSOMEIP_V3_DESERIALIZER_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 message_impl; 17 18 class deserializer { 19 public: 20 VSOMEIP_EXPORT deserializer(std::uint32_t _buffer_shrink_threshold); 21 VSOMEIP_EXPORT deserializer(byte_t *_data, std::size_t _length, 22 std::uint32_t _buffer_shrink_threshold); 23 VSOMEIP_EXPORT deserializer(const deserializer& _other); 24 VSOMEIP_EXPORT virtual ~deserializer(); 25 26 VSOMEIP_EXPORT void set_data(const byte_t *_data, std::size_t _length); 27 VSOMEIP_EXPORT void append_data(const byte_t *_data, std::size_t _length); 28 VSOMEIP_EXPORT void drop_data(std::size_t _length); 29 30 VSOMEIP_EXPORT std::size_t get_available() const; 31 VSOMEIP_EXPORT std::size_t get_remaining() const; 32 VSOMEIP_EXPORT void set_remaining(std::size_t _remaining); 33 34 // to be used by applications to deserialize a message 35 VSOMEIP_EXPORT message_impl *deserialize_message(); 36 37 // to be used (internally) by objects to deserialize their members 38 // Note: this needs to be encapsulated! 39 VSOMEIP_EXPORT bool deserialize(uint8_t& _value); 40 VSOMEIP_EXPORT bool deserialize(uint16_t& _value); 41 VSOMEIP_EXPORT bool deserialize(uint32_t& _value, 42 bool _omit_last_byte = false); 43 VSOMEIP_EXPORT bool deserialize(uint8_t *_data, std::size_t _length); 44 VSOMEIP_EXPORT bool deserialize(std::string& _target, std::size_t _length); 45 VSOMEIP_EXPORT bool deserialize(std::vector<uint8_t>& _value); 46 47 VSOMEIP_EXPORT bool look_ahead(std::size_t _index, uint8_t &_value) const; 48 VSOMEIP_EXPORT bool look_ahead(std::size_t _index, uint16_t &_value) const; 49 VSOMEIP_EXPORT bool look_ahead(std::size_t _index, uint32_t &_value) const; 50 51 VSOMEIP_EXPORT void reset(); 52 53 #ifdef VSOMEIP_DEBUGGING 54 VSOMEIP_EXPORT void show() const; 55 #endif 56 protected: 57 std::vector<byte_t> data_; 58 std::vector<byte_t>::iterator position_; 59 std::size_t remaining_; 60 private: 61 const std::uint32_t buffer_shrink_threshold_; 62 std::uint32_t shrink_count_; 63 64 }; 65 66 } // namespace vsomeip_v3 67 68 #endif // VSOMEIP_V3_DESERIALIZER_HPP 69