-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Add setExternal in ManagedBytes #1582
Changes from all commits
9fd7c2b
fd13e59
02f481f
e20c77f
1607336
b9ee051
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,3 +179,16 @@ bool ManagedBytes::write(ConnectionWriter& writer) { | |
writer.convertTextMode(); | ||
return !writer.isError(); | ||
} | ||
|
||
void ManagedBytes::setExternal(const char *extData, size_t len) | ||
{ | ||
if (!extData) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the style used in the rest of the code |
||
return; | ||
} | ||
clear(); | ||
owned = false; | ||
Bytes extb(const_cast<char*>(extData), len); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering why setExternal accepts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may be actually the trieckiest part of this PR. The |
||
b = extb; | ||
setUsed(len); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,6 +257,24 @@ class yarp::sig::VectorOf : public VectorBase | |
len = 0; | ||
first = nullptr; | ||
} | ||
|
||
/** | ||
* Read vector from a connection. | ||
* return true if a vector was read correctly | ||
*/ | ||
virtual bool read(yarp::os::ConnectionReader& connection) override | ||
{ | ||
return VectorBase::read(connection); | ||
} | ||
|
||
/** | ||
* Write vector to a connection. | ||
* return true if a vector was written correctly | ||
*/ | ||
virtual bool write(yarp::os::ConnectionWriter& connection) override | ||
{ | ||
return VectorBase::write(connection); | ||
} | ||
}; | ||
|
||
|
||
|
@@ -457,16 +475,15 @@ class YARP_sig_API yarp::sig::Vector : public yarp::os::Portable | |
void clear () | ||
{ storage.clear();} | ||
|
||
///////// Serialization methods | ||
/* | ||
/** | ||
* Read vector from a connection. | ||
* return true iff a vector was read correctly | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
* @return true if a vector was read correctly | ||
*/ | ||
virtual bool read(yarp::os::ConnectionReader& connection) override; | ||
|
||
/** | ||
* Write vector to a connection. | ||
* return true iff a vector was written correctly | ||
* @return true if a vector was written correctly | ||
*/ | ||
virtual bool write(yarp::os::ConnectionWriter& connection) override; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 comments here.
First of all, this should not be
const char*
, but just char, since the data is not owned, but can be modified. Second, I suggest to useconst Bytes& ext
instead, like in the other constructor, in order to make the interface more coherentThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point but I tried to be as much coherent as possible to
yarp::sig::Image::setExternal
:yarp/src/libYARP_sig/include/yarp/sig/Image.h
Lines 247 to 252 in 29e9108
What is the best option ? 😅