C++ serializes open source libraries and can be converted in three lines of code

C++ serializes open source libraries and can be converted in three lines of code

2022-09-30 0 1,260
Resource Number 43917 Last Updated 2025-02-24
¥ 0USD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

In this issue, we recommend an open source C++ serialize library called FdogSerialize.

C++ serializes open source libraries and can be converted in three lines of code插图

FStruct is an open source library for serialization in C++. It uses a non-invasive way without modifying the original structure. Currently, it supports serialization of base types, base type arrays, structures, and data types such as vector, list, map, etc. Supports JSON and XML data formats, aliases, ignores fields, and can be converted in at least three lines of code.

class=”pgc-h-arrow-right” data-track=”188″>

first stage

  • supports conversion between base types and Json
  • Support array of base types and json conversion
  • supports composition of base types into structure types and Json conversion
  • supports Json conversion from struct to struct type
  • Support vector type and json conversion
  • Support list type and json conversion
  • Support map type and json conversion
  • Support set type and json conversion

Stage 2

  • Support STL and custom type multi-layer nesting
  • Optimize the interface used in the first phase, integrate multiple interfaces into one, and facilitate the invocation of

Stage 3

  • Supports correct formatting of json strings (under development)
  • Support to get whether a field exists (under development)
  • supports getting the value of a field without serializing it first (in development)

Stage 4

  • supports required and optional fields. When the required field has no value, error will be reported (defined as pointer type, it is optional field) (under development)
  • Support XML data format conversion (under development)

Miscellaneous support

    • aliases

are supported

  • Support field ignore
  • supports case ignoring
  • If the supported field is empty, no serialization will be performed (under development)
  • Support fuzzy conversion (in development)

class=”pgc-h-arrow-right”>

Based on C++ base types, FdogSerialize supports 16 types, as long as the most basic type in your structure falls within these 16 ranges, you can complete the conversion.

Base type

Base type

1

bool

Boolean type

9

unsigned int

无符号整型

2

char

Unsigned character

10

long

long integer

3

unsigned char

Unsigned character

11

unsigned long

unsigned long integer

4

**char ***

character pointer (string type)

12

long long

5

short

Short integer

13

unsigned long long

unsigned long integer

6

unsigned short

Unsigned short integer

14

float

Single-precision floating-point type

7

int

Integer

15

double

double-schedule floating-point type

8

unsigned int

Unsigned integer

16

long double

Long dual-schedule floating-point type

Although the school structure contains one basic type and one custom type, the bottom layer of the custom type is essentially the basic type. Therefore, the school structure can be parsed normally, in fact any type can be parsed.

struct headmaster{
	char * name;
	int age;
};

struct school{
	char * schoolName;
	headmaster info;
};

class=”pgc-h-arrow-right”>

Serialization and deserialization each provide three functions:

call function

FSerialize(string & json_, T & object_, string name = “”)

Base type and structure type call

FSerializeA(string & json_, T & object_, string name = “”)

array, vector, list call

FSerializeS(string & json_, T & object_, string name = “”)

set, map type call

deserialize call function

FSerialize( T & object_, string & json_, string name = “”)

Base type and structure type call

FSerializeA( T & object_, string & json_, string name = “”)

Array, vector, list type call

FSerializeS( T & object_, string & json_, string name = “”)

set, map type call

1 Base type serialization

#include "fdogserialize.h" // Add header file required for serialization 
int main()
{
	int value = 10;
    string json_;
    // Convert value to json format data, the second type is recommended
    FdogSerialize::Instance()->FSerialize(json_, value); 			//json value is "{10}"
    FdogSerialize::Instance()->FSerialize(json_, value, "value");   //json value is "{"value":10}"

// To convert JSON-formatted data to value, make sure that json_ is a correctly formatted string
    FdogSerialize::Instance()->FDesSerialize(value, json_);
    return 0;
}

2 Base type array serialization

#include "fdogserialize.h" // Adds the header file needed for serialization

int main()
{
    int valueArray[5] = {1,2,3,4,5};
    string json_;
    // Convert valueArray to json format. The second type is recommended
    FdogSerialize::Instance()->FSerialize(json_, value); 			//json value is "{[1,2,3,4,5]}"
    FdogSerialize::Instance()->FSerialize(json_, value, "value");   //json The value is "{"valueArray":[1,2,3,4,5]}"
    // To convert json data to value, ensure that json_ is a string in the correct format
    FdogSerialize::Instance()->FDesSerialize(value, json_);
}

3 Serialization of the structure consisting of the underlying type

#include "fdogserialize.h" // Adds the header file needed for serialization

// Customize the base type structure
struct student{
    char * name;
    int age;
};

int main()
{
    REGISTEREDMEMBER(student, name, age); // You need to register a custom type. The first parameter is the name of the custom structure, followed by the member name
    struct stu;
    stu.name = "pieddog Fdog.";
    stu.age = 22;
    string json_;
    // Converts the value to json format data
    FdogSerialize::Instance()->FSerialize(json_, value, "stu");   //json value is"{"stu":{"name":"花狗Fdog","age":22}}"
    // To convert json data to value, ensure that json_ is a string in the correct format
    FdogSerialize::Instance()->FDesSerialize(value, json_);
}

4 vector serialization

#include "fdogserialize.h" //Add the header file needed for serialization

//Custom base type structs
struct student{
    char * name;
    int age;
};

int main()
{
    REGISTEREDMEMBER(student, name, age); //You need to register a custom type. The first parameter is the name of the custom structure, followed by the member name
    vector<student> stu;
    struct stu_1;
    stu_1.name = "pieddog Fdog";
    stu_1.age = 22;
    
    struct stu_2;
    stu_2.name = "Black Dog Fdog";
    stu_2.age = 23;
    
    stu.push_back(stu_1);
    stu.push_back(stu_2);
    
    string json_;
    //Convert the value to json format data
    FdogSerialize::Instance()->FSerializeA(json_, stu, "stu");   
    //json值为"{"stu":[{"name":"pieddog Fdog","age":22},{"name":"Black Dog Fdog","age":23}]}"

    //To convert json format data to value, ensure that json_ is a correctly formatted string
    FdogSerialize::Instance()->FDesSerializeA(value, json_);
}

5 list Serialization of type

#include "fdogserialize.h" //Add the header file needed for serialization

//Custom base type structs
struct student{
    char * name;
    int age;
};

int main()
{
    REGISTEREDMEMBER(student, name, age); //You need to register a custom type. The first parameter is the name of the custom structure, followed by the member name
    list<student> stu;
    struct stu_1;
    stu_1.name = "pieddog Fdog";
    stu_1.age = 22;
    
    struct stu_2;
    stu_2.name = "Black Dog Fdog";
    stu_2.age = 23;
    
    stu.push_back(stu_1);
    stu.push_back(stu_2);
    
    string json_;
    //Convert the value to json format data
    FdogSerialize::Instance()->FSerializeA(json_, stu, "stu");   
    //json value is"{"stu":[{"name":"pieddog Fdog","age":22},{"name":"Black Dog Fdog","age":23}]}"

    //To convert json format data to value, ensure that json_ is a correctly formatted string
    FdogSerialize::Instance()->FDesSerializeA(value, json_);
}

6 map Serialization of type

#include "fdogserialize.h" //Add the header file needed for serialization

//Custom base type structs
struct student{
    char * name;
    int age;
};

int main()
{
    REGISTEREDMEMBER(student, name, age); //You need to register a custom type. The first parameter is the name of the custom structure, followed by the member name
    vector<student> stu;
    struct stu_1;
    stu_1.name = "pieddog Fdog";
    stu_1.age = 22;
    
    struct stu_2;
    stu_2.name = "Black Dog Fdog";
    stu_2.age = 23;
    
    stu.push_back(stu_1);
    stu.push_back(stu_2);
    
    string json_;
    //Convert the value to json format data
    FdogSerialize::Instance()->FSerializeA(json_, stu, "stu");   
    //json value is"{"stu":[{"name":"pieddog Fdog","age":22},{"name":"Black Dog Fdog","age":23}]}"

    //To convert json format data to value, ensure that json_ is a correctly formatted string
    FdogSerialize::Instance()->FDesSerializeA(value, json_);
}

7 Necessary description

//You need to add a nested structure under the macro Serialize_type_judgment_all definition
#define Serialize_type_judgment_all\
    Serialize_type_judgment(student)
	//Add in turn
    
// Needs to add nested structures under the macro Serialize_type_judgment_all definition
#define DesSerialize_type_judgment_all\
    DesSerialize_type_judgment(student)
	//Add in turn

//Two macro definition guidelines: Use this custom type as a member of another custom type

Miscellaneous support

Miscellaneous function support

Description

setAliasName(string Type, string memberName, string AliasName)

Using aliases

setIgnoreField(string Type, string memberName)

Ignore field

setIgnoreLU(string Type, string memberName)

Ignore case

setFuzzy(string Type)

Fuzzy conversion

1 Support aliases

#include "fdogserialize.h" // Add header files for serialization 

// Custom base type struct 
struct student{
    char * name;
    int age;
};

int main()
{
     REGISTEREDMEMBER(student, name, age);  // To register a custom type, the first parameter is the name of the custom structure, followed by the member name 
FdogSerialize::Instance()-> setAliasName("student", "name",  "Aliasname");
     // The first parameter is the type, the second parameter is the original name, and the third parameter is an alias 
     // In addition, you can also use setAliasNameAll to set aliases for multiple parameters 
     struct stu; 
     stu.name = "pieddog Fdog";
     stu.age = 22;
     string json_;
FdogSerialize::Instance()-> FSerialize(json_, value);    < span class = "HLJS - the comment" > / / json values for "{{" Aliasname" : "flower dog Fdog", "age" : 22}} "< / span >
}

2 Support fields ignore

#include "fdogserialize.h" // Add header files for serialization 

// Custom base type struct 
struct student{
    char * name;
    int age;
};

int main()
{
    REGISTEREDMEMBER(student, name, age);  // To register a custom type, the first parameter is the name of the custom structure, followed by the member name 
FdogSerialize::Instance()-> setIgnoreField("student", "name");
    // The first parameter is the type, the second parameter is the field to be ignored 
    // Alternatively, you can also use setIgnoreFieldAll to set multiple ignored fields 
    struct stu; 
    stu.name = "pieddog Fdog";
    stu.age = 22;
    string json_;
FdogSerialize::Instance()-> FSerialize(json_, value);    < span class = "HLJS - the comment" > / / json values for "{{" age" : 22}} "< / span >
}

3 Case ignoring

When converting json to an object, if the case of the key value in json is different from that of the member name in the object, you can set the case to be ignored.

#include "fdogserialize.h" // Add header files needed for serialization 

// Custom base type struct 
struct student{
    char * name;
    int age;
};

int main()
{
    REGISTEREDMEMBER(student, name, age); 
    struct stu;
    FdogSerialize::Instance()->setIgnoreLU("student", "name"); 
    string stu_json = "{\"Name\":\"yujing\", \"AGE\":21}";
    FdogSerialize::Instance()->FDesSerialize(json_, value);
}

4 Support fuzzy conversion

If the json and the key value in the object are different, it will be matched according to the blur level after being enabled.

—END—

Open Source protocol: Apache2.0

资源下载此资源为免费资源立即下载
Telegram:@John_Software

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free source code C++ serializes open source libraries and can be converted in three lines of code https://ictcoder.com/kyym/c-serializes-open-source-libraries-and-can-be-converted-in-three-lines-of-code.html

Share free open-source source code

Q&A
  • 1, automatic: after taking the photo, click the (download) link to download; 2. Manual: After taking the photo, contact the seller to issue it or contact the official to find the developer to ship.
View details
  • 1, the default transaction cycle of the source code: manual delivery of goods for 1-3 days, and the user payment amount will enter the platform guarantee until the completion of the transaction or 3-7 days can be issued, in case of disputes indefinitely extend the collection amount until the dispute is resolved or refunded!
View details
  • 1. Heptalon will permanently archive the process of trading between the two parties and the snapshots of the traded goods to ensure that the transaction is true, effective and safe! 2, Seven PAWS can not guarantee such as "permanent package update", "permanent technical support" and other similar transactions after the merchant commitment, please identify the buyer; 3, in the source code at the same time there is a website demonstration and picture demonstration, and the site is inconsistent with the diagram, the default according to the diagram as the dispute evaluation basis (except for special statements or agreement); 4, in the absence of "no legitimate basis for refund", the commodity written "once sold, no support for refund" and other similar statements, shall be deemed invalid; 5, before the shooting, the transaction content agreed by the two parties on QQ can also be the basis for dispute judgment (agreement and description of the conflict, the agreement shall prevail); 6, because the chat record can be used as the basis for dispute judgment, so when the two sides contact, only communicate with the other party on the QQ and mobile phone number left on the systemhere, in case the other party does not recognize self-commitment. 7, although the probability of disputes is very small, but be sure to retain such important information as chat records, mobile phone messages, etc., in case of disputes, it is convenient for seven PAWS to intervene in rapid processing.
View details
  • 1. As a third-party intermediary platform, Qichou protects the security of the transaction and the rights and interests of both buyers and sellers according to the transaction contract (commodity description, content agreed before the transaction); 2, non-platform online trading projects, any consequences have nothing to do with mutual site; No matter the seller for any reason to require offline transactions, please contact the management report.
View details

Related Article

make a comment
No comments available at the moment
Official customer service team

To solve your worries - 24 hours online professional service