s***@gmail.com
2018-01-11 18:38:15 UTC
I am trying to check whether the packed message is handled correctly.
The message was serialized using:
kj::VectorOutputStream output;
capnp::MallocMessageBuilder message;
typename msgT::Builder r1 = message.initRoot<msgT>();
assign_function(&r1);
capnp::writePackedMessage(output, message);
serialized_size = output.getArray().size();
And was deserialized using:
typename msgT::Reader r2;
kj::ArrayInputStream input(output.getArray());
capnp::PackedMessageReader reader(input);
r2 = reader.getRoot<msgT>();
It was then checked using:
capnp::AnyStruct::Reader left = r1.asReader();
capnp::AnyStruct::Reader right = r2;
return left == right;
The message assign function is:
void capnproto::assign_function(RobotControl::Builder *r) {
auto states = r->initState(nested_iter);
for (int i = 0; i < nested_iter; i++) {
auto command = states[i].initRobotCommand();
if (i%2 == 0) {
command.setMove(1);
} else {
command.setGrasp(1);
}
auto pose = states[i].initPose();
auto pos = pose.initPos();
auto ori = pose.initOri();
pos.setX(static_cast<double>(i + 1.0));
pos.setY(static_cast<double>(i + 1.0));
pos.setZ(static_cast<double>(i + 1.0));
ori.setX(static_cast<double>(i + 1.0));
ori.setY(static_cast<double>(i + 1.0));
ori.setZ(static_cast<double>(i + 1.0));
ori.setW(static_cast<double>(i + 1.0));
}
}
I also tried to print out r2, but it returned:
unknown file: Failure
C++ exception with description "capnp/layout.c++:2240: failed: expected
ref->kind() == WirePointer::LIST; Message contains non-list pointer where
list pointer was expected.
stack: 0x4e86bb 0x4dfb0b 0x611d71 0x60b375 0x5ee6f8 0x5ef090 0x5ef783
0x5f68ca 0x613349 0x60c1b7 0x5f5366 0x4dd3c8 0x7f84f1d6c830 0x4ddde9"
thrown in the test body.
The print function is:
void capnproto::print_function(RobotControl::Reader *r) {
auto states = r->getState();
for (int i = 0; i < nested_iter; i++) {
auto command = states[i].getRobotCommand();
if (i%2 == 0) {
std::cout << command.isMove() << std::endl;
} else {
std::cout << command.isGrasp() << std::endl;
}
auto pose = states[i].getPose();
auto pos = pose.getPos();
auto ori = pose.getOri();
std::cout << pos.getX() << " " << pos.getY() <<
" " << pos.getZ() << std::endl;
std::cout << ori.getX() << " " << ori.getY() <<
" " << ori.getZ() << " " << ori.getW() << std::endl;
}
}
However, this test for simple scalar value message passed.
Can anyone help me with this?
Best,
Shuo
The message was serialized using:
kj::VectorOutputStream output;
capnp::MallocMessageBuilder message;
typename msgT::Builder r1 = message.initRoot<msgT>();
assign_function(&r1);
capnp::writePackedMessage(output, message);
serialized_size = output.getArray().size();
And was deserialized using:
typename msgT::Reader r2;
kj::ArrayInputStream input(output.getArray());
capnp::PackedMessageReader reader(input);
r2 = reader.getRoot<msgT>();
It was then checked using:
capnp::AnyStruct::Reader left = r1.asReader();
capnp::AnyStruct::Reader right = r2;
return left == right;
The message assign function is:
void capnproto::assign_function(RobotControl::Builder *r) {
auto states = r->initState(nested_iter);
for (int i = 0; i < nested_iter; i++) {
auto command = states[i].initRobotCommand();
if (i%2 == 0) {
command.setMove(1);
} else {
command.setGrasp(1);
}
auto pose = states[i].initPose();
auto pos = pose.initPos();
auto ori = pose.initOri();
pos.setX(static_cast<double>(i + 1.0));
pos.setY(static_cast<double>(i + 1.0));
pos.setZ(static_cast<double>(i + 1.0));
ori.setX(static_cast<double>(i + 1.0));
ori.setY(static_cast<double>(i + 1.0));
ori.setZ(static_cast<double>(i + 1.0));
ori.setW(static_cast<double>(i + 1.0));
}
}
I also tried to print out r2, but it returned:
unknown file: Failure
C++ exception with description "capnp/layout.c++:2240: failed: expected
ref->kind() == WirePointer::LIST; Message contains non-list pointer where
list pointer was expected.
stack: 0x4e86bb 0x4dfb0b 0x611d71 0x60b375 0x5ee6f8 0x5ef090 0x5ef783
0x5f68ca 0x613349 0x60c1b7 0x5f5366 0x4dd3c8 0x7f84f1d6c830 0x4ddde9"
thrown in the test body.
The print function is:
void capnproto::print_function(RobotControl::Reader *r) {
auto states = r->getState();
for (int i = 0; i < nested_iter; i++) {
auto command = states[i].getRobotCommand();
if (i%2 == 0) {
std::cout << command.isMove() << std::endl;
} else {
std::cout << command.isGrasp() << std::endl;
}
auto pose = states[i].getPose();
auto pos = pose.getPos();
auto ori = pose.getOri();
std::cout << pos.getX() << " " << pos.getY() <<
" " << pos.getZ() << std::endl;
std::cout << ori.getX() << " " << ori.getY() <<
" " << ori.getZ() << " " << ori.getW() << std::endl;
}
}
However, this test for simple scalar value message passed.
Can anyone help me with this?
Best,
Shuo
--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+***@googlegroups.com.
Visit this group at https://groups.google.com/group/capnproto.
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+***@googlegroups.com.
Visit this group at https://groups.google.com/group/capnproto.