C++ BSON Library

Overview

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.

You might also like...
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

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

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

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

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

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

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

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

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

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.

    opened by jeaye 2
  • 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 :)

    opened by Mylifeismyhome 0
  • 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

    opened by nathanieltagg 0
Owner
Dwight Merriman
Dwight Merriman
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

Mindaugas Vinkelis 771 Jan 2, 2023
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

Cap'n Proto 9.5k Jan 1, 2023
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

iLab @ USC 3.4k Jan 3, 2023
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

Topology 491 Dec 28, 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

Google 19.7k Jan 9, 2023
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

null 550 Dec 25, 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.

RedSkittleFox 14 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

null 6.9k Jan 4, 2023
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.

mayah 157 Dec 22, 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

Chase Geigle 561 Dec 28, 2022