19 auto io_msg = std::make_shared<goby::middleware::protobuf::IOData>();
20 std::string* encoded = io_msg->mutable_data();
21 pb_msg.SerializeToString(encoded);
27 encoded->push_back((crc32_value >> (i *
bits_in_byte)) & 0xFF);
35 const auto& encoded = io_msg.data();
38 throw(std::runtime_error(
"Message is too small"));
40 std::uint32_t computed_crc =
42 std::uint32_t provided_crc = 0;
45 for (
auto it = encoded.rbegin(), end = encoded.rbegin() +
bytes_in_crc32; it != end; ++it, ++i)
48 provided_crc |=
static_cast<std::uint32_t
>(
static_cast<std::uint8_t
>(*it))
51 if (computed_crc != provided_crc)
53 throw(std::runtime_error(
"Computed CRC (" + std::to_string(computed_crc) +
54 ") does not equal CRC on message (" +
55 std::to_string(provided_crc) +
")"));
58 ProtobufMessage pb_msg;
59 pb_msg.ParseFromArray(encoded.data(), encoded.size() -
bytes_in_crc32);