C++ BSON Library

This is a standalone BSON ("binary JSON") library for C++. (See bsonspec.org for more information on the BSON format.)

The library is at this time a bit early stage, but if you find it useful, that's great.

Notes

  • The code herein originates as a fork from the MongoDB C++ driver. Anything that isn't simply bson was then eliminated to get a standalone bson implementation. Some things were removed just for simplicity. Other changes have been made along the way too.

  • The namespace for the module is _bson. The underscore is present as it is anticipated that one day there will be an official bson driver perhaps, and we don't want to collide with that name-wise.

  • In current form the code uses a touch of C++11. The main reason for this is simply to have absolutely no outside dependencies; for example in C++11 we have unique_ptr in the standard library, and that is used herein. The C++11 specific code is minimal it would be quite easy to make the library work with older C++ editions.

  • Endian-awareness has been added, is preliminary, needs testing.

Notes for those who have used the MongoDB C++ Driver

  • The _bson::bsonobj class here behaves differently than the driver's mongo::BSONObj. The MongoDB driver version has a build in smart pointer implementation. That was removed here; bsonobj herein is simply a "view" on a bson data buffer in memory, and bsonobj itself does no memory management of it. The notion is that this is simpler and you can easily wrap them as needed yourself.

  • To avoid confusion as to what implementation is being used, the classes herein use lowercase names, unlike the MongoDB C++ driver library. If you see things in uppercase, they should probably be downcased for consistency eventually...

License

Apache 2.0.

Building

As mentioned above, the library uses std::unique_ptr among other things. Thus, use -std=c++0x on the compiler command line. (If that doesn't work for your project, I'd recommend using the BSON implementation in the MongoDB C++ driver instead.)

For Windows, see build/example1/example1.vcxproj for an example of settings that work. (Tested on Visual Studio 2013.)

Support

See Also

The bsontools command line utilities project which uses this library. Likely useful for any BSON user regardless of language.

Similar Resources

A C++11 or library for parsing and serializing JSON to and from a DOM container in memory.

A C++11 or library for parsing and serializing JSON to and from a DOM container in memory.

Branch master develop Azure Docs Drone Matrix Fuzzing --- Appveyor codecov.io Boost.JSON Overview Boost.JSON is a portable C++ library which provides

Dec 1, 2022

Zmeya is a header-only C++11 binary serialization library designed for games and performance-critical applications

Zmeya Zmeya is a header-only C++11 binary serialization library designed for games and performance-critical applications. Zmeya is not even a serializ

Nov 2, 2022

CppSerdes is a serialization/deserialization library designed with embedded systems in mind

CppSerdes is a serialization/deserialization library designed with embedded systems in mind

A C++ serialization/deserialization library designed with embedded systems in mind

Nov 5, 2022

Morse code decoding library

Morse code decoding library

ggmorse Morse code decoding library ggmorse2.mp4 ggmorse0.mp4 ggmorse1.mp4 Try it out You can easily test the library using the free GGMorse applicati

Nov 20, 2022

Header-only library for automatic (de)serialization of C++ types to/from JSON.

fuser 1-file header-only library for automatic (de)serialization of C++ types to/from JSON. how it works The library has a predefined set of (de)seria

Oct 20, 2022

C++17 library for all your binary de-/serialization needs

blobify blobify is a header-only C++17 library to handle binary de-/serialization in your project. Given a user-defined C++ struct, blobify can encode

Oct 20, 2022

A C++11 ASN.1 BER Encoding and Decoding Library

fast_ber A performant ASN.1 BER encoding and decoding library written in C++11 Introduction fast_ber is a small, lightweight library for BER encoding

Dec 1, 2022

A high performance C++14 library for effortlessly reading and writing UBJSON

UbjsonCpp A high performance C++14 library for effortlessly reading and writing UBJSON This library implements UBJSON Draft 12 and Value semmantics Ab

Aug 2, 2022

Serial traits library

Abandoned Repo is abandoned in favor of rpnx-core. No further updates will be made. https://github.com/rpnx-net/rpnx-core rpnx::serial_traits A work i

Nov 18, 2020
Comments
  • Is this usable?

    Is this usable?

    Dwight,

    I see you're working on this, and it's a stripped version of mongo's old bson code. I'm currently benchmarking different bson libs and I'm curious if you recommend using this at all. Since it's similar to https://github.com/chrismanning/bson-cpp I tried just bringing it in and porting over my code. Unfortunately, it looks like bsonobj::jsonString (at least) isn't defined; it has a definition in valid.cpp, but it's disabled, contains references to mongo, and has a comment saying its dependency on base64 is an issue.

    Thanks for the help.

  • How to parse BinData?

    How to parse BinData?

    The sample is showing the function fromjson to parse a json string, now I am trying to parse a bson string including bindata, unfortunately I get an error using the same function as shown in the sample, so my question now is "how to parse bson strings including bindata"?

    Error Message which I get in the fromjson function: parse error - Bad characters in expected numeric value line:1, file_offset:8, doc_number:1

    I mean the message is probably not helpful at all, so if you need more details, just tell me :)

  • Fails in test;

    Fails in test; "-7" doesn't work

    Hi, Just testing to see if maybe BSON is an answer to a problem I have. But my test case fails:

    $ cat tmp.json {"x":-7,"y":78.38,"z":576.08,"P":0.50}

    $ bsontools/mac/fromjson < tmp.json > out.bson fromjson parse error - Bad characters in expected numeric value line:1, file_offset:7, doc_number:1

    I can't find the problem in the source code

Your binary serialization library

Bitsery Header only C++ binary serialization library. It is designed around the networking requirements for real-time data delivery, especially for ga

Dec 1, 2022
Cap'n Proto serialization/RPC system - core tools and C++ library
Cap'n Proto serialization/RPC system - core tools and C++ library

Cap'n Proto is an insanely fast data interchange format and capability-based RPC system. Think JSON, except binary. Or think Protocol Buffers, except

Dec 1, 2022
A C++11 library for serialization
A C++11 library for serialization

cereal - A C++11 library for serialization cereal is a header-only C++11 serialization library. cereal takes arbitrary data types and reversibly turns

Dec 2, 2022
Header-only C++11 library to encode/decode base64, base64url, base32, base32hex and hex (a.k.a. base16) as specified in RFC 4648, plus Crockford's base32. MIT licensed with consistent, flexible API.

cppcodec Header-only C++11 library to encode/decode base64, base64url, base32, base32hex and hex (a.k.a. base16) as specified in RFC 4648, plus Crockf

Nov 17, 2022
FlatBuffers: Memory Efficient Serialization Library

FlatBuffers FlatBuffers is a cross platform serialization library architected for maximum memory efficiency. It allows you to directly access serializ

Nov 27, 2022
FlatBuffers Compiler and Library in C for C

OS-X & Ubuntu: Windows: The JSON parser may change the interface for parsing union vectors in a future release which requires code generation to match

Nov 26, 2022
Simple C++ 20 Serialization Library that works out of the box with aggregate types!

BinaryLove3 Simple C++ 20 Serialization Library that works out of the box with aggregate types! Requirements BinaryLove3 is a c++20 only library.

Sep 2, 2022
A C++ library for interacting with JSON.

JsonCpp JSON is a lightweight data-interchange format. It can represent numbers, strings, ordered sequences of values, and collections of name/value p

Dec 4, 2022
A header only C++11 library for parsing TOML

tinytoml A header only C++11 library for parsing TOML. This parser is based on TOML v0.4.0. This library is distributed under simplified BSD License.

Oct 10, 2022
cpptoml is a header-only library for parsing TOML

cpptoml A header-only library for parsing TOML configuration files. Targets: TOML v0.5.0 as of August 2018. This includes support for the new DateTime

Dec 1, 2022