Comments (1)
It's perfectly fine to ask questions here. :-)
First off, your structure definition looks correct. I don't think this is the problem.
I'm not sure how you got a payload of 13 bytes with double
as a key and having a double
in your element structure. A double always costs 9 bytes in serialized format, and since you have one for the map key and one in the element, the serializer should produce more than 18 bytes for this input, guaranteed.
Second, when I make a reproduction case that does not include file IO things seem to work fine. Take a look at this example: https://godbolt.org/z/6eYiXd
I suspect your data is getting truncated. You should make sure your file IO is correct in both directions.
The actual serialized data bytes should be: BB 01 89 00 00 00 00 00 00 04 40 B9 02 89 00 00 00 00 00 00 1A 40 01
.
If you truncate to the first 14 bytes and then zero filled the rest it would look like this: BB 01 89 00 00 00 00 00 00 04 40 B9 02 89 00 00 00 00 00 00 00 00 00
.
I'm not quite sure why this is happening, but it does seem to explain the result you got. Your file IO is probably the culprit here.
To make things simpler, you can build a nop::Serializer<nop::StreamWriter<std::ofstream>>
and a nop::Deserializer<nop::StreamReader<std::ifstream>>
directly and avoid the intermediate std::stringstream
and std::string
buffer. This might address the file IO issues you are having.
Lastly, you should avoid using double
for the key of std::map
. A small change in value due to limited accuracy/rounding during double precision floating point computations would result in the wrong element being indexed or std::map::find()
failing to locate a previously inserted element. If you need to represent money values you should use a decimal type, which is usually based on an integer.
Best,
Corey
from libnop.
Related Issues (20)
- Fails to compile with g++ 9
- Feature request: Support for zero-copy views like std::span HOT 2
- Optional.Basic test fails with GCC 9 and `-fstack-protector` HOT 7
- performance HOT 1
- [compile] error include/nop/base/logical_buffer.h:135:14: error: uninitialized variable ‘size’ in ‘constexpr’ function HOT 1
- Usage help HOT 3
- encode array of floats as binary container HOT 5
- Compilation issue: for unsigned long long int data
- test/serializer_tests.cpp build failure on 32bit HOT 1
- Is there any performance result? HOT 2
- Inheritance suppport HOT 5
- example did not work. HOT 2
- fails to compile with gcc-11 HOT 1
- User-Defined Types not work with MSVC 2022?! HOT 2
- Could I serialize a class with some "recursive/tree-like" data? HOT 1
- std::unordered_set support
- zero copy support:master HOT 2
- Serializing a vector of pointers HOT 3
- MVSC clang::falltrough error and NOP_STRUCTURE error HOT 1
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 libnop.