39 convertTextModePending(false),
44 target_used(&lst_used),
59 this->textMode = textMode;
63 convertTextModePending =
false;
72 convertTextModePending =
false;
74 target_used = &lst_used;
81 target_used = &lst_used;
84 for (i = 0; i < lst.size(); i++) {
88 for (i = 0; i < header.size(); i++) {
99 if (pool !=
nullptr) {
100 if (
data.length() + poolIndex > pool->
length()) {
104 if (pool ==
nullptr &&
data.length() < poolLength) {
106 if (*target_used < target->size()) {
108 if (bytes->
length() < poolLength) {
113 if (pool ==
nullptr) {
118 if (pool ==
nullptr) {
126 if (poolLength < 65536) {
131 target->push_back(pool);
134 if (pool !=
nullptr) {
135 memcpy(pool->
get() + poolIndex,
data.get(),
data.length());
136 poolIndex +=
data.length();
148 poolLength = initialPoolSize;
161 if (*target_used < target->size()) {
175 if (buf ==
nullptr) {
180 target->push_back(buf);
207 convertTextModePending =
true;
221 this->reader = &reader;
225 template <
typename T,
typename NetT>
228 if (std::is_same<T, NetT>::value) {
241 appendType<std::int8_t, NetInt8>(
this,
data);
246 appendType<std::int16_t, NetInt16>(
this,
data);
251 appendType<std::int32_t, NetInt32>(
this,
data);
256 appendType<std::int64_t, NetInt64>(
this,
data);
261 appendType<yarp::conf::float32_t, NetFloat32>(
this,
data);
266 appendType<yarp::conf::float64_t, NetFloat64>(
this,
data);
276 if (terminate ==
'\n') {
278 }
else if (terminate == 0) {
308 const char* eol =
"\r\n";
316 return header_used + lst_used;
326 if (index < header_used) {
336 if (index < header_used) {
348 for (i = 0; i < header_used; i++) {
352 for (i = 0; i < lst_used; i++) {
362 for (
size_t i = 0; i < header_used; i++) {
366 for (
size_t i = 0; i < lst_used; i++) {
388 for (i = 0; i < header_used; i++) {
392 for (i = 0; i < lst_used; i++) {
401 return header.size() + lst.size();
415 target_used = &header_used;
460 applyConvertTextMode();
471 initialPoolSize = size;
479 std::string output(total_size, 0);
480 char* dest =
const_cast<char*
>(output.c_str());
481 for (
size_t i = 0; i < header_used; i++) {
482 const char*
data = header[i]->get();
483 size_t len = header[i]->used();
484 memmove(dest,
data, len);
487 for (
size_t i = 0; i < lst_used; i++) {
488 const char*
data = lst[i]->get();
489 size_t len = lst[i]->used();
490 memmove(dest,
data, len);
496 bool BufferedConnectionWriter::applyConvertTextMode()
const
501 bool BufferedConnectionWriter::applyConvertTextMode()
503 if (convertTextModePending) {
504 convertTextModePending =
false;
508 for (
size_t i = 0; i < lst_used; i++) {
512 const std::string& str = sos.
str();
513 b.
fromBinary(str.c_str(),
static_cast<int>(str.length()));
514 std::string replacement = b.
toString() +
"\n";
515 for (
auto& i : lst) {
522 Bytes data(
const_cast<char*
>(replacement.c_str()), replacement.length());
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 simple abstraction for a block of bytes.
An interface for writing to a network connection.
virtual bool isError() const =0
virtual void appendBlock(const char *data, size_t len)=0
Send a block of data to the 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()
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...
virtual bool read(ConnectionReader &reader)=0
Read this object from a network connection.
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.
void write(const Bytes &b) override
Write a block of bytes to the stream.
const std::string & str() const
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
SizedWriter * getBuffer() const override
void appendInt8(std::int8_t data) override
Send a representation of a 8-bit integer to the network connection.
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.