Skip to content

Instantly share code, notes, and snippets.

@youtalk
Created July 2, 2017 22:34
Show Gist options
  • Save youtalk/3831e80dbf826e2f9399e55baf997b2b to your computer and use it in GitHub Desktop.
Save youtalk/3831e80dbf826e2f9399e55baf997b2b to your computer and use it in GitHub Desktop.
FreeRTPS String Serializer
uint32_t serialize_std_msgs__string(void *_msg, uint8_t *_buf, uint32_t _buf_size)
{
struct std_msgs__string *_s = (struct std_msgs__string *)_msg;
uint8_t *_p = _buf;
if ((uintptr_t)_p & 3)
_p += 4 - ((uintptr_t)_p & 3);
uint32_t _data_len = (uint32_t)strlen(_s->data) + 1;
*((uint32_t *)_p) = _data_len;
_p += 4;
memcpy(_p, _s->data, _data_len);
_p += _data_len;
return _p - _buf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment