Comments (3)
If you're writing your strings in C/C++ or most any text editor then you probably have valid UTF-8, unless you are adding invisible control characters.
JSON strictly requires UTF-8, so Glaze will reject illegal strings, such as strings that contain null or control characters in the middle of them. These can be written as escaped unicode \u
, but this is typically dangerous and prone to error in C++ and other languages because it can result in hidden null characters in types like std::string
and will break a lot of C string algorithms like strnlen
We are planning to add a compile time option to automatically unicode escape invalid UTF-8. The open issue is here #812. But, this is not recommended for general use.
What is your use case for non UTF-8 strings? Are you expecting invisible control characters in your strings?
In summary, Glaze does not unicode escape invalid UTF-8 when writing to ensure performance, but Glaze does ensure that the strings written will trigger a read error by any conforming JSON parser. If any JSON library is able to parse what you are writing, then you know that you're good to go.
from glaze.
I'm writing a Vulkan driver in C++, and some commands/structs allow using a void pointer to hold arbitrary data. Since I'm sending the data over a network, I need to be able to serialize it.
However, now that I think about it, I probably should use std::vector<uint8_t> for those fields over std::string, right?
from glaze.
Absolutely, arbitrary data like this is best in a std::vector<uint8_t>
or std::vector<std::byte>
.
I'll note that the same goes for if you use the binary format BEVE with Glaze.
from glaze.
Related Issues (20)
- add IWYU pragma to internal headers HOT 1
- Parsing glz::json_t using glz::read_json HOT 1
- Missed Breaking Change for Cpp 23 HOT 4
- undefined behaviour, out of bounds in GLZ_SKIP_WS HOT 4
- prettify_json("\xf3") invokes out ouf bounds read in prettify.hpp HOT 3
- reading generic json on invalid input causes out of bounds read in read.hpp HOT 1
- reading generic json can cause a stack overflow HOT 2
- prettify_json("\"") invokes memcpy on nullptr in dump.hpp HOT 8
- glz::minify_json invoked on "f" causes out of bounds read in minify.hpp HOT 3
- CMAKE Version update HOT 2
- converting float -8536070.f to string gives "-08536070" HOT 10
- Optionally Write Keys at Runtime (while using Partials) HOT 2
- Roundtrip failure for double -0x1.e42427b42cb42p+949 HOT 2
- out of bounds write in prettify_json
- read_json on json_t invoked with invalid unicode causes out of bounds read in hex_to_u32 HOT 1
- [BUG?] Build fails on latest version (using g++) HOT 1
- deprectaed in c++17 out-of-line definition of constexpr static data member HOT 1
- clang - remainder by zero is undefined HOT 1
- size_t wraparound causes huge allocation when reading generic json
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 glaze.