Coder Social home page Coder Social logo

fuckjson's Introduction

FuckJSON[v2.3]

Meta universe's C++ serialization and deserialization JSON tool

Advantage

  • Based on the most modern JSON library, nlohman JSON.
  • You only need the original structure and two macro.
  • Powerful static reflection, maximum performance(relative to other languages), minimum overhead, the fastest response, the easiest to maintain, and the low code.
  • Now, the problems of modularity, interdependence and circular dependency have been solved.
  • Pure header files can be compiled directly without cmake
  • Supports serializing objects or vector objects to strings, serializing objects to get JSON, and deserializing JSON format strings to objects.
  • Loose boolean type deserialization, including but not limited to true, false, and 0, 1
  • Support direct conversion of class or struct to JSON string
  • Allow the varchar type of the database, adopt the text < > scheme and be accurate to each character to ensure the maximum length and data security
  • Supports a box similar to Rust, without using raw pointers, and is extremely fast
  • It can deserialize JSON format strings, including nested objects. Theoretically, it can be nested infinitely

Model layer

class Tab;
class Type;

Class(Tab)
uint32_t id;
bool ok;
text<15> name;
tm date;
vector<Type> types;
box<Type> type;
Tab(uint32_t a = 0, bool b = false, const char* c = "", tm d = now(), vector<Type> e = {}, box<Type> f = nullptr) :
  id(a), ok(b), name(c), date(d), types(e), type(f) {}
FUCKJSON(Tab, id, ok, name, date, types, type)

Class(Type)
uint8_t id;
text<10> language;
double bigBlob;
vector<Tab> tabs;
box<Tab> tab;
Type(uint8_t a = 0, const char* b = "", double c = 0, vector<Tab> d = {}, box<Tab> e = nullptr) :
  id(a), language(b), bigBlob(c), tabs(d), tab(e) {}
FUCKJSON(Type, id, language, bigBlob, tabs, tab)

Examples

Suppose there is an object Tab above

Tab t{ 1, true, "reflect", now() };

Serialize the object into a JSON string

std::string s; s << &t;

Serialize objects into JSON

json(t);

Deserialize JSON strings into objects

json::parse(t, R"(
{
  "id": 3,
  "ok": false,
  "name": "🍻🍺!",
  "date": "2021-09-08 01:04:30",
  "type":  {
    "bigBlob": 0.1,
    "id": 1,
    "language": "MetaπŸŒ€πŸŒŒπŸͺ!"
  }
}
)");

Features

  • Modularization
  • Header files only
  • Low code
  • High performance

Premise

g++ -std=c++17 main.cc -o main -I./ -O3
g++ -std=c++17 *.cpp -o o2o -I./ -O3
g++ -std=c++17 benchmark.cc -o benchmark -I./ -O3
g++ -std=c++17 text.cc -o text -I./ -O3

Supported compilers(minimum version):

- Linux: G++ 9.2, Clang++ 9.0
- MacOS: Apple clang version 12.0.0 
- Windows: MSVC C++ compiler version 1930.

Attributions

uses the following libraries.

json 

https://github.com/nlohmann/json

Copyright (c) 2013-2021 Niels Lohmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

fuckjson's People

Contributors

asciphx avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.