Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Brief introduction and usage of kapok

Shulou Source: shulou.com Published: 2022-06-02 04:00:26 10月03日 Update

This article introduces the relevant knowledge of "introduction and usage of kapok". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Introduction and use of kapok

Kapok is an excellent serialization library that serializes objects into strings in Json format. It also uses rapidjson open source projects to support SAX and DOM parsing.

GitHUb address: https://github.com/qicosmos/Kapok

GitHub address: https://github.com/miloyip/rapidjson

Because they are used in the project, the methods used are recorded here.

Usage

The method of using kapok is very simple and requires only three steps.

1. Add a serializable attribute # include "kapok/Kapok.hpp" to the object

Struct YourType {

Int a

Double b; std::string c

/ / get the meta-information of the object, which is a macro definition, which is actually a function META (a, b, c)} 2. Serialize object # include "kapok/Kapok.hpp"

YourType t = {1,2.2, "Hello"}

/ / create a serialized object

Serialize sr

/ / use sr to serialize the object t

Sr.Serialize (t)

/ / get the json string of the serialized object

Std::string json_str = sr.GetString (); 3. Deserialize object # include "kapok/Kapok.hpp"

/ / create a deserialized object

DeSerializer dr;YourType t

/ / as long as you parse the sr.GetString () format

/ / for example, you can send sr.GetString () to the client through the network on the server side.

/ / it is also possible for the client to parse and deserialize using dr.

Dr.Parse (json_str)

/ / deserialize to object t

Dr.DeSerializer (t); "introduction to kapok and how to use it" ends here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Sequence object method introduction usage content address character string actual client client more format knowledge project excellent practical learned next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Redmi OPPO Reno Apple Shulou Tech Info