summaryrefslogtreecommitdiff
path: root/implementation/message
diff options
context:
space:
mode:
authorDirk Huss <dirk_huss@mentor.com>2015-11-25 15:11:49 +0100
committerDirk Huss <dirk_huss@mentor.com>2015-11-25 15:11:49 +0100
commit78be04b467566633318a277ccd2d968c1c4e46bf (patch)
tree444ef60cfdca2cc80d584f26911fb08b93a034b9 /implementation/message
parent40d4759f262a86bcebaf3a91d9d813f4d6a3ae10 (diff)
downloadvSomeIP-78be04b467566633318a277ccd2d968c1c4e46bf.tar.gz
vSomeIP 2.0.02.0.0
Diffstat (limited to 'implementation/message')
-rw-r--r--implementation/message/include/message_header_impl.hpp6
-rw-r--r--implementation/message/src/deserializer.cpp202
-rw-r--r--implementation/message/src/message_base_impl.cpp46
-rw-r--r--implementation/message/src/message_header_impl.cpp87
-rw-r--r--implementation/message/src/message_impl.cpp26
-rw-r--r--implementation/message/src/payload_impl.cpp42
-rw-r--r--implementation/message/src/serializer.cpp128
7 files changed, 271 insertions, 266 deletions
diff --git a/implementation/message/include/message_header_impl.hpp b/implementation/message/include/message_header_impl.hpp
index 1d3e70b..b233d75 100644
--- a/implementation/message/include/message_header_impl.hpp
+++ b/implementation/message/include/message_header_impl.hpp
@@ -9,7 +9,7 @@
#include <vsomeip/export.hpp>
#include <vsomeip/primitive_types.hpp>
#include <vsomeip/enumeration_types.hpp>
-#include <vsomeip/serializable.hpp>
+#include <vsomeip/internal/serializable.hpp>
namespace vsomeip {
@@ -20,8 +20,8 @@ public:
VSOMEIP_EXPORT message_header_impl();
VSOMEIP_EXPORT message_header_impl(const message_header_impl& header);
- VSOMEIP_EXPORT virtual bool serialize(serializer *_to) const;
- VSOMEIP_EXPORT virtual bool deserialize(deserializer *_from);
+ VSOMEIP_EXPORT bool serialize(serializer *_to) const;
+ VSOMEIP_EXPORT bool deserialize(deserializer *_from);
// internal
VSOMEIP_EXPORT message_base * get_owner() const;
diff --git a/implementation/message/src/deserializer.cpp b/implementation/message/src/deserializer.cpp
index fb9cde6..6017d5a 100644
--- a/implementation/message/src/deserializer.cpp
+++ b/implementation/message/src/deserializer.cpp
@@ -9,7 +9,7 @@
#include <iomanip>
#include <sstream>
-#include <vsomeip/logger.hpp>
+#include "../../logging/include/logger.hpp"
#endif
#include "../include/message_impl.hpp"
@@ -19,186 +19,186 @@
namespace vsomeip {
deserializer::deserializer()
- : position_(data_.begin()),
- remaining_(0) {
+ : position_(data_.begin()),
+ remaining_(0) {
}
deserializer::deserializer(byte_t *_data, std::size_t _length)
- : data_(_data, _data + _length),
- position_(data_.begin()),
- remaining_(_length) {
+ : data_(_data, _data + _length),
+ position_(data_.begin()),
+ remaining_(_length) {
}
deserializer::deserializer(const deserializer &_other)
- : data_(_other.data_),
- position_(_other.position_){
+ : data_(_other.data_),
+ position_(_other.position_){
}
deserializer::~deserializer() {
}
std::size_t deserializer::get_available() const {
- return data_.size();
+ return data_.size();
}
std::size_t deserializer::get_remaining() const {
- return remaining_;
+ return remaining_;
}
void deserializer::set_remaining(std::size_t _remaining) {
- remaining_ = _remaining;
+ remaining_ = _remaining;
}
bool deserializer::deserialize(uint8_t& _value) {
- if (0 == remaining_)
- return false;
+ if (0 == remaining_)
+ return false;
- _value = *position_++;
+ _value = *position_++;
- remaining_--;
- return true;
+ remaining_--;
+ return true;
}
bool deserializer::deserialize(uint16_t& _value) {
- if (2 > remaining_)
- return false;
+ if (2 > remaining_)
+ return false;
- uint8_t byte0, byte1;
- byte0 = *position_++;
- byte1 = *position_++;
- remaining_ -= 2;
+ uint8_t byte0, byte1;
+ byte0 = *position_++;
+ byte1 = *position_++;
+ remaining_ -= 2;
- _value = VSOMEIP_BYTES_TO_WORD(byte0, byte1);
+ _value = VSOMEIP_BYTES_TO_WORD(byte0, byte1);
- return true;
+ return true;
}
bool deserializer::deserialize(uint32_t &_value, bool _omit_last_byte) {
- if (3 > remaining_ || (!_omit_last_byte && 4 > remaining_))
- return false;
+ if (3 > remaining_ || (!_omit_last_byte && 4 > remaining_))
+ return false;
- uint8_t byte0 = 0, byte1, byte2, byte3;
- if (!_omit_last_byte) {
- byte0 = *position_++;
- remaining_--;
- }
- byte1 = *position_++;
- byte2 = *position_++;
- byte3 = *position_++;
- remaining_ -= 3;
+ uint8_t byte0 = 0, byte1, byte2, byte3;
+ if (!_omit_last_byte) {
+ byte0 = *position_++;
+ remaining_--;
+ }
+ byte1 = *position_++;
+ byte2 = *position_++;
+ byte3 = *position_++;
+ remaining_ -= 3;
- _value = VSOMEIP_BYTES_TO_LONG(
- byte0, byte1, byte2, byte3);
+ _value = VSOMEIP_BYTES_TO_LONG(
+ byte0, byte1, byte2, byte3);
- return true;
+ return true;
}
bool deserializer::deserialize(uint8_t *_data, std::size_t _length) {
- if (_length > remaining_)
- return false;
+ if (_length > remaining_)
+ return false;
- std::memcpy(_data, &data_[position_ - data_.begin()], _length);
- position_ += _length;
- remaining_ -= _length;
+ std::memcpy(_data, &data_[position_ - data_.begin()], _length);
+ position_ += _length;
+ remaining_ -= _length;
- return true;
+ return true;
}
bool deserializer::deserialize(std::vector< uint8_t >& _value) {
- if (_value.capacity() > remaining_)
- return false;
+ if (_value.capacity() > remaining_)
+ return false;
- _value.assign(position_, position_ + _value.capacity());
- position_ += _value.capacity();
- remaining_ -= _value.capacity();
+ _value.assign(position_, position_ + _value.capacity());
+ position_ += _value.capacity();
+ remaining_ -= _value.capacity();
- return true;
+ return true;
}
bool deserializer::look_ahead(std::size_t _index, uint8_t &_value) const {
- if (_index >= data_.size())
- return false;
+ if (_index >= data_.size())
+ return false;
- _value = *(position_ + _index);
+ _value = *(position_ + _index);
- return true;
+ return true;
}
bool deserializer::look_ahead(std::size_t _index, uint16_t &_value) const {
- if (_index+1 >= data_.size())
- return false;
+ if (_index+1 >= data_.size())
+ return false;
- std::vector< uint8_t >::iterator i = position_ + _index;
- _value = VSOMEIP_BYTES_TO_WORD(*i, *(i+1));
+ std::vector< uint8_t >::iterator i = position_ + _index;
+ _value = VSOMEIP_BYTES_TO_WORD(*i, *(i+1));
- return true;
+ return true;
}
bool deserializer::look_ahead(std::size_t _index, uint32_t &_value) const {
- if (_index+3 >= data_.size())
- return false;
+ if (_index+3 >= data_.size())
+ return false;
- std::vector< uint8_t >::const_iterator i = position_ + _index;
- _value = VSOMEIP_BYTES_TO_LONG(*i, *(i+1), *(i+2), *(i+3));
+ std::vector< uint8_t >::const_iterator i = position_ + _index;
+ _value = VSOMEIP_BYTES_TO_LONG(*i, *(i+1), *(i+2), *(i+3));
- return true;
+ return true;
}
message * deserializer::deserialize_message() {
- message_impl* deserialized_message = new message_impl;
- if (0 != deserialized_message) {
- if (false == deserialized_message->deserialize(this)) {
- delete deserialized_message;
- deserialized_message = 0;
- }
- }
+ message_impl* deserialized_message = new message_impl;
+ if (0 != deserialized_message) {
+ if (false == deserialized_message->deserialize(this)) {
+ delete deserialized_message;
+ deserialized_message = 0;
+ }
+ }
- return deserialized_message;
+ return deserialized_message;
}
void deserializer::set_data(const byte_t *_data, std::size_t _length) {
- if (0 != _data) {
- data_.assign(_data, _data + _length);
- position_ = data_.begin();
- remaining_ = data_.end() - position_;
- } else {
- data_.clear();
- position_ = data_.end();
- remaining_ = 0;
- }
+ if (0 != _data) {
+ data_.assign(_data, _data + _length);
+ position_ = data_.begin();
+ remaining_ = data_.end() - position_;
+ } else {
+ data_.clear();
+ position_ = data_.end();
+ remaining_ = 0;
+ }
}
void deserializer::append_data(const byte_t *_data, std::size_t _length) {
- std::size_t offset = (position_ - data_.begin());
- data_.insert(data_.end(), _data, _data + _length);
- position_ = data_.begin() + offset;
- remaining_ += _length;
+ std::size_t offset = (position_ - data_.begin());
+ data_.insert(data_.end(), _data, _data + _length);
+ position_ = data_.begin() + offset;
+ remaining_ += _length;
}
void deserializer::drop_data(std::size_t _length) {
- if (position_ + _length < data_.end())
- position_ += _length;
- else
- position_ = data_.end();
+ if (position_ + _length < data_.end())
+ position_ += _length;
+ else
+ position_ = data_.end();
}
void deserializer::reset() {
- data_.erase(data_.begin(), position_);
- position_ = data_.begin();
- remaining_ = data_.size();
+ data_.erase(data_.begin(), position_);
+ position_ = data_.begin();
+ remaining_ = data_.size();
}
#ifdef VSOMEIP_DEBUGGING
void deserializer::show() const {
- std::stringstream its_message;
- its_message << "("
- << std::hex << std::setw(2) << std::setfill('0')
- << (int)*position_ << ", "
- << std:: dec << remaining_ << ") ";
- for (int i = 0; i < data_.size(); ++i)
- its_message << std::hex << std::setw(2) << std::setfill('0')
- << (int)data_[i] << " ";
- VSOMEIP_DEBUG << its_message;
+ std::stringstream its_message;
+ its_message << "("
+ << std::hex << std::setw(2) << std::setfill('0')
+ << (int)*position_ << ", "
+ << std:: dec << remaining_ << ") ";
+ for (int i = 0; i < data_.size(); ++i)
+ its_message << std::hex << std::setw(2) << std::setfill('0')
+ << (int)data_[i] << " ";
+ VSOMEIP_DEBUG << its_message;
}
#endif
diff --git a/implementation/message/src/message_base_impl.cpp b/implementation/message/src/message_base_impl.cpp
index c5ab95a..616ed63 100644
--- a/implementation/message/src/message_base_impl.cpp
+++ b/implementation/message/src/message_base_impl.cpp
@@ -10,7 +10,7 @@ namespace vsomeip {
message_base_impl::message_base_impl()
: is_reliable_(false) {
- header_.set_owner(this);
+ header_.set_owner(this);
}
message_base_impl::~message_base_impl() {
@@ -18,88 +18,88 @@ message_base_impl::~message_base_impl() {
// header interface
message_t message_base_impl::get_message() const {
- return VSOMEIP_WORDS_TO_LONG(header_.service_, header_.method_);
+ return VSOMEIP_WORDS_TO_LONG(header_.service_, header_.method_);
}
void message_base_impl::set_message(message_t _message) {
- header_.service_ = VSOMEIP_LONG_WORD0(_message);
- header_.method_ = VSOMEIP_LONG_WORD1(_message);
+ header_.service_ = VSOMEIP_LONG_WORD0(_message);
+ header_.method_ = VSOMEIP_LONG_WORD1(_message);
}
service_t message_base_impl::get_service() const {
- return header_.service_;
+ return header_.service_;
}
void message_base_impl::set_service(service_t _service) {
- header_.service_ = _service;
+ header_.service_ = _service;
}
instance_t message_base_impl::get_instance() const {
- return header_.instance_;
+ return header_.instance_;
}
void message_base_impl::set_instance(instance_t _instance) {
- header_.instance_ = _instance;
+ header_.instance_ = _instance;
}
method_t message_base_impl::get_method() const {
- return header_.method_;
+ return header_.method_;
}
void message_base_impl::set_method(method_t _method) {
- header_.method_ = _method;
+ header_.method_ = _method;
}
request_t message_base_impl::get_request() const {
- return VSOMEIP_WORDS_TO_LONG(header_.client_, header_.session_);
+ return VSOMEIP_WORDS_TO_LONG(header_.client_, header_.session_);
}
client_t message_base_impl::get_client() const {
- return header_.client_;
+ return header_.client_;
}
void message_base_impl::set_client(client_t _client) {
- header_.client_ = _client;
+ header_.client_ = _client;
}
session_t message_base_impl::get_session() const {
- return header_.session_;
+ return header_.session_;
}
void message_base_impl::set_session(session_t _session) {
- header_.session_ = _session;
+ header_.session_ = _session;
}
protocol_version_t message_base_impl::get_protocol_version() const {
- return header_.protocol_version_;
+ return header_.protocol_version_;
}
void message_base_impl::set_protocol_version(protocol_version_t _protocol_version) {
- header_.protocol_version_ = _protocol_version;
+ header_.protocol_version_ = _protocol_version;
}
interface_version_t message_base_impl::get_interface_version() const {
- return header_.interface_version_;
+ return header_.interface_version_;
}
void message_base_impl::set_interface_version(interface_version_t _interface_version) {
- header_.interface_version_ = _interface_version;
+ header_.interface_version_ = _interface_version;
}
message_type_e message_base_impl::get_message_type() const {
- return header_.type_;
+ return header_.type_;
}
void message_base_impl::set_message_type(message_type_e _type) {
- header_.type_ = _type;
+ header_.type_ = _type;
}
return_code_e message_base_impl::get_return_code() const {
- return header_.code_;
+ return header_.code_;
}
void message_base_impl::set_return_code(return_code_e _code) {
- header_.code_ = _code;
+ header_.code_ = _code;
}
bool message_base_impl::is_reliable() const {
diff --git a/implementation/message/src/message_header_impl.cpp b/implementation/message/src/message_header_impl.cpp
index 1bde36c..39446b7 100644
--- a/implementation/message/src/message_header_impl.cpp
+++ b/implementation/message/src/message_header_impl.cpp
@@ -13,66 +13,69 @@
namespace vsomeip {
message_header_impl::message_header_impl()
- : service_(0x0), instance_(0x0), method_(0x0),
- client_(0x0), session_(0x0),
- protocol_version_(0x1), interface_version_(0x0),
- type_(message_type_e::MT_UNKNOWN),
- code_(return_code_e::E_UNKNOWN) {
+ : service_(0x0), method_(0x0),
+ client_(0x0), session_(0x0),
+ protocol_version_(0x1), interface_version_(0x0),
+ type_(message_type_e::MT_UNKNOWN),
+ code_(return_code_e::E_UNKNOWN),
+ instance_(0x0) {
};
-message_header_impl::message_header_impl(const message_header_impl& _header)
- : service_(_header.service_), instance_(_header.instance_), method_(_header.method_),
- client_(_header.client_), session_(_header.session_),
- protocol_version_(_header.protocol_version_), interface_version_(_header.interface_version_),
- type_(_header.type_),
- code_(_header.code_) {
+message_header_impl::message_header_impl(const message_header_impl &_header)
+ : service_(_header.service_), method_(_header.method_),
+ client_(_header.client_), session_(_header.session_),
+ protocol_version_(_header.protocol_version_),
+ interface_version_(_header.interface_version_),
+ type_(_header.type_),
+ code_(_header.code_),
+ instance_(_header.instance_) {
};
bool message_header_impl::serialize(serializer *_to) const {
- return (0 != _to
- && _to->serialize(service_)
- && _to->serialize(method_)
- && _to->serialize(owner_->get_length())
- && _to->serialize(client_)
- && _to->serialize(session_)
- && _to->serialize(protocol_version_)
- && _to->serialize(interface_version_)
- && _to->serialize(static_cast<uint8_t>(type_))
- && _to->serialize(static_cast<uint8_t>(code_)));
+ return (0 != _to
+ && _to->serialize(service_)
+ && _to->serialize(method_)
+ && _to->serialize(owner_->get_length())
+ && _to->serialize(client_)
+ && _to->serialize(session_)
+ && _to->serialize(protocol_version_)
+ && _to->serialize(interface_version_)
+ && _to->serialize(static_cast<uint8_t>(type_))
+ && _to->serialize(static_cast<uint8_t>(code_)));
};
bool message_header_impl::deserialize(deserializer *_from) {
- bool is_successful;
+ bool is_successful;
- uint8_t tmp_message_type, tmp_return_code;
- uint32_t tmp_length;
+ uint8_t tmp_message_type, tmp_return_code;
+ uint32_t tmp_length;
- is_successful = (0 != _from
- && _from->deserialize(service_)
- && _from->deserialize(method_)
- && _from->deserialize(tmp_length)
- && _from->deserialize(client_)
- && _from->deserialize(session_)
- && _from->deserialize(protocol_version_)
- && _from->deserialize(interface_version_)
- && _from->deserialize(tmp_message_type)
- && _from->deserialize(tmp_return_code));
+ is_successful = (0 != _from
+ && _from->deserialize(service_)
+ && _from->deserialize(method_)
+ && _from->deserialize(tmp_length)
+ && _from->deserialize(client_)
+ && _from->deserialize(session_)
+ && _from->deserialize(protocol_version_)
+ && _from->deserialize(interface_version_)
+ && _from->deserialize(tmp_message_type)
+ && _from->deserialize(tmp_return_code));
- if (is_successful) {
- type_ = static_cast< message_type_e >(tmp_message_type);
- code_ = static_cast< return_code_e >(tmp_return_code);
- length_ = static_cast< length_t >(tmp_length - VSOMEIP_SOMEIP_HEADER_SIZE);
- }
+ if (is_successful) {
+ type_ = static_cast< message_type_e >(tmp_message_type);
+ code_ = static_cast< return_code_e >(tmp_return_code);
+ length_ = static_cast< length_t >(tmp_length - VSOMEIP_SOMEIP_HEADER_SIZE);
+ }
- return is_successful;
+ return is_successful;
};
message_base * message_header_impl::get_owner() const {
- return owner_;
+ return owner_;
}
void message_header_impl::set_owner(message_base *_owner) {
- owner_ = _owner;
+ owner_ = _owner;
}
} // namespace vsomeip
diff --git a/implementation/message/src/message_impl.cpp b/implementation/message/src/message_impl.cpp
index 51596a0..c19ae76 100644
--- a/implementation/message/src/message_impl.cpp
+++ b/implementation/message/src/message_impl.cpp
@@ -20,31 +20,31 @@ message_impl::~message_impl() {
}
length_t message_impl::get_length() const {
- return (VSOMEIP_SOMEIP_HEADER_SIZE
- + (payload_ ? payload_->get_length() : 0));
+ return (VSOMEIP_SOMEIP_HEADER_SIZE
+ + (payload_ ? payload_->get_length() : 0));
}
std::shared_ptr< payload > message_impl::get_payload() const {
- return payload_;
+ return payload_;
}
void message_impl::set_payload(std::shared_ptr< payload > _payload) {
- payload_ = _payload;
+ payload_ = _payload;
}
bool message_impl::serialize(serializer *_to) const {
- return (header_.serialize(_to)
- && (payload_ ? payload_->serialize(_to) : true));
+ return (header_.serialize(_to)
+ && (payload_ ? payload_->serialize(_to) : true));
}
bool message_impl::deserialize(deserializer *_from) {
- payload_ = runtime::get()->create_payload();
- bool is_successful = header_.deserialize(_from);
- if (is_successful) {
- payload_->set_capacity(header_.length_);
- is_successful = payload_->deserialize(_from);
- }
- return is_successful;
+ payload_ = runtime::get()->create_payload();
+ bool is_successful = header_.deserialize(_from);
+ if (is_successful) {
+ payload_->set_capacity(header_.length_);
+ is_successful = payload_->deserialize(_from);
+ }
+ return is_successful;
}
} // namespace vsomeip
diff --git a/implementation/message/src/payload_impl.cpp b/implementation/message/src/payload_impl.cpp
index 62e48e0..3355788 100644
--- a/implementation/message/src/payload_impl.cpp
+++ b/implementation/message/src/payload_impl.cpp
@@ -10,66 +10,66 @@
namespace vsomeip {
payload_impl::payload_impl()
- : data_() {
+ : data_() {
}
payload_impl::payload_impl(const byte_t *_data, uint32_t _size) {
- data_.assign(_data, _data + _size);
+ data_.assign(_data, _data + _size);
}
payload_impl::payload_impl(const std::vector<byte_t> &_data)
- : data_(_data) {
+ : data_(_data) {
}
payload_impl::payload_impl(const payload_impl& _payload)
- : data_(_payload.data_) {
+ : data_(_payload.data_) {
}
payload_impl::~payload_impl() {
}
bool payload_impl::operator==(const payload &_other) {
- bool is_equal(true);
- try {
- const payload_impl &other = dynamic_cast< const payload_impl & >(_other);
- is_equal = (data_ == other.data_);
- }
- catch (...) {
- is_equal = false;
- }
- return is_equal;
+ bool is_equal(true);
+ try {
+ const payload_impl &other = dynamic_cast< const payload_impl & >(_other);
+ is_equal = (data_ == other.data_);
+ }
+ catch (...) {
+ is_equal = false;
+ }
+ return is_equal;
}
byte_t * payload_impl::get_data() {
- return data_.data();
+ return data_.data();
}
const byte_t * payload_impl::get_data() const {
- return data_.data();
+ return data_.data();
}
length_t payload_impl::get_length() const {
- return data_.size();
+ return length_t(data_.size());
}
void payload_impl::set_capacity(length_t _capacity) {
- data_.reserve(_capacity);
+ data_.reserve(_capacity);
}
void payload_impl::set_data(const byte_t *_data, const length_t _length) {
- data_.assign(_data, _data + _length);
+ data_.assign(_data, _data + _length);
}
void payload_impl::set_data(const std::vector< byte_t > &_data) {
- data_ = _data;
+ data_ = _data;
}
bool payload_impl::serialize(serializer *_to) const {
- return (0 != _to && _to->serialize(data_.data(), data_.size()));
+ return (0 != _to && _to->serialize(data_.data(), uint32_t(data_.size())));
}
bool payload_impl::deserialize(deserializer *_from) {
- return (0 != _from && _from->deserialize(data_));
+ return (0 != _from && _from->deserialize(data_));
}
} // namespace vsomeip
diff --git a/implementation/message/src/serializer.cpp b/implementation/message/src/serializer.cpp
index cfa32ec..6c064ab 100644
--- a/implementation/message/src/serializer.cpp
+++ b/implementation/message/src/serializer.cpp
@@ -9,10 +9,10 @@
#include <iomanip>
#include <sstream>
-#include <vsomeip/logger.hpp>
+#include "../../logging/include/logger.hpp"
#endif
-#include <vsomeip/serializable.hpp>
+#include <vsomeip/internal/serializable.hpp>
#include "../include/serializer.hpp"
#include "../../utility/include/byteorder.hpp"
@@ -20,115 +20,117 @@
namespace vsomeip {
serializer::serializer()
- : data_(0), capacity_(0), position_(0), remaining_(0) {
+ : data_(0), capacity_(0), position_(0), remaining_(0) {
}
serializer::~serializer() {
+ if (0 != data_)
+ delete [] data_;
};
bool serializer::serialize(const serializable *_from) {
- return (_from && _from->serialize(this));
+ return (_from && _from->serialize(this));
}
bool serializer::serialize(const uint8_t _value) {
- if (1 > remaining_)
- return false;
+ if (1 > remaining_)
+ return false;
- *position_++ = _value;
- remaining_--;
+ *position_++ = _value;
+ remaining_--;
- return true;
+ return true;
}
bool serializer::serialize(const uint16_t _value) {
- if (2 > remaining_)
- return false;
+ if (2 > remaining_)
+ return false;
- *position_++ = VSOMEIP_WORD_BYTE1(_value);
- *position_++ = VSOMEIP_WORD_BYTE0(_value);
- remaining_ -= 2;
+ *position_++ = VSOMEIP_WORD_BYTE1(_value);
+ *position_++ = VSOMEIP_WORD_BYTE0(_value);
+ remaining_ -= 2;
- return true;
+ return true;
}
bool serializer::serialize(const uint32_t _value, bool _omit_last_byte) {
- if (3 > remaining_ || (!_omit_last_byte && 4 > remaining_))
- return false;
-
- if (!_omit_last_byte) {
- *position_++ = VSOMEIP_LONG_BYTE3(_value);
- remaining_--;
- }
- *position_++ = VSOMEIP_LONG_BYTE2(_value);
- *position_++ = VSOMEIP_LONG_BYTE1(_value);
- *position_++ = VSOMEIP_LONG_BYTE0(_value);
- remaining_ -= 3;
-
- return true;
+ if (3 > remaining_ || (!_omit_last_byte && 4 > remaining_))
+ return false;
+
+ if (!_omit_last_byte) {
+ *position_++ = VSOMEIP_LONG_BYTE3(_value);
+ remaining_--;
+ }
+ *position_++ = VSOMEIP_LONG_BYTE2(_value);
+ *position_++ = VSOMEIP_LONG_BYTE1(_value);
+ *position_++ = VSOMEIP_LONG_BYTE0(_value);
+ remaining_ -= 3;
+
+ return true;
}
bool serializer::serialize(const uint8_t *_data, uint32_t _length) {
- if (_length > remaining_)
- return false;
+ if (_length > remaining_)
+ return false;
- ::memcpy(position_, _data, _length);
- position_ += _length;
- remaining_ -= _length;
+ ::memcpy(position_, _data, _length);
+ position_ += _length;
+ remaining_ -= _length;
- return true;
+ return true;
}
byte_t * serializer::get_data() const {
- return data_;
+ return data_;
}
uint32_t serializer::get_capacity() const {
- return capacity_;
+ return capacity_;
}
uint32_t serializer::get_size() const {
- return capacity_ - remaining_;
+ return capacity_ - remaining_;
}
void serializer::create_data(uint32_t _capacity) {
- if (0 != data_)
- delete [] data_;
-
- data_ = new byte_t[_capacity];
- position_ = data_;
- if (0 != data_) {
- capacity_ = remaining_ = _capacity;
- } else {
- capacity_ = remaining_ = 0;
- }
+ if (0 != data_)
+ delete [] data_;
+
+ data_ = new byte_t[_capacity];
+ position_ = data_;
+ if (0 != data_) {
+ capacity_ = remaining_ = _capacity;
+ } else {
+ capacity_ = remaining_ = 0;
+ }
}
void serializer::set_data(byte_t *_data, uint32_t _capacity) {
- delete [] data_;
+ delete [] data_;
- data_ = _data;
- position_ = _data;
+ data_ = _data;
+ position_ = _data;
- if (0 != data_) {
- capacity_ = remaining_ = _capacity;
- } else {
- capacity_ = remaining_ = 0;
- }
+ if (0 != data_) {
+ capacity_ = remaining_ = _capacity;
+ } else {
+ capacity_ = remaining_ = 0;
+ }
}
void serializer::reset() {
- position_ = data_;
- remaining_ = capacity_;
+ position_ = data_;
+ remaining_ = capacity_;
}
#ifdef VSOMEIP_DEBUGGING
void serializer::show() {
- std::stringstream its_data;
- its_data << "SERIALIZED: ";
- for (int i = 0; i < position_ - data_; ++i)
- its_data << std::setw(2) << std::setfill('0')
- << std::hex << (int)data_[i];
- VSOMEIP_DEBUG << its_data.str();
+ std::stringstream its_data;
+ its_data << "SERIALIZED: ";
+ for (int i = 0; i < position_ - data_; ++i)
+ its_data << std::setw(2) << std::setfill('0')
+ << std::hex << (int)data_[i];
+ VSOMEIP_DEBUG << its_data.str();
}
#endif