void thread_reader(CPipeReadEndPoint& read_pipe) { try { std::cout << "[thread_reader ID:" << std::this_thread::get_id() << "] Started." << std::endl; // Simple read commands: size_t len = 0; char buf[100]; read_pipe.Read(&len, sizeof(len)); read_pipe.Read(buf, len); buf[len] = 0; cout << "RX: " << buf << endl; // Read MRPT object from a pipe: // *Note*: If the object class is known in advance, one can avoid smart // pointers with ReadObject(&existingObj) auto arch = mrpt::serialization::archiveFrom(read_pipe); auto obj = arch.ReadObject(); if (IS_CLASS(obj, CPose3D)) { CPose3D::Ptr ptrPose = std::dynamic_pointer_cast<CPose3D>(obj); cout << "RX pose: " << *ptrPose << endl; } printf("[thread_reader] Finished.\n"); } catch (std::exception& e) { cerr << e.what() << endl; } }
void thread_reader(CPipeReadEndPoint& read_pipe) { try { std::cout << "[thread_reader ID:" << std::this_thread::get_id() << "] Started." << std::endl; // Simple read commands: size_t len = 0; char buf[100]; read_pipe.Read(&len, sizeof(len)); read_pipe.Read(buf, len); buf[len] = 0; cout << "RX: " << buf << endl; // Read MRPT object from a pipe: // *Note*: If the object class is known in advance, one can avoid smart // pointers with ReadObject(&existingObj) auto arch = archiveFrom(read_pipe); #ifndef HAS_BROKEN_CLANG_STD_VISIT auto doprint = [](auto& pose) { cout << "RX pose: " << pose << endl; }; auto var = arch.ReadVariant<mrpt::poses::CPose2D, mrpt::poses::CPose3D>(); std::visit(doprint, var); var = arch.ReadVariant<mrpt::poses::CPose2D, mrpt::poses::CPose3D>(); std::visit(doprint, var); #endif printf("[thread_reader] Finished.\n"); } catch (const std::exception& e) { cerr << e.what() << endl; } }