Skip to content

Commit

Permalink
Changed writing of constants (small letters now).
Browse files Browse the repository at this point in the history
Fixed deserializing of byte arrays.
  • Loading branch information
lutzbichler committed Jul 22, 2014
1 parent dfad8d7 commit 9f89671
Show file tree
Hide file tree
Showing 26 changed files with 175 additions and 138 deletions.
2 changes: 1 addition & 1 deletion examples/client-sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class client_sample {
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));

app_->register_message_handler(
vsomeip::VSOMEIP_ANY_SERVICE, SAMPLE_INSTANCE_ID, vsomeip::VSOMEIP_ANY_METHOD,
vsomeip::any_service, SAMPLE_INSTANCE_ID, vsomeip::any_method,
std::bind(&client_sample::on_message,
this,
std::placeholders::_1));
Expand Down
9 changes: 5 additions & 4 deletions implementation/configuration/src/configuration_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "../include/servicegroup.hpp"
#include "../include/service.hpp"
#include "../../logging/include/logger_impl.hpp"
#include "../../service_discovery/include/defines.hpp"

namespace vsomeip {
namespace cfg {
Expand Down Expand Up @@ -237,7 +238,7 @@ bool configuration_impl::get_service_configuration(std::shared_ptr< servicegroup
bool use_magic_cookies(false);

std::shared_ptr< service > its_service(std::make_shared< service >());
its_service->reliable_ = its_service->unreliable_ = VSOMEIP_ILLEGAL_PORT;
its_service->reliable_ = its_service->unreliable_ = illegal_port;
its_service->use_magic_cookies_ = false;

its_service->group_ = _group;
Expand Down Expand Up @@ -535,7 +536,7 @@ std::string configuration_impl::get_address(service_t _service, instance_t _inst
}

uint16_t configuration_impl::get_reliable_port(service_t _service, instance_t _instance) const {
uint16_t its_reliable = VSOMEIP_ILLEGAL_PORT;
uint16_t its_reliable = illegal_port;

service *its_service = find_service(_service, _instance);
if (its_service) its_reliable = its_service->reliable_;
Expand All @@ -556,7 +557,7 @@ bool configuration_impl::has_enabled_magic_cookies(std::string _address, uint16_
}

uint16_t configuration_impl::get_unreliable_port(service_t _service, instance_t _instance) const {
uint16_t its_unreliable = VSOMEIP_ILLEGAL_PORT;
uint16_t its_unreliable = illegal_port;

service *its_service = find_service(_service, _instance);
if (its_service) its_unreliable = its_service->unreliable_;
Expand All @@ -565,7 +566,7 @@ uint16_t configuration_impl::get_unreliable_port(service_t _service, instance_t
}

std::string configuration_impl::get_multicast(service_t _service, instance_t _instance) const {
std::string its_multicast(VSOMEIP_DEFAULT_MULTICAST);
std::string its_multicast(default_multicast);

service *its_service = find_service(_service, _instance);
if (its_service) its_multicast = its_service->multicast_;
Expand Down
8 changes: 4 additions & 4 deletions implementation/endpoints/src/endpoint_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ bool endpoint_impl< MaxBufferSize >::resync_on_magic_cookie(message_buffer_t &_b

if (is_client()) {
its_cookie_identifier
= static_cast< uint8_t >(VSOMEIP_MAGIC_COOKIE_SERVICE_MESSAGE_ID);
= static_cast< uint8_t >(magic_cookie_service_message);
its_cookie_type
= static_cast< uint8_t >(VSOMEIP_MAGIC_COOKIE_SERVICE_MESSAGE_TYPE);
= static_cast< uint8_t >(magic_cookie_service_message_type);
} else {
its_cookie_identifier
= static_cast< uint8_t >(VSOMEIP_MAGIC_COOKIE_CLIENT_MESSAGE_ID);
= static_cast< uint8_t >(magic_cookie_client_message);
its_cookie_type
= static_cast< uint8_t >(VSOMEIP_MAGIC_COOKIE_CLIENT_MESSAGE_TYPE);
= static_cast< uint8_t >(magic_cookie_client_message_type);
}

do {
Expand Down
2 changes: 1 addition & 1 deletion implementation/endpoints/src/udp_server_endpoint_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void udp_server_endpoint_impl::restart() {
}

void udp_server_endpoint_impl::send_queued(endpoint_type _target, message_buffer_ptr_t _buffer) {
#if 0
#if 1
std::stringstream msg;
msg << "usei::sq(" << _target.address().to_string() << ":" << _target.port() << "): ";
for (std::size_t i = 0; i < _buffer->size(); ++i)
Expand Down
14 changes: 7 additions & 7 deletions implementation/message/include/deserializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class message;
class deserializer {
public:
deserializer();
deserializer(uint8_t *_data, std::size_t _length);
deserializer(byte_t *_data, std::size_t _length);
deserializer(const deserializer& _other);
virtual ~deserializer();

void set_data(const uint8_t *_data, std::size_t _length);
void append_data(const uint8_t *_data, std::size_t _length);
void set_data(const byte_t *_data, std::size_t _length);
void append_data(const byte_t *_data, std::size_t _length);
void drop_data(std::size_t _length);

std::size_t get_available() const;
Expand All @@ -46,12 +46,12 @@ class deserializer {
bool look_ahead(std::size_t _index, uint32_t &_value) const;

void reset();
#ifdef VSOMEIP_DEBUG
void show_data() const;
#ifdef VSOMEIP_DEBUGGING
void show() const;
#endif
protected:
std::vector< uint8_t > data_;
std::vector< uint8_t >::iterator position_;
std::vector< byte_t > data_;
std::vector< byte_t >::iterator position_;
std::size_t remaining_;
};

Expand Down
10 changes: 6 additions & 4 deletions implementation/message/include/serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#ifndef VSOMEIP_SERIALIZER_HPP
#define VSOMEIP_SERIALIZER_HPP

#include <cstdint>
#include <vector>

#include <vsomeip/primitive_types.hpp>

namespace vsomeip {

class serializable;
Expand All @@ -36,13 +37,14 @@ class serializer

virtual void reset();

#ifdef VSOMEIP_DEBUGGING
virtual void show();

#endif
private:
uint8_t * data_;
byte_t * data_;
uint32_t capacity_;

uint8_t *position_;
byte_t *position_;
uint32_t remaining_;
};

Expand Down
35 changes: 21 additions & 14 deletions implementation/message/src/deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <cstring>
#include <iostream>

#ifdef VSOMEIP_DEBUGGING
#include <iomanip>
#include <sstream>

#include <vsomeip/logger.hpp>
#endif

#include "../include/byteorder.hpp"
#include "../include/message_impl.hpp"
Expand All @@ -18,7 +24,7 @@ deserializer::deserializer()
remaining_(0) {
}

deserializer::deserializer(uint8_t *_data, std::size_t _length)
deserializer::deserializer(byte_t *_data, std::size_t _length)
: data_(_data, _data + _length),
position_(data_.begin()),
remaining_(_length) {
Expand Down Expand Up @@ -92,20 +98,20 @@ bool deserializer::deserialize(uint8_t *_data, std::size_t _length) {
if (_length > remaining_)
return false;

::memcpy(_data, &_data[position_ - data_.begin()], _length);
std::memcpy(_data, &data_[position_ - data_.begin()], _length);
position_ += _length;
remaining_ -= _length;

return true;
}

bool deserializer::deserialize(std::vector<uint8_t>& _value) {
bool deserializer::deserialize(std::vector< uint8_t >& _value) {
if (_value.capacity() > remaining_)
return false;

_value.assign(position_, position_ + _value.capacity());
remaining_ -= _value.capacity();
position_ += _value.capacity();
remaining_ -= _value.capacity();

return true;
}
Expand Down Expand Up @@ -151,7 +157,7 @@ message * deserializer::deserialize_message() {
return deserialized_message;
}

void deserializer::set_data(const uint8_t *_data, std::size_t _length) {
void deserializer::set_data(const byte_t *_data, std::size_t _length) {
if (0 != _data) {
data_.assign(_data, _data + _length);
position_ = data_.begin();
Expand All @@ -163,7 +169,7 @@ void deserializer::set_data(const uint8_t *_data, std::size_t _length) {
}
}

void deserializer::append_data(const uint8_t *_data, std::size_t _length) {
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;
Expand All @@ -183,14 +189,15 @@ void deserializer::reset() {
remaining_ = data_.size();
}

#ifdef VSOMEIP_DEBUG_
void deserializer::show_data() const {
std::cout << "("
<< std::hex << std::setw(2) << std::setfill('0') << (int)*position_ << ", "
<< std:: dec << remaining_ << ") ";
#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)
std::cout << std::hex << std::setw(2) << std::setfill('0') << (int)data_[i] << " ";
std::cout << std::dec << std::endl;
its_message << std::hex << std::setw(2) << std::setfill('0') << (int)data_[i] << " ";
VSOMEIP_DEBUG << its_message;
}
#endif

Expand Down
12 changes: 9 additions & 3 deletions implementation/message/src/serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <cstring>

#ifdef VSOMEIP_DEBUGGING
#include <iomanip>
#include <sstream>

#include <vsomeip/logger.hpp>
#endif

#include <vsomeip/serializable.hpp>

#include "../include/byteorder.hpp"
Expand Down Expand Up @@ -75,7 +79,7 @@ bool serializer::serialize(const uint8_t *_data, uint32_t _length) {
return true;
}

uint8_t * serializer::get_data() const {
byte_t * serializer::get_data() const {
return data_;
}

Expand All @@ -91,7 +95,7 @@ void serializer::create_data(uint32_t _capacity) {
if (0 != data_)
delete [] data_;

data_ = new uint8_t[_capacity];
data_ = new byte_t[_capacity];
position_ = data_;
if (0 != data_) {
capacity_ = remaining_ = _capacity;
Expand All @@ -100,7 +104,7 @@ void serializer::create_data(uint32_t _capacity) {
}
}

void serializer::set_data(uint8_t *_data, uint32_t _capacity) {
void serializer::set_data(byte_t *_data, uint32_t _capacity) {
delete [] data_;

data_ = _data;
Expand All @@ -118,12 +122,14 @@ void serializer::reset() {
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();
}
#endif

} // namespace vsomeip
Loading

0 comments on commit 9f89671

Please sign in to comment.