CN105573956B - Sequencing method and network communication method based on serializing - Google Patents
Sequencing method and network communication method based on serializing Download PDFInfo
- Publication number
- CN105573956B CN105573956B CN201510916783.2A CN201510916783A CN105573956B CN 105573956 B CN105573956 B CN 105573956B CN 201510916783 A CN201510916783 A CN 201510916783A CN 105573956 B CN105573956 B CN 105573956B
- Authority
- CN
- China
- Prior art keywords
- definition
- agreement
- protocol
- field
- serialize
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F13/00—Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
- G06F13/38—Information transfer, e.g. on bus
- G06F13/42—Bus transfer protocol, e.g. handshake; Synchronisation
- G06F13/4265—Bus transfer protocol, e.g. handshake; Synchronisation on a point to point bus
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computer And Data Communications (AREA)
Abstract
The present invention provides a kind of sequencing method and based on the network communication method of serializing.In such a way that conventional structure body defines, the definition of agreement is abstracted into type system, and indicates the field that needs serialize;The type system of definition and specific protocol number are bound;It is realized using the SFINAE characteristic of C++ template system and the automatic sequenceization of protocol fields with nested agreement is handled with the structural body of formation sequence.Moreover, the function for public access rights that leading-out needle defines the class of Lua;And utilize the structural body of derived function translation sequence between Lua network-side and C++ network-side.
Description
Technical field
The present invention relates to network technique field, it is more particularly related to a kind of sequencing method and be based on sequence
The network communication method of columnization.
Background technique
Optional some network transmission schemes at present substantially have traditional direct transport structures memory and based on serializing
Two schemes.
The first scheme is achieved in that the data in memory, which are directly passed through network, is sent to other side, and its advantages are
Therefore the CPU usage amount of both sides can be saved by not needing structure elucidation, but since the data of pod type are all fixed-length datas,
Therefore it is difficult to realize in transmission list or dictionary data or extremely not flexible, sends string data largely using directly setting one
The mode of a longest character string is transmitted, and majority of case all has the case where waste memory, wastes feelings when transmitting larger character string
Condition is especially apparent.Client with server version is inconsistent need extended field when be less susceptible to realize, also cannot achieve pair
The verification of the field level of junk data and malicious data.
It is agreement buffering (protocol buffer) that second scheme is largely foremost, it is by defining one
Then type definition file generates the mode of the code of each language to realize serializing, it solves many of the first scheme
Drawback can effectively transmit variable length data.But it also has Railway Project, first is that it is not supported
Delphi, so not being available for the game for using delphi to do server-side;Second be it serialize after data volume or
It is bigger, to service for network interaction frequently large size MMO (Massively Multiplayer Online) game
The bandwidth requirement of device is relatively high;Third is that it can not achieve the heat the not more fresh code the case where and updates agreement.
Summary of the invention
The technical problem to be solved by the present invention is to for drawbacks described above exists in the prior art, providing one kind be can be improved
Run time behaviour and it can be easier to realize quick failure mechanism when encountering rubbish or malicious data
In order to achieve the above technical purposes, according to the present invention, a kind of sequencing method is provided, comprising:
First step: in such a way that conventional structure body defines, the definition of agreement is abstracted into type system, and indicate
The field for needing to serialize;
Second step: the type system of definition and specific protocol number are bound;
Third step: the automatic sequence to protocol fields and nested agreement is realized using the SFINAE characteristic of C++ template system
Columnization processing is with the structural body of formation sequence.
Preferably, the step of indicating the field that needs serialize includes: agreement and the protocol fields letter that will need to serialize
Cease the example for being abstracted into corresponding types system.
Preferably, the step of indicating the field that needs serialize includes: will be specific macro in structural body definition.
Moreover, in order to achieve the above technical purposes, according to the present invention, additionally providing a kind of network communication based on serializing
Method, comprising:
First step: in such a way that conventional structure body defines, the definition of agreement is abstracted into type system, and indicate
The field for needing to serialize;
Second step: the type system of definition and specific protocol number are bound;
Third step: the automatic sequence to protocol fields and nested agreement is realized using the SFINAE characteristic of C++ template system
Columnization processing is with the structural body of formation sequence;
Four steps: the function for public access rights that leading-out needle defines the class of Lua;
5th step: the structural body of derived function translation sequence between Lua network-side and C++ network-side is utilized;
6th step: then modification protocol definition modifies default parameters at log-in protocol, come from by running client
The configuration file of update, is put into the more new version of agreement by dynamic more new configuration file.
Preferably, the step of indicating the field that needs serialize includes: agreement and the protocol fields letter that will need to serialize
Cease the example for being abstracted into corresponding types system.
Preferably, the step of indicating the field that needs serialize includes: will be specific macro in structural body definition.
Compared to the mode of Ergodic judgement type at runtime, the definition of agreement is abstracted into type system, needing sequence
The example that the agreement and its field information of change are abstracted into corresponding types system, and it is skilful using the SFINAE characteristic of C++ template system
The wonderful automatic sequence process realized to field and nested agreement, when operation is greatly improved compared to other solutions
Performance simultaneously makes code structure more precision and elegance, and the degree of modularity is higher, and can be easier to realize and encounter rubbish or malice
Quick failure mechanism when data.
Detailed description of the invention
In conjunction with attached drawing, and by reference to following detailed description, it will more easily have more complete understanding to the present invention
And its adjoint advantage and feature is more easily to understand, in which:
Fig. 1 schematically shows flow chart according to the preferred embodiment of the invention.
It should be noted that attached drawing is not intended to limit the present invention for illustrating the present invention.Note that indicating that the attached drawing of structure can
It can be not necessarily drawn to scale.Also, in attached drawing, same or similar element indicates same or similar label.
Specific embodiment
In order to keep the contents of the present invention more clear and understandable, combined with specific embodiments below with attached drawing in of the invention
Appearance is described in detail.
In the present invention, type system is generated using the SFINAE characteristic of C++ template system, is defined according to conventional structure body
Mode define protocol definition, and indicate the field that needs serialize, after binding the protocol number of this agreement, local number can be loaded
According to or network flow, when serialize to object/unserializing handles and use in C++ and Lua, and being communicated with Lua without
All types need to be registered.
It, can be literary by the protocol configuration automatically generated in the small version updating for not updating C++ code more new resources
Part, modifies to unaware agreement or newly-increased agreement uses in Lua file, and the logic of original C++ code is unaffected.
Fig. 1 schematically shows flow chart according to the preferred embodiment of the invention.Process shows sequence of the invention
The specific embodiment of column method and the network communication method based on serializing.
As shown in Figure 1, preferred embodiment includes: according to the present invention
First step S1: in such a way that conventional structure body defines, the definition of agreement is abstracted into type system, and refer to
The bright field for needing to serialize;
For example, the step of indicating the field that needs serialize includes: the agreement and protocol fields information for serializing needs
The example for being abstracted into corresponding types system.Alternatively, for example, the step of indicating the field that needs serialize includes: will be specific
It is macro to be included in structural body definition.
Second step S2: the type system of definition and specific protocol number are bound;
In specific example, for the two above-mentioned steps, for example, being firstly added associated documents (for example, #Include
" SDReflect.h "), protocol type (support inherit and polymorphic) is then defined as common definition structural body, has defined it
It is macro to indicate field that needs serialize to structural body to increase a RTTI for sample for reference (demo) afterwards, then in corresponding cpp
The type system of definition and specific protocol number are bound by way of registering loader (loader) in file, so that it may with
The heart is desired serialize or communicate with networking client.
Wherein, it supports to inherit and polymorphic mode includes: the type loader branch for serializing type and being generated by compiling duration
Succession and polymorphic is held, does not need to modify configuration file by hand and realizes and inherit and polymorphic feature.
Third step S3: it is realized using the SFINAE characteristic of C++ template system to the automatic of protocol fields and nested agreement
Serializing processing is with the structural body of formation sequence;
Further, in order to which agreement or type are carried out seamless communication between C++ network-side and Lua network-side, may be used also
To execute following four steps S4 and the 5th step S5.
Four steps S4: the function for public access rights that leading-out needle defines the class of Lua;
Specifically, for example, (can determine if necessary needing to export the method for defining public access rights to the class of Lua
An adopted general communication functions, parameter type is base class), operation can automatically generate after generating the python file that Lua is bound
With the communication cryptology of Lua, derived function free translation sequence structural body between Lua and C++ is then rested against.
5th step S5: the structure of derived function translation sequence between Lua network-side and C++ network-side is utilized
Body.
Further, agreement is updated by way of more new configuration file in order to realize, following 6th steps can also be performed
Rapid S6.
6th step S6: modification protocol definition, then at log-in protocol modify default parameters, by operation client come
Configuration file is automatically updated, the configuration file of update is put into the more new version of agreement.
In this manner it is possible to use new agreement in Lua, and do not need to update the .so file of C++ compiling at this time, it is former
There is the protocol definition in .so file still can normally forward.Calling code (the python of C++ can be generated by Python
The effect of code is analytic definition header file, automatically in C++ type and other C++ functions for needing to export in Lua infuse
In volume to Lua virtual machine), it does not hereafter need to write by hand for every kind of serializing type or using generator registration type to Lua
The mechanism of all sequences structure can be transmitted mutually with Lua.It can be matched by automatically generating when C++ code cannot be updated
The mode for setting file realizes newly-increased or change protocol definition and may be implemented and definition in original .so and logic and deposit and mutual not shadow
Loud mechanism.
As a result, in the present invention, client and the direct definition structure body of server-side, and which field is indicated in structural body
It is to need to serialize, it can directly carry out communication and seamless interacted with Lua script.In the feelings that cannot update C++ code
Change Lua protocol definition is realized by change configuration file under condition and increases new agreement.
In the present invention, C++ uses template SFINAE characteristic implementation type system, can be fixed in compiling duration automatic identification type
Justice and the adjacent field of merging treatment, greatly improve performance;The succession of body support structure and polymorphic, supported protocol and standard
The unlimited nesting of template library (STL, Standard Template Library) container.Using the solution of the present invention, passes through and configure
Former C++ agreement existing logic is not influenced when file modification Lua agreement.Moreover, the end Delphi is by pre-saving reflective information
Improve performance.
In addition, can be used and marked in position binary bits (bit) of serializing head Sign field in specific example
The mode of note realizes dynamic head-coating structure, to make to need to guarantee that the volume of each packet is as small as possible and special in a large amount of parcels
Situation needs the demand of super large packet all to be met.
In the case where hand trip is inconvenient to update binary code, the present invention can be modified by way of more new configuration file
Or newly-increased agreement is used for Lua file, the version updating mode of adaptation mobile phone environment that can be more flexible compared to other solutions.
In the present invention, to include: serializing/antitone sequence module use template in compiling duration to the mode of ergodic sequence field
SFINAE characteristic, which generates type loader system and does not need repeatedly to jump judgement in the runtime, directly to carry out sequence to field
Column/unserializing feature is eliminated in the runtime by way of multiple " if else " sentences or hash table to difference
Type field carries out handling caused performance cost.
In addition, it should be noted that, unless stated otherwise or point out, the otherwise term " first " in specification, "
Two ", the descriptions such as " third " are used only for distinguishing various components, element, the step etc. in specification, each without being intended to indicate that
Component, element, the logical relation between step or ordinal relation etc..
It is understood that although the present invention has been disclosed in the preferred embodiments as above, above-described embodiment not to
Limit the present invention.For any person skilled in the art, without departing from the scope of the technical proposal of the invention,
Many possible changes and modifications all are made to technical solution of the present invention using the technology contents of the disclosure above, or are revised as
With the equivalent embodiment of variation.Therefore, anything that does not depart from the technical scheme of the invention are right according to the technical essence of the invention
Any simple modifications, equivalents, and modifications made for any of the above embodiments still fall within the range of technical solution of the present invention protection
It is interior.
Claims (7)
1. a kind of sequencing method, characterized by comprising:
First step: in such a way that structural body defines, the definition of agreement is abstracted into type system, and indicate and need sequence
The field of change;
Second step: the type system of definition and specific protocol number are bound;
Third step: the automatic sequence to protocol fields and nested agreement is realized using the SFINAE characteristic of C++ template system
Processing is with the structural body of formation sequence, in compiling duration automatic identification type definition and the adjacent field of merging treatment;
Newly-increased or change protocol definition is realized by change configuration file in the case where C++ code cannot be updated.
2. the method according to claim 1, wherein the step of indicating the field that needs serialize includes: need to
The agreement and protocol fields information to be serialized are at the example for corresponding to type system.
3. the method according to claim 1, wherein the step of indicating the field that needs serialize includes: will be special
It is fixed macro in structural body definition.
4. a kind of network communication method based on serializing, characterized by comprising:
First step: in such a way that conventional structure body defines, the definition of agreement is abstracted into type system, and indicate needs
The field of serializing;
Second step: the type system of definition and specific protocol number are bound;
Third step: the automatic sequence to protocol fields and nested agreement is realized using the SFINAE characteristic of C++ template system
Processing is with the structural body of formation sequence, in compiling duration automatic identification type definition and the adjacent field of merging treatment;
Four steps: the function for public access rights that leading-out needle defines the class of Lua;
5th step: the structural body of derived function translation sequence between Lua network-side and C++ network-side is utilized;
Newly-increased or change protocol definition is realized by change configuration file in the case where C++ code cannot be updated.
5. according to the method described in claim 4, characterized by further comprising:
6th step: modification protocol definition, then at log-in protocol modify default parameters, by operation client come automatically more
The configuration file of update is put into the more new version of agreement by new configuration file.
6. method according to claim 4 or 5, which is characterized in that the step of indicating the field that needs serialize include: by
The agreement and protocol fields information for needing to serialize are at the example for corresponding to type system.
7. method according to claim 4 or 5, which is characterized in that the step of indicating the field that needs serialize include: by
It is specific macro in structural body definition.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201510916783.2A CN105573956B (en) | 2015-12-10 | 2015-12-10 | Sequencing method and network communication method based on serializing |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201510916783.2A CN105573956B (en) | 2015-12-10 | 2015-12-10 | Sequencing method and network communication method based on serializing |
Publications (2)
Publication Number | Publication Date |
---|---|
CN105573956A CN105573956A (en) | 2016-05-11 |
CN105573956B true CN105573956B (en) | 2019-06-21 |
Family
ID=55884111
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201510916783.2A Active CN105573956B (en) | 2015-12-10 | 2015-12-10 | Sequencing method and network communication method based on serializing |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN105573956B (en) |
Families Citing this family (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106528259B (en) * | 2016-11-04 | 2019-07-09 | 网易(杭州)网络有限公司 | Data sending, receiving method and its device |
CN107040539B (en) * | 2017-04-20 | 2020-08-21 | 广州华多网络科技有限公司 | Protocol data packet construction method and device and computer system |
CN110339575B (en) * | 2018-04-08 | 2022-08-26 | 腾讯科技(深圳)有限公司 | Method and device for determining cheating users in online game |
CN108683704A (en) * | 2018-04-09 | 2018-10-19 | 福建天晴数码有限公司 | A kind of Socket network communications test method and its system, storage medium |
CN109343836B (en) * | 2018-08-31 | 2021-09-10 | 创新先进技术有限公司 | Data serialization and data deserialization method, device and equipment |
CN113839902B (en) * | 2020-06-08 | 2023-05-02 | 腾讯科技(深圳)有限公司 | Communication protocol adaptation method, device, computer equipment and storage medium |
CN114697402B (en) * | 2020-12-29 | 2023-07-14 | 中移物联网有限公司 | Internet of things protocol serialization method and device and electronic equipment |
CN113138755A (en) * | 2021-04-19 | 2021-07-20 | 上海逸动医学科技有限公司 | JSON serialization and deserialization optimization method and system |
WO2023184285A1 (en) * | 2022-03-30 | 2023-10-05 | 华为技术有限公司 | Data transmission method and apparatus |
CN115237415B (en) * | 2022-09-22 | 2022-12-16 | 南京雷电信息技术有限公司 | Method for realizing situation duplication under GIS platform |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1859359A (en) * | 2005-07-12 | 2006-11-08 | 上海华为技术有限公司 | Realizing method and its device for communication protocol described by abstract grammar rule |
CN104426871A (en) * | 2013-08-29 | 2015-03-18 | 中兴通讯股份有限公司 | Method and device for realizing remote calling |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104077335B (en) * | 2013-05-07 | 2017-05-03 | 腾讯科技(深圳)有限公司 | Methods, devices and system for serializing and deserializing structured data |
CN104270257B (en) * | 2014-09-10 | 2017-11-07 | 烽火通信科技股份有限公司 | NE-level webmaster business configuration adaption system and method based on PB and XPATH |
-
2015
- 2015-12-10 CN CN201510916783.2A patent/CN105573956B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1859359A (en) * | 2005-07-12 | 2006-11-08 | 上海华为技术有限公司 | Realizing method and its device for communication protocol described by abstract grammar rule |
CN104426871A (en) * | 2013-08-29 | 2015-03-18 | 中兴通讯股份有限公司 | Method and device for realizing remote calling |
Also Published As
Publication number | Publication date |
---|---|
CN105573956A (en) | 2016-05-11 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN105573956B (en) | Sequencing method and network communication method based on serializing | |
US11150874B2 (en) | API specification generation | |
CN106161381B (en) | Device and method and computer-readable medium for removing to obscure scripting language | |
TWI316660B (en) | A method, a system and computer readable medium with related instructions recorded thereon of facilitating i/o operation in a pageable mode virtual environment absent intervention of a host of the pageable mode virtual environment | |
CN110249307A (en) | System and method for executing primary contract on block chain | |
CN105378661B (en) | Resource packet index | |
Doglio et al. | REST API Development with Node. js | |
US10733152B2 (en) | System and method for implementing native contract on blockchain | |
US9582666B1 (en) | Computer system for improved security of server computers interacting with client computers | |
CN108491236A (en) | A kind of plug-in loading method, device and computer readable storage medium | |
US20050055398A1 (en) | Protocol agnostic request response pattern | |
CN105051687B (en) | Using dispositions method and equipment | |
CN106713423B (en) | The processing method and processing device of distributed data in a kind of cloud access base site controller | |
US11349816B2 (en) | Obfuscating source code sent, from a server computer, to a browser on a client computer | |
CN106970820A (en) | Code storage method and code storage | |
CN104243475A (en) | Method and system for dynamic mixing based on WEB reverse proxy | |
CN104951275B (en) | The processing method and system of computer instruction data | |
CN113064583B (en) | Multistage page route jump method, device, computer equipment and storage medium | |
CN103297482B (en) | Information processing method and equipment | |
CN105843809A (en) | Data processing method and device | |
KR102040561B1 (en) | Inheritance based coding practice content development system using game for coding learning and method thereof | |
CN105069064B (en) | Acquisition methods and device, the method for pushing and device of vocabulary | |
CN108347471A (en) | Obtain the method, apparatus and system of third party's user information | |
CN104123365B (en) | Web page resources method for down loading and system | |
Paulweber et al. | Structuring the state and behavior of ASMs: introducing a trait-based construct for abstract state machine languages |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |