Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lint issue #9

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions rmw_zenoh_cpp/src/detail/attachment_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <cstdio>
#include <zenoh.h>
#include <zenoh_macros.h>

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <zenoh_macros.h>

#include "rmw/types.h"

#include "logging_macros.hpp"

#include "attachment_helpers.hpp"

namespace rmw_zenoh_cpp {
namespace rmw_zenoh_cpp
{

bool create_attachment_iter(z_owned_bytes_t *kv_pair, void *context) {
attachement_context_t *ctx = (attachement_context_t *)context;
bool create_attachment_iter(z_owned_bytes_t * kv_pair, void * context)
{
attachement_context_t * ctx = reinterpret_cast<attachement_context_t *>(context);
z_owned_bytes_t k, v;

if (ctx->idx == 0) {
Expand All @@ -40,8 +42,9 @@ bool create_attachment_iter(z_owned_bytes_t *kv_pair, void *context) {
z_bytes_serialize_from_int64(&v, ctx->data->source_timestamp);
} else if (ctx->idx == 2) {
z_bytes_serialize_from_str(&k, "source_gid");
z_bytes_serialize_from_buf(&v, ctx->data->source_gid,
RMW_GID_STORAGE_SIZE);
z_bytes_serialize_from_buf(
&v, ctx->data->source_gid,
RMW_GID_STORAGE_SIZE);
} else {
return false;
}
Expand All @@ -51,14 +54,18 @@ bool create_attachment_iter(z_owned_bytes_t *kv_pair, void *context) {
return true;
}

z_result_t attachement_data_t::serialize_to_zbytes(z_owned_bytes_t *attachment) {
z_result_t attachement_data_t::serialize_to_zbytes(z_owned_bytes_t * attachment)
{
attachement_context_t context = attachement_context_t(this);
return z_bytes_from_iter(attachment, create_attachment_iter,
(void *)&context);
return z_bytes_from_iter(
attachment, create_attachment_iter,
reinterpret_cast<void *>(&context));
}

bool get_attachment(const z_loaned_bytes_t *const attachment,
const std::string &key, z_owned_bytes_t *val) {
bool get_attachment(
const z_loaned_bytes_t * const attachment,
const std::string & key, z_owned_bytes_t * val)
{
if (z_bytes_is_empty(attachment)) {
return false;
}
Expand All @@ -72,7 +79,7 @@ bool get_attachment(const z_loaned_bytes_t *const attachment,
z_owned_string_t key_string;
z_bytes_deserialize_into_string(z_loan(key_), &key_string);

const char* key_string_ptr = z_string_data(z_loan(key_string));
const char * key_string_ptr = z_string_data(z_loan(key_string));
size_t key_string_len = z_string_len(z_loan(key_string));
if (key_string_len == key.length() && strncmp(key_string_ptr, key.c_str(), key.length()) == 0) {
found = true;
Expand All @@ -98,9 +105,10 @@ bool get_attachment(const z_loaned_bytes_t *const attachment,
return true;
}

bool get_gid_from_attachment(const z_loaned_bytes_t *const attachment,
uint8_t gid[RMW_GID_STORAGE_SIZE]) {

bool get_gid_from_attachment(
const z_loaned_bytes_t * const attachment,
uint8_t gid[RMW_GID_STORAGE_SIZE])
{
if (z_bytes_is_empty(attachment)) {
return false;
}
Expand All @@ -124,8 +132,10 @@ bool get_gid_from_attachment(const z_loaned_bytes_t *const attachment,
return true;
}

int64_t get_int64_from_attachment(const z_loaned_bytes_t *const attachment,
const std::string &name) {
int64_t get_int64_from_attachment(
const z_loaned_bytes_t * const attachment,
const std::string & name)
{
// A valid request must have had an attachment
if (z_bytes_is_empty(attachment)) {
return -1;
Expand All @@ -135,7 +145,7 @@ int64_t get_int64_from_attachment(const z_loaned_bytes_t *const attachment,
z_owned_bytes_t val;
if (!get_attachment(attachment, name, &val)) {
RMW_ZENOH_LOG_ERROR_NAMED(
"rmw_zenoh_cpp", "Failed to deserialize int64 from the attachment.")
"rmw_zenoh_cpp", "Failed to deserialize int64 from the attachment.")
return false;
}

Expand All @@ -154,4 +164,4 @@ int64_t get_int64_from_attachment(const z_loaned_bytes_t *const attachment,
return num;
}

} // namespace rmw_zenoh_cpp
} // namespace rmw_zenoh_cpp
41 changes: 25 additions & 16 deletions rmw_zenoh_cpp/src/detail/attachment_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,49 @@

#include "rmw/types.h"

namespace rmw_zenoh_cpp {
namespace rmw_zenoh_cpp
{

class attachement_data_t final {
class attachement_data_t final
{
public:
int64_t sequence_number;
int64_t source_timestamp;
uint8_t source_gid[RMW_GID_STORAGE_SIZE];
attachement_data_t(const int64_t _sequence_number,
const int64_t _source_timestamp,
const uint8_t _source_gid[RMW_GID_STORAGE_SIZE]) {
attachement_data_t(
const int64_t _sequence_number,
const int64_t _source_timestamp,
const uint8_t _source_gid[RMW_GID_STORAGE_SIZE])
{
sequence_number = _sequence_number;
source_timestamp = _source_timestamp;
memcpy(source_gid, _source_gid, RMW_GID_STORAGE_SIZE);
}
z_result_t serialize_to_zbytes(z_owned_bytes_t *);
};

class attachement_context_t final {
class attachement_context_t final
{
public:
const attachement_data_t *data;
const attachement_data_t * data;
int length = 3;
int idx = 0;

attachement_context_t(const attachement_data_t *_data) : data(_data) {}
attachement_context_t(const attachement_data_t * _data)
: data(_data) {}
};

bool get_attachment(const z_loaned_bytes_t *const attachment,
const std::string &key, z_owned_bytes_t *val);
bool get_attachment(
const z_loaned_bytes_t * const attachment,
const std::string & key, z_owned_bytes_t * val);

bool get_gid_from_attachment(const z_loaned_bytes_t *const attachment,
uint8_t gid[RMW_GID_STORAGE_SIZE]);
bool get_gid_from_attachment(
const z_loaned_bytes_t * const attachment,
uint8_t gid[RMW_GID_STORAGE_SIZE]);

int64_t get_int64_from_attachment(const z_loaned_bytes_t *const attachment,
const std::string &name);
} // namespace rmw_zenoh_cpp
int64_t get_int64_from_attachment(
const z_loaned_bytes_t * const attachment,
const std::string & name);
} // namespace rmw_zenoh_cpp

#endif // DETAIL__ATTACHMENT_HELPERS_HPP_
#endif // DETAIL__ATTACHMENT_HELPERS_HPP_
Loading
Loading