All Projects → google → Libnop

google / Libnop

Licence: other
libnop: C++ Native Object Protocols

Programming Languages

cpp14
131 projects

Projects that are alternatives of or similar to Libnop

Fsharp.json
F# JSON Reflection based serialization library
Stars: ✭ 144 (-67.49%)
Mutual labels:  serialization-library
ikeapack
Compact data serializer/packer written in Go, intended to produce a cross-language usable format.
Stars: ✭ 18 (-95.94%)
Mutual labels:  serialization-library
Savegamefree
Save Game Free is a free and simple but powerful solution for saving and loading game data in unity.
Stars: ✭ 279 (-37.02%)
Mutual labels:  serialization-library
Persistentstorageserializable
Swift library that makes easier to serialize the user's preferences (app's settings) with system User Defaults or Property List file on disk.
Stars: ✭ 162 (-63.43%)
Mutual labels:  serialization-library
xmpp
Erlang/Elixir XMPP parsing and serialization library on top of Fast XML
Stars: ✭ 111 (-74.94%)
Mutual labels:  serialization-library
BinaryLove3
Simple C++ 20 Serialization Library that works out of the box with aggregate types!
Stars: ✭ 13 (-97.07%)
Mutual labels:  serialization-library
Json
Lighter and Faster Json Serialization tool.
Stars: ✭ 128 (-71.11%)
Mutual labels:  serialization-library
Typedefs
Programming language agnostic type construction language based on polynomials.
Stars: ✭ 337 (-23.93%)
Mutual labels:  serialization-library
EndianBinaryIO
A C# library that can read and write primitives, enums, arrays, and strings to streams and byte arrays with specified endianness, string encoding, and boolean sizes.
Stars: ✭ 20 (-95.49%)
Mutual labels:  serialization-library
fuser
Header-only library for automatic (de)serialization of C++ types to/from JSON.
Stars: ✭ 48 (-89.16%)
Mutual labels:  serialization-library
Hagar
Fast, flexible, and version-tolerant serializer for .NET
Stars: ✭ 216 (-51.24%)
Mutual labels:  serialization-library
Thorsserializer
C++ Serialization library for JSON
Stars: ✭ 241 (-45.6%)
Mutual labels:  serialization-library
python-graphenelib
Python3 library for Graphene-based blockchains
Stars: ✭ 69 (-84.42%)
Mutual labels:  serialization-library
Hprose Php
Hprose is a cross-language RPC. This project is Hprose 3.0 for PHP
Stars: ✭ 1,952 (+340.63%)
Mutual labels:  serialization-library
Flatbuffers
FlatBuffers: Memory Efficient Serialization Library
Stars: ✭ 17,180 (+3778.1%)
Mutual labels:  serialization-library
Hprose Js
Hprose is a cross-language RPC. This project is Hprose 2.0 RPC for JavaScript
Stars: ✭ 133 (-69.98%)
Mutual labels:  serialization-library
JsonFormatter
Easy, Fast and Lightweight Json Formatter. (Serializer and Deserializer)
Stars: ✭ 26 (-94.13%)
Mutual labels:  serialization-library
Azure Iot Sdk C
A C99 SDK for connecting devices to Microsoft Azure IoT services
Stars: ✭ 412 (-7%)
Mutual labels:  serialization-library
Hprose Nodejs
Hprose is a cross-language RPC. This project is Hprose 2.0 for Node.js
Stars: ✭ 297 (-32.96%)
Mutual labels:  serialization-library
serializer-benchmark
A PHP benchmark application to compare PHP serializer libraries
Stars: ✭ 14 (-96.84%)
Mutual labels:  serialization-library

libnop: C++ Native Object Protocols

libnop is a header-only library for serializing and deserializing C++ data types without external code generators or runtime support libraries. The only mandatory requirement is a compiler that supports the C++14 standard.

Note: This is not an officially supported Google product at this time.

Goals

libnop has the following goals:

  • Make simple serialization tasks easy and complex tasks tractable.
  • Remove the need to use code generators and schema files to describe data types, formats, and protocols: perform these tasks naturally within the C++ language.
  • Avoid additional runtime support requirements for serialization.
  • Provide contemporary features such as bidirectional binary compatibility, data validation, type safety, and type fungibility.
  • Handle intrinsic types, common STL types and containers, and user-defined types with a minimum of effort.
  • Produce optimized code that is easy to analyze and profile.
  • Avoid internal dynamic memory allocation when possible.

Getting Started

Take a look at Getting Started for an introduction to the library.

Quick Examples

Here is a quick series of examples to demonstrate how libnop is used. You can find more examples in the repository under examples/.

Writing STL Containers to a Stream

#include <iostream>
#include <map>
#include <sstream>
#include <utility>
#include <vector>

#include <nop/serializer.h>
#include <nop/utility/stream_writer.h>

int main(int argc, char** argv) {
  using Writer = nop::StreamWriter<std::stringstream>;
  nop::Serializer<Writer> serializer;

  serializer.Write(std::vector<int>{1, 2, 3, 4});
  serializer.Write(std::vector<std::string>{"foo", "bar", "baz"});

  using MapType =
      std::map<std::uint32_t, std::pair<std::uint64_t, std::string>>;
  serializer.Write(
      MapType{{0, {10, "foo"}}, {1, {20, "bar"}}, {2, {30, "baz"}}});

  const std::string data = serializer.writer().stream().str();
  std::cout << "Wrote " << data.size() << " bytes." << std::endl;
  return 0;
}

Simple User-Defined Types

#include <cstdint>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

#include <nop/serializer.h>
#include <nop/structure.h>
#include <nop/utility/stream_writer.h>

namespace example {

struct Person {
  std::string name;
  std::uint32_t age_years;
  std::uint8_t height_inches;
  std::uint16_t weight_pounds;
  NOP_STRUCTURE(Person, name, age_years, height_inches, weight_pounds);
};

}  // namespace example

int main(int argc, char** argv) {
  using Writer = nop::StreamWriter<std::stringstream>;
  nop::Serializer<Writer> serializer;

  serializer.Write(example::Person{"John Doe", 37, 72, 180});
  serializer.Write(std::vector<example::Person>{
      {"John Doe", 37, 72, 180}, {"Jane Doe", 36, 69, 130}});

  const std::string data = serializer.writer().stream().str();
  std::cout << "Wrote " << data.size() << " bytes." << std::endl;
  return 0;
}

More Complex User-Defined Types

#include <array>
#include <iostream>
#include <sstream>
#include <string>

#include <nop/serializer.h>
#include <nop/structure.h>
#include <nop/utility/stream_writer.h>

namespace example {

// Contrived template type with private members.
template <typename T>
struct UserDefined {
 public:
  UserDefined() = default;
  UserDefined(std::string label, std::vector<T> vector)
      : label_{std::move(label)}, vector_{std::move(vector)} {}

  const std::string label() const { return label_; }
  const std::vector<T>& vector() const { return vector_; }

 private:
  std::string label_;
  std::vector<T> vector_;

  NOP_STRUCTURE(UserDefined, label_, vector_);
};

}  // namespace example

int main(int argc, char** argv) {
  using Writer = nop::StreamWriter<std::stringstream>;
  nop::Serializer<Writer> serializer;

  serializer.Write(example::UserDefined<int>{"ABC", {1, 2, 3, 4, 5}});

  using ArrayType = std::array<example::UserDefined<float>, 2>;
  serializer.Write(
      ArrayType{{{"ABC", {1, 2, 3, 4, 5}}, {"XYZ", {3.14, 2.72, 23.14}}}});

  const std::string data = serializer.writer().stream().str();
  std::cout << "Wrote " << data.size() << " bytes." << std::endl;
  return 0;
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].