void serialize_field(
  const rosidl_typesupport_introspection_cpp::MessageMember * member,
  void * field,
  eprosima::fastcdr::Cdr & ser)
{
  if (!member->is_array_) {
    ser << *static_cast<T *>(field);
  } else if (member->array_size_ && !member->is_upper_bound_) {
    ser.serializeArray(static_cast<T *>(field), member->array_size_);
  } else {
    std::vector<T> & data = *reinterpret_cast<std::vector<T> *>(field);
    ser << data;
  }
}
void serialize_field(
  const rosidl_typesupport_introspection_c__MessageMember * member,
  void * field,
  eprosima::fastcdr::Cdr & ser)
{
  if (!member->is_array_) {
    ser << *static_cast<T *>(field);
  } else if (member->array_size_ && !member->is_upper_bound_) {
    ser.serializeArray(static_cast<T *>(field), member->array_size_);
  } else {
    auto & data = *reinterpret_cast<typename GenericCSequence<T>::type *>(field);
    ser.serializeSequence(reinterpret_cast<T *>(data.data), data.size);
  }
}
inline
void serialize_field<std::string>(
  const rosidl_typesupport_introspection_c__MessageMember * member,
  void * field,
  eprosima::fastcdr::Cdr & ser)
{
  using CStringHelper = StringHelper<rosidl_typesupport_introspection_c__MessageMembers>;
  if (!member->is_array_) {
    auto && str = CStringHelper::convert_to_std_string(field);
    // Control maximum length.
    if (member->string_upper_bound_ && str.length() > member->string_upper_bound_ + 1) {
      throw std::runtime_error("string overcomes the maximum length");
    }
    ser << str;
  } else {
    // First, cast field to rosidl_generator_c
    // Then convert to a std::string using StringHelper and serialize the std::string
    if (member->array_size_ && !member->is_upper_bound_) {
      // tmpstring is defined here and not below to avoid
      // memory allocation in every iteration of the for loop
      std::string tmpstring;
      auto string_field = static_cast<rosidl_generator_c__String *>(field);
      for (size_t i = 0; i < member->array_size_; ++i) {
        tmpstring = string_field[i].data;
        ser.serialize(tmpstring);
      }
    } else {
      auto & string_sequence_field =
        *reinterpret_cast<rosidl_generator_c__String__Sequence *>(field);
      std::vector<std::string> cpp_string_vector;
      for (size_t i = 0; i < string_sequence_field.size; ++i) {
        cpp_string_vector.push_back(
          CStringHelper::convert_to_std_string(string_sequence_field.data[i]));
      }
      ser << cpp_string_vector;
    }
  }
}
Ejemplo n.º 4
0
void GUID_t::deserialize(eprosima::fastcdr::Cdr &cdr)
{
    cdr.deserializeArray(m_value, 16);
}
Ejemplo n.º 5
0
void GUID_t::serialize(eprosima::fastcdr::Cdr &cdr) const
{
    cdr.serializeArray(m_value, 16);
}
Ejemplo n.º 6
0
void EntityId_t::deserialize(eprosima::fastcdr::Cdr &cdr)
{
    cdr.deserializeArray(entityKey_, 3);
    cdr >> entityKind_;
}
Ejemplo n.º 7
0
void EntityId_t::serialize(eprosima::fastcdr::Cdr &cdr) const
{
    cdr.serializeArray(entityKey_, 3);
    cdr << entityKind_;
}
Ejemplo n.º 8
0
void GUID_t::deserialize(eprosima::fastcdr::Cdr &cdr)
{
    cdr.deserializeArray(guidPrefix_, 12);
    cdr >> entityId_;
}
Ejemplo n.º 9
0
void GUID_t::serialize(eprosima::fastcdr::Cdr &cdr) const
{
    cdr.serializeArray(guidPrefix_, 12);
    cdr << entityId_;
}