and now I have it but I need to use it with MSVC 2017(recently updated to latest version 15.9.33), x64.
I only need serialization and no need for RPC or async.
This is my very first time posting a message to this community, please let me know if I'm not doing right here.
I have a schema whose basic construct is List of List of struct ( x,y points in 4d expressed by two level lists). Second level will have a few hundreds of entries and first level will have lots of entries.
Now I found that writing 4 entries in first level, two entries in second level (two x,y points each in 4 frames), I get the same error.
I'm putting my schema and my read/write code below. I'm using these codes with capnproto0.8.0. But actually this schema is a little striped version than the one I want to use. When I used that a little more complex schema, I faced similar issue with capnproto 0.7.0 and 0.8.0.
It would be very much appreciated for any help.
Thank you.
/**
* Copyright (c) 2021 ASTOM R&D
* Author: Yojiro Nobukuni
*/
//#include "pch.h"
#include "../sparse4d.capnp.h"
#include <capnp/message.h>
#include <capnp/serialize-packed.h>
#include <iostream>
#include <ios>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
//#include <unistd.h>
/**
* g++ writer.cpp photodeco_kernel.capnp.c++ -o writer -lcapnp -lkj
* ./writer > test.message
*/
/**
* Write PhotodecoKernel message to fd
* @param int fd fd to read message in
*/
void writeSparse4D(int fd, unsigned int nofPlanes, unsigned int nofPoints, bool packed)
{
::capnp::MallocMessageBuilder message;
auto dir4d = message.initRoot<Dir4D>();
auto header = dir4d.initHeader();
header.setTSize(7);
header.setZSize(7);
header.setXSize(7);
header.setYSize(7);
auto planes = dir4d.initPlanes(nofPlanes);
for (auto plane : planes) {
plane.setT(9);
plane.setZ(8);
auto points = plane.initPoints(nofPoints);
#if 0
// This one or the other one in #else block, same behavior.
for (unsigned int i = 0; i < nofPoints; i++) {
points[i].setX(1);
points[i].setY(2);
points[i].setIntensity(3);
}
#else
for (auto p : points) {
p.setX(1);
p.setY(2);
p.setIntensity(3);
}
#endif
}
try {
if (packed)
writePackedMessageToFd(fd, message);
else
writeMessageToFd(fd, message);
}
catch (std::exception& e) {
std::cout << "writeSparse4D: std::exception: " << e.what() << std::endl;
return;
}
}
/**
* Print PhotodecoKernerl kernel in text
* @param PhotodecoKernel::Reader kernel
*/
void printDir4D(Dir4D::Reader dir4d, bool printPoints)
{
auto header = dir4d.getHeader();
std::cout << " sizes[T,Z,Y,X] = "
<< header.getTSize() << ", " << header.getZSize() << ", " << header.getYSize() << ", " << header.getXSize() << ", "
<< std::endl;
//std::cout << " nofPoints = " << header.getNofPoints() << std::endl;
if (!printPoints) return;
size_t nofPoints = 0;
auto planes = dir4d.getPlanes();
for (auto plane : planes) {
const auto t = plane.getT();
const auto z = plane.getZ();
std::cout << "plane(t,z): " << t << ", " << z << std::endl;
for (auto p : plane.getPoints()) {
std::cout << t << ", " << z << ", " << p.getY() << ", " << p.getX() << ", " << p.getIntensity() << std::endl;
nofPoints++;
}
}
std::cout << "Total nof KernelPoints = " << nofPoints << std::endl;
}
/**
* Read PhotodecoKernerl message from fd and print it in text
* @param int fd
* @param bool packed
*/
void printSparseDir4D(int fd, bool printPoints, bool packed)
{
std::cout << "printSparseDir4D" << std::endl;
// readerOptions for reading message.
capnp::ReaderOptions readerOptions;
readerOptions.traversalLimitInWords = 1000 * 1000 * 1000 * readerOptions.traversalLimitInWords;
//readerOptions.nestingLimit;
::capnp::MessageReader *message;
try {
if (packed)
message = new ::capnp::PackedFdMessageReader(fd, readerOptions);
else
message = new ::capnp::StreamFdMessageReader(fd, readerOptions);
auto dir4d = message->getRoot<Dir4D>();
printDir4D(dir4d, printPoints);
}
catch (std::exception& e) {
std::cout << "printSparseDir4D: std::exception: " << e.what() << std::endl;
return;
}
delete message;
}