Skip to content

janneku/cppbencode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cppbencode - Bencode serialization library for C++ STL
Copyright 2012 Janne Kulmala <[email protected]>

Program code is licensed with GNU LGPL 2.1. See COPYING.LGPL file.

See the example program in example.cc for basic usage.

-----

This library exposes just one class: ben::Value. Ben::Value objects are 
used to hold single values or recursive structures. It can store 
different types: Null, integer, string, boolean, a list of Values, or a 
dictionary (key-value pairs). The objects can be used for loading the 
contents from a Bencoded string, serializing the content as Bencode, 
comparing equivalency between objects and copying/assigning. The object 
provide a set of safe getters for different types that throw exceptions 
if the contained value is of wrong type.

Bencode is defined here: http://www.bittorrent.org/beps/bep_0003.html

-----

Advantages of using Bencode:

- Compact serialization (unlike XML). A bit more efficient than JSON, mostly
  because strings are stored without encoding. No white space or indentation.
- Easier to debug than binary serialization, as serialized form is plain ASCII
  as long as the structure does not contain binary strings.
- Can store arbitary large integers.
- A structure has always exactly one Bencode serialization. Two data structures
  can be compared in serialized form, for example, when verifying cryptographic
  signature.
- Does not specify encoding for strings, and leaves agreeing on the encoding for
  the users. Bencode strings are byte arrays, and can contain zero bytes or
  other control character sequences.
- Bencode structures can be stored sequentially in a stream. A decoder always
  knows whether an input contained a partial or a full object. Useful for TCP
  sockets and very large files, because the input can not be read to memory at
  once.

About

Bencode serialization library for C++ STL

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published