36 convertTextModePending(
false),
41 target_used(&lst_used),
56 this->textMode = textMode;
60 convertTextModePending =
false;
69 convertTextModePending =
false;
71 target_used = &lst_used;
78 target_used = &lst_used;
81 for (
i = 0;
i < lst.size();
i++) {
85 for (
i = 0;
i < header.size();
i++) {
96 if (pool !=
nullptr) {
97 if (
data.length() + poolIndex > pool->
length()) {
101 if (pool ==
nullptr &&
data.length() < poolLength) {
105 if (bytes->
length() < poolLength) {
110 if (pool ==
nullptr) {
115 if (pool ==
nullptr) {
123 if (poolLength < 65536) {
128 target->push_back(pool);
131 if (pool !=
nullptr) {
133 poolIndex +=
data.length();
145 poolLength = initialPoolSize;
172 if (buf ==
nullptr) {
177 target->push_back(buf);
204 convertTextModePending =
true;
218 this->reader = &reader;
222template <
typename T,
typename NetT>
225 if (std::is_same<T, NetT>::value) {
273 if (terminate ==
'\n') {
275 }
else if (terminate == 0) {
305 const char*
eol =
"\r\n";
313 return header_used + lst_used;
323 if (index < header_used) {
333 if (index < header_used) {
345 for (
i = 0;
i < header_used;
i++) {
349 for (
i = 0;
i < lst_used;
i++) {
359 for (
size_t i = 0;
i < header_used;
i++) {
363 for (
size_t i = 0;
i < lst_used;
i++) {
385 for (
i = 0;
i < header_used;
i++) {
389 for (
i = 0;
i < lst_used;
i++) {
398 return header.size() + lst.size();
412 target_used = &header_used;
457 applyConvertTextMode();
472 initialPoolSize = size;
481 char* dest =
const_cast<char*
>(output.c_str());
482 for (
size_t i = 0;
i < header_used;
i++) {
483 const char*
data = header[
i]->get();
484 size_t len = header[
i]->used();
488 for (
size_t i = 0;
i < lst_used;
i++) {
489 const char*
data = lst[
i]->get();
490 size_t len = lst[
i]->used();
497bool BufferedConnectionWriter::applyConvertTextMode()
const
502bool BufferedConnectionWriter::applyConvertTextMode()
504 if (convertTextModePending) {
505 convertTextModePending =
false;
509 for (
size_t i = 0;
i < lst_used;
i++) {
513 const std::string& str = sos.
str();
514 b.
fromBinary(str.c_str(),
static_cast<int>(str.length()));
516 for (
auto&
i : lst) {
A simple collection of objects that can be described and transmitted in a portable way.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
void fromBinary(const char *buf, size_t len)
Initializes bottle from a binary representation.
A mini-server for performing network communication in the background.
T * read(bool shouldWait=true) override
Read an available object from the port.
A simple abstraction for a block of bytes.
An interface for writing to a network connection.
A dummy connection to test yarp::os::Portable implementations.
ConnectionWriter & getWriter()
Get the dummy ConnectionWriter loaded with whatever was written the ConnectionWriter since it was las...
void setTextMode(bool textmode)
Set the textMode of the dummy connection.
ConnectionReader & getReader(ConnectionWriter *replyWriter=nullptr)
Get the dummy ConnectionReader loaded with whatever was written the ConnectionWriter since it was las...
An abstraction for a block of bytes, with optional responsibility for allocating/destroying that bloc...
size_t setUsed(size_t used)
explicitly declare how many of the bytes are in use.
void copy()
Makes sure data block is owned, making a copy if necessary.
Simple specification of the minimum functions needed from output streams.
virtual void flush()
Make sure all pending write operations are finished.
virtual void write(char ch)
Write a single byte to the stream.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
This is a base class for objects that can be both read from and be written to the YARP network.
Minimal requirements for an efficient Writer.
An OutputStream that produces a string.
const std::string & str() const
void write(const Bytes &b) override
Write a block of bytes to the stream.
A helper for creating cached object descriptions.
void requestDrop() override
Tag the connection to be dropped after the current message.
~BufferedConnectionWriter() override
Destructor.
void startWrite() const override
Call when writing is about to begin.
bool dropRequested() override
virtual void appendBlockCopy(const Bytes &data)
Add a buffer by copying its contents.
void appendInt32(std::int32_t data) override
Send a representation of a 32-bit integer to the network connection.
void appendBlock(const char *data, size_t len) override
Send a block of data to the network connection.
void declareSizes(int argc, int *argv) override
If you can easily determine how many blocks there are in a message, call this first,...
std::string toString() const
void appendInt8(std::int8_t data) override
Send a representation of a 8-bit integer to the network connection.
SizedWriter * getBuffer() override
void setReplyHandler(PortReader &reader) override
This sets a handler to deal with replies to the message.
const char * data(size_t index) const override
bool isBareMode() const override
Check if the connection is bare mode.
void stopPool()
Stop adding to the current pool buffer.
bool isValid() const override
bool convertTextMode() override
Converts a standard description in binary into a textual description, if the connection is in text-mo...
size_t bufferCount() const
bool write(ConnectionWriter &connection) const override
Write this object to a network connection.
void stopWrite() const override
Call when all writing is finished.
void push(const Bytes &data, bool copy)
Add the specified buffer to the list of buffers to be written.
void appendInt16(std::int16_t data) override
Send a representation of a 16-bit integer to the network connection.
bool isError() const override
void setInitialPoolSize(size_t size)
Set a custom initial pool size, which affects the size of buffers created for temporary data storage.
bool addPool(const yarp::os::Bytes &data)
Add the specified bytes to the current pool buffer.
void appendFloat64(yarp::conf::float64_t data) override
Send a representation of a 64-bit floating point number to the network connection.
void clear() override
Clear all cached data.
BufferedConnectionWriter(bool textMode=false, bool bareMode=false)
Constructor.
bool isActive() const override
bool isTextMode() const override
Check if the connection is text mode.
void restart()
Tell the writer that we will be serializing a new object, but to keep any cached buffers that already...
void addToHeader()
Switch to storing a header.
void appendFloat32(yarp::conf::float32_t data) override
Send a representation of a 32-bit floating point number to the network connection.
size_t headerLength() const override
PortReader * getReplyHandler() override
void appendInt64(std::int64_t data) override
Send a representation of a 64-bit integer to the network connection.
void setReference(yarp::os::Portable *obj) override
Stores a direct pointer to the object being sent.
virtual size_t dataSize() const
size_t length() const override
yarp::os::Portable * getReference() override
void appendText(const std::string &str, const char terminate='\n') override
Send a terminated string to the network connection.
virtual void appendLine(const std::string &data)
Send a string along with a carriage-return-line-feed sequence.
void reset(bool textMode)
Completely clear the writer and start afresh.
void appendExternalBlock(const char *data, size_t len) override
Send a block of data to the network connection, without making a copy.
The components from which ports and connections are built.
constexpr size_t BUFFERED_CONNECTION_INITIAL_POOL_SIZE
An interface to the operating system, including Port based communication.