Comments (7)
Did you solve that problem ? I have same problem in the latest version including your fix.
from rlpvalue.
Did you solve that problem ? I have same problem in the latest version including your fix.
What input did you try to serialize ? What result do you expect from it ?
from rlpvalue.
Same input like you. below:
RLPValue lorem("Lorem ipsum dolor sit amet, consectetur adipisicing elit");
std::string serialized_lorem = lorem.write();
for (size_t i = 0; i < serialized_lorem.size(); i++) {
printf("\\x%.2x ", serialized_lorem.c_str()[i]);
}
But it prints out \xffffffb8 \x38 \x4c ...
but should print \xb8 \x38 \x4c ...
from rlpvalue.
My code is here.
/* g++ -o rlp rlp.cpp -I. -L/usr/local/lib -lrlpvalue -static */
#include <stdio.h>
#include "rlpvalue.h"
using namespace std;
int main(void)
{
RLPValue lorem("Lorem ipsum dolor sit amet, consectetur adipisicing elit");
std::string serialized_lorem = lorem.write();
for (size_t i = 0; i < serialized_lorem.size(); i++) {
printf("\\x%.2x ", serialized_lorem.c_str()[i]);
}
printf("\n");
return 0;
}
from rlpvalue.
I think the data is placed in "serialized_lorem" correctly.
Is this simply a matter of output?
from rlpvalue.
Recommend using ParseHex
and HexStr
for going to/from hexidecimal. Example:
https://github.com/bloq/rlpvalue/blob/master/test/unitester.cpp#L129
std::string genHex = HexStr(genOutput.begin(),
genOutput.end());
fprintf(stderr, "INS :%s\nGENS:%s\n",
outs.c_str(),
genHex.c_str());
from rlpvalue.
Pretty late to the party, this got me also. It isn't a bug in the serialized_lorem. Instead its an issue with how you print to hex.
In the code the length is prepended to the data using this:
static std::string encodeLength(size_t n, unsigned char offset)
{
std::string rs;
if (n < 56) {
unsigned char ch = n + offset;
rs.assign((const char *) &ch, 1);
}
else {
// assert(n too big);
std::string binlen = encodeBinary(n);
unsigned char ch = binlen.size() + offset + 55;
rs.assign((const char *) &ch, 1);
rs.append(binlen);
}
return rs;
}
which represents the length as a single char, if the offset (0xC0 for example) pushes this above what can be represented as a single signed byte then it will be represented as a negative in std::string.
When printing if this gets interpreted as a signed char and converted to an unsigned char, then your output will be incorrect. Hence why HexStr is recommended going to hexidecimal
from rlpvalue.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rlpvalue.