Skip to content

Commit

Permalink
interim version; not working
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhaefner committed Dec 21, 2017
1 parent f89bf58 commit b2330b5
Show file tree
Hide file tree
Showing 22 changed files with 1,119 additions and 882 deletions.
25 changes: 25 additions & 0 deletions include/simppl/bool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@



inline
Serializer& write(bool b)
{
dbus_bool_t _b = b;
dbus_message_iter_append_basic(iter_, dbus_type_code<bool>::value, &_b);
return *this;
}



Deserializer& read(bool& t)
{
dbus_bool_t b;
dbus_message_iter_get_basic(iter_, &b);
dbus_message_iter_next(iter_);

t = b;
return *this;
}


template<> struct dbus_type_code<bool> { enum { value = DBUS_TYPE_BOOLEAN }; };
49 changes: 49 additions & 0 deletions include/simppl/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,55 @@ struct FixedSizeBuffer
};


namespace detail
{


template<size_t len>
struct Codec<FixedSizeBuffer<len>>
{
static
void encode(Serializer& s, const FixedSizeBuffer<len>& b)
{
DBusMessageIter iter;

dbus_message_iter_open_container(s.iter_, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &iter);
dbus_message_iter_append_fixed_array(&iter, DBUS_TYPE_BYTE, &b.buf, len);
dbus_message_iter_close_container(s.iter_, &iter);
}


static
void decode(Deserializer& s, FixedSizeBuffer<len>& b)
{
DBusMessageIter iter;
dbus_message_iter_recurse(s.iter_, &iter);

unsigned char* buf;
int _len = len;
dbus_message_iter_get_fixed_array(&iter, &buf, &_len);

b.assign(buf);

// advance to next element
dbus_message_iter_next(s.iter_);
}
};


template<size_t len>
struct make_type_signature<FixedSizeBuffer<len>>
{
static inline
std::ostream& eval(std::ostream& os)
{
return os << DBUS_TYPE_ARRAY_AS_STRING;
}
};


} // namespace detail

} // namespace dbus

} // namespace simppl
Expand Down
4 changes: 2 additions & 2 deletions include/simppl/detail/deserialize_and_return.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct deserialize_and_return
ReturnT rc;

Deserializer d(msg);
d.read(rc);
Codec<ReturnT>::decode(d, rc);

return rc;
}
Expand Down Expand Up @@ -53,7 +53,7 @@ struct deserialize_and_return<std::tuple<T...>>
return_type rc;

Deserializer d(msg);
d.read_flattened(rc);
Codec<return_type>::decode(d, rc);

return rc;
}
Expand Down
Loading

0 comments on commit b2330b5

Please sign in to comment.