CN105573956A - Serialization method and serialization-based network communication method - Google Patents

Serialization method and serialization-based network communication method Download PDF

Info

Publication number
CN105573956A
CN105573956A CN201510916783.2A CN201510916783A CN105573956A CN 105573956 A CN105573956 A CN 105573956A CN 201510916783 A CN201510916783 A CN 201510916783A CN 105573956 A CN105573956 A CN 105573956A
Authority
CN
China
Prior art keywords
serializing
definition
agreement
field
type system
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.)
Granted
Application number
CN201510916783.2A
Other languages
Chinese (zh)
Other versions
CN105573956B (en
Inventor
王进
谢斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
SHENGQU INFORMATION TECHNOLOGY (SHANGHAI) Co Ltd
Original Assignee
SHENGQU INFORMATION TECHNOLOGY (SHANGHAI) Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by SHENGQU INFORMATION TECHNOLOGY (SHANGHAI) Co Ltd filed Critical SHENGQU INFORMATION TECHNOLOGY (SHANGHAI) Co Ltd
Priority to CN201510916783.2A priority Critical patent/CN105573956B/en
Publication of CN105573956A publication Critical patent/CN105573956A/en
Application granted granted Critical
Publication of CN105573956B publication Critical patent/CN105573956B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation
    • G06F13/4265Bus 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 invention provides a serialization method and a serialization-based network communication method. According to a way defined by a conventional structural body, the definition of a protocol is abstracted into a type system, and a field which needs to be serialized is pointed out; the type system of the definition and a specific protocol number are bound; and the SFINAE (Substitution Failure Is Not An Error) characteristics of a C++ template system are used for realizing the automatic serialization processing of the protocol field and a nested protocol to generate a serialized structural body. In addition, a function which is defined by aiming at the category of Lua and aims at common access permission is derived; and a derived function is used for transmitting the serialized structural body between a Lua network terminal and a C++ network terminal.

Description

Sequencing method and the network communication method based on serializing
Technical field
The present invention relates to networking technology area, more particularly, the present invention relates to a kind of sequencing method and the network communication method based on serializing.
Background technology
More optional network transmission schemes, roughly have traditional direct transport structures internal memory and the two schemes based on serializing at present.
The implementation of the first scheme is that the data in internal memory are directly sent to the other side by network, its advantage is that Structure of need does not resolve the CPU use amount therefore can saving both sides, but the data due to pod type are all fixed-length datas, therefore realization or extremely dumb is difficult at transmission list or dictionary data, sending string data major part adopts the mode of a directly setting character string the longest to transmit, all there is the situation of waste internal memory in majority of case, during transmission larger character string, waste situation is especially obvious.Not too easily realize during extended field in client and server version inconsistent needs, also cannot realize the field level verification to junk data and malicious data.
First scheme major part is foremost is agreement buffering (protocolbuffer), it is by defining a type definition file, then the mode of the code of each language is generated to realize serializing, it solve many drawbacks of the first scheme, effectively can transmit variable length data.But it also has Railway Project, first is that it does not support delphi, so cannot use for the game using delphi to do service end; Second is data volume after its serializing or larger, for higher to the bandwidth requirement of server network interaction frequently large-scale MMO (MassivelyMultiplayerOnline) game; 3rd is the situation heat more New Deal that it can not realize at not more fresh code.
Summary of the invention
Technical matters to be solved by this invention is for there is above-mentioned defect in prior art, provides a kind of and can improve run time behaviour and more easily can realize quick failure mechanism when running into rubbish or malicious data
In order to realize above-mentioned technical purpose, according to the present invention, providing a kind of sequencing method, comprising:
First step: the mode of conveniently structure definition, is abstracted into type system by the definition of agreement, and indicates the field needing serializing;
Second step: the type system of definition and specific protocol number are bound;
Third step: utilize the SFINAE characteristic of C++ template system to realize the automatic sequence process of protocol fields and nested agreement with the structure of formation sequence.
Preferably, indicate and need the step of the field of serializing to comprise: by the example needing the agreement of serializing and protocol fields information to become corresponding type system.
Preferably, indicate and need the step of the field of serializing to comprise: to be grandly included in specific in structure definition.
And, in order to realize above-mentioned technical purpose, according to the present invention, additionally providing a kind of network communication method based on serializing, comprising:
First step: the mode of conveniently structure definition, is abstracted into type system by the definition of agreement, and indicates the field needing serializing;
Second step: the type system of definition and specific protocol number are bound;
Third step: utilize the SFINAE characteristic of C++ template system to realize the automatic sequence process of protocol fields and nested agreement with the structure of formation sequence;
4th step: the function for public access rights that leading-out needle defines the class of Lua;
5th step: the structure utilizing function translation sequence between Lua network-side and C++ network-side of deriving;
6th step: amendment agreement definition, then at log-in protocol place amendment default parameters, carrys out automatic Reconfigurations file by running client, the configuration file of renewal is put into the renewal version of agreement.
Preferably, indicate and need the step of the field of serializing to comprise: by the example needing the agreement of serializing and protocol fields information to become corresponding type system.
Preferably, indicate and need the step of the field of serializing to comprise: to be grandly included in specific in structure definition.
Compare the mode of operationally Ergodic judgement type, the definition of agreement is abstracted into type system, the agreement and field information thereof that need serializing are abstracted into the example of corresponding types system, and utilize the SFINAE characteristic of C++ template system to achieve the automatic sequence process of field with nested agreement cleverly, compare other solution increased substantially run time behaviour and made code structure precision and elegance more, the degree of modularity is higher, and more easily can realize quick failure mechanism when running into rubbish or malicious data.
Accompanying drawing explanation
By reference to the accompanying drawings, and by reference to detailed description below, will more easily there is more complete understanding to the present invention and more easily understand its adjoint advantage and feature, wherein:
Fig. 1 schematically shows process flow diagram according to the preferred embodiment of the invention.
It should be noted that, accompanying drawing is for illustration of the present invention, and unrestricted the present invention.Note, represent that the accompanying drawing of structure may not be draw in proportion.Further, in accompanying drawing, identical or similar element indicates identical or similar label.
Embodiment
In order to make content of the present invention clearly with understandable, below in conjunction with specific embodiments and the drawings, content of the present invention is described in detail.
In the present invention, the SFINAE characteristic of C++ template system is utilized to generate type system, conveniently the mode of structure definition defines agreement definition, and indicate the field needing serializing, after binding the protocol number of this agreement, local data or network flow can be loaded, serializing/unserializing process is carried out to object and uses in C++ and Lua, and without the need to registering all types when communicating with Lua.
In the little version updating not upgrading C++ code only more new resources, can by the protocol profile automatically generated, unaware ground amendment agreement or newly-increased agreement use in Lua file, and the logic of original C++ code is unaffected.
Fig. 1 schematically shows process flow diagram according to the preferred embodiment of the invention.Process flow diagram shows the specific embodiment of sequencing method of the present invention and the network communication method based on serializing.
As shown in Figure 1, comprise according to the preferred embodiment of the present invention:
First step S1: the mode of conveniently structure definition, is abstracted into type system by the definition of agreement, and indicates the field needing serializing;
Such as, indicate and need the step of the field of serializing to comprise: by the example needing the agreement of serializing and protocol fields information to become corresponding type system.Alternatively, such as, indicate and need the step of the field of serializing to comprise: to be grandly included in specific in structure definition.
Second step S2: the type system of definition and specific protocol number are bound;
In concrete example, for these two steps above-mentioned, such as, first associated documents are added (such as, #Include " SDReflect.h "), then as common definition structure, define protocol type (support inherit and polymorphic), to increase a RTTI to structure grand in indicate the field needing serializing for sample for reference (demo) after having defined, then by the mode of registration loader (loader), the type system of definition and specific protocol number are bound in the cpp file of correspondence, just can arbitraryly carry out serializing or communicate with networking client.
Wherein, support to inherit and polymorphic mode comprises: the type loader support that serializing type is generated by compiling duration is inherited and polymorphic, does not need manual amendment configuration file realization succession and polymorphic feature.
Third step S3: utilize the SFINAE characteristic of C++ template system to realize the automatic sequence process of protocol fields and nested agreement with the structure of formation sequence;
Further, in order to agreement or type are carried out seamless communication between C++ network-side and Lua network-side, following 4th step S4 and the 5th step S5 can also be performed.
4th step S4: the function for public access rights that leading-out needle defines the class of Lua;
Particularly, such as, needing to derive to the method for the class of Lua definition public access rights (if need to define a general communication functions, parameter type is base class), can automatically generate the communication cryptology with Lua after running the python file generating Lua binding, then just can rely on the function of derivation free translation sequence structure between Lua and C++.
5th step S5: the structure utilizing function translation sequence between Lua network-side and C++ network-side of deriving.
Further, in order to realize the mode more New Deal by Reconfigurations file, following 6th step S6 can also be performed.
6th step S6: amendment agreement definition, then at log-in protocol place amendment default parameters, carrys out automatic Reconfigurations file by running client, the configuration file of renewal is put into the renewal version of agreement.
Like this, just can use New Deal in Lua, and now not need the .so file upgrading C++ compiling, the agreement definition in original .so file still can normally forward.(effect of python code is analytic definition header file can to generate the invoke code of C++ by Python, automatically the type in C++ and other are needed to export to C++ function registration in Lua in Lua virtual machine), after this do not need to write for often kind of serializing type craft or use maker registration type namely can transmit mutually the mechanism of all sequences structure with Lua to Lua.Newly-increased or change agreement definition can be realized by the mode of automatic generating configuration file when C++ code can not be upgraded and can realize with former .so in define and logic depositing and the mechanism be independent of each other.
Thus, in the present invention, client and the direct definition structure body of service end, and in structure, indicate which field needs serializing, namely can directly carry out communicating and seamlessly to carry out alternately with Lua script.Realize change Lua agreement definition when C++ code can not be upgraded by change configuration file and increase New Deal.
In the present invention, C++ adopts template SFINAE characteristic to realize type system, in the compiling duration automatic identification types definition field that also merging treatment is adjacent, can greatly improve performance; The succession of body support structure and polymorphic, supported protocol and STL (STL, StandardTemplateLibrary) container infinitely nested.Adopt the solution of the present invention, do not affect the existing logic of former C++ agreement by during configuration file amendment Lua agreement.And Delphi end improves performance by preservative reflex information in advance.
In addition, in concrete example, the mode that binary bits (bit) position that can be used in serializing head Sign field carries out marking realizes dynamic head-coating structure, thus makes the little as far as possible and special circumstances of the volume that needs when a large amount of parcel to ensure each bag need the demand of super large bag to be met.
When hand trip is inconvenient to upgrade binary code, the present invention revises or increases newly agreement for Lua file by the mode of Reconfigurations file, compares the version updating pattern that other solution can adapt to mobile phone environment more flexibly.
In the present invention, the mode of ergodic sequence field comprises: serializing/antitone sequence module uses template SFINAE characteristic to generate type loader system at compiling duration and do not need in the runtime repeatedly redirect to judge directly to carry out field the feature of serializing/unserializing, eliminates and dissimilar field is processed to the performance cost caused in the runtime by the mode of multiple " ifelse " statement or hash table.
In addition, it should be noted that, unless stated otherwise or point out, otherwise the term " first " in instructions, " second ", " the 3rd " etc. describe only for distinguishing each assembly, element, step etc. in instructions, instead of for representing logical relation between each assembly, element, step or ordinal relation etc.
Be understandable that, although the present invention with preferred embodiment disclose as above, but above-described embodiment and be not used to limit the present invention.For any those of ordinary skill in the art, do not departing under technical solution of the present invention ambit, the technology contents of above-mentioned announcement all can be utilized to make many possible variations and modification to technical solution of the present invention, or be revised as the Equivalent embodiments of equivalent variations.Therefore, every content not departing from technical solution of the present invention, according to technical spirit of the present invention to any simple modification made for any of the above embodiments, equivalent variations and modification, all still belongs in the scope of technical solution of the present invention protection.

Claims (7)

1. a sequencing method, is characterized in that comprising:
First step: according to the mode of structure definition, the definition of agreement is abstracted into type system, and indicates the field needing serializing;
Second step: the type system of definition and specific protocol number are bound;
Third step: utilize the SFINAE characteristic of C++ template system to realize the automatic sequence process of protocol fields and nested agreement with the structure of formation sequence.
2. according to claim 1, it is characterized in that, indicate and need the step of the field of serializing to comprise: by the example needing the agreement of serializing and protocol fields information to become corresponding type system.
3. according to claim 1, it is characterized in that, indicate and need the step of the field of serializing to comprise: by specific grand be included in structure definition in.
4., based on a network communication method for serializing, it is characterized in that comprising:
First step: the mode of conveniently structure definition, is abstracted into type system by the definition of agreement, and indicates the field needing serializing;
Second step: the type system of definition and specific protocol number are bound;
Third step: utilize the SFINAE characteristic of C++ template system to realize the automatic sequence process of protocol fields and nested agreement with the structure of formation sequence;
4th step: the function for public access rights that leading-out needle defines the class of Lua;
5th step: the structure utilizing function translation sequence between Lua network-side and C++ network-side of deriving.
5. according to claim 4, characterized by further comprising:
6th step: amendment agreement definition, then at log-in protocol place amendment default parameters, carrys out automatic Reconfigurations file by running client, the configuration file of renewal is put into the renewal version of agreement.
6. according to claim 4 or 5, it is characterized in that, indicate and need the step of the field of serializing to comprise: by the example needing the agreement of serializing and protocol fields information to become corresponding type system.
7. according to claim 4 or 5, it is characterized in that, indicate and need the step of the field of serializing to comprise: to be grandly included in specific in structure definition.
CN201510916783.2A 2015-12-10 2015-12-10 Sequencing method and network communication method based on serializing Active CN105573956B (en)

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 true CN105573956A (en) 2016-05-11
CN105573956B 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)

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106528259A (en) * 2016-11-04 2017-03-22 网易(杭州)网络有限公司 Data sending method, data receiving method, data sending device and data receiving device
CN107040539A (en) * 2017-04-20 2017-08-11 广州华多网络科技有限公司 A kind of protocol data bag construction method, device and computer system
CN108683704A (en) * 2018-04-09 2018-10-19 福建天晴数码有限公司 A kind of Socket network communications test method and its system, storage medium
CN109343836A (en) * 2018-08-31 2019-02-15 阿里巴巴集团控股有限公司 Data Serialization, data antitone sequence method, device and equipment
CN110339575A (en) * 2018-04-08 2019-10-18 腾讯科技(深圳)有限公司 It practises fraud in a kind of determining online game the method and device of user
CN113138755A (en) * 2021-04-19 2021-07-20 上海逸动医学科技有限公司 JSON serialization and deserialization optimization method and system
CN113839902A (en) * 2020-06-08 2021-12-24 腾讯科技(深圳)有限公司 Communication protocol adaptation method, device, computer equipment and storage medium
CN114697402A (en) * 2020-12-29 2022-07-01 中移物联网有限公司 Internet of things protocol serialization method and device and electronic equipment
CN115237415A (en) * 2022-09-22 2022-10-25 南京雷电信息技术有限公司 Method for realizing situation duplication under GIS platform
WO2023184285A1 (en) * 2022-03-30 2023-10-05 华为技术有限公司 Data transmission method and apparatus

Citations (4)

* Cited by examiner, † Cited by third party
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
WO2014180143A1 (en) * 2013-05-07 2014-11-13 Tencent Technology (Shenzhen) Company Limited Methods and systems for data serialization and deserialization
CN104270257A (en) * 2014-09-10 2015-01-07 烽火通信科技股份有限公司 Network element level network management service configuration adaptive system and method based on PB and XPATH
CN104426871A (en) * 2013-08-29 2015-03-18 中兴通讯股份有限公司 Method and device for realizing remote calling

Patent Citations (4)

* Cited by examiner, † Cited by third party
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
WO2014180143A1 (en) * 2013-05-07 2014-11-13 Tencent Technology (Shenzhen) Company Limited Methods and systems for data serialization and deserialization
CN104426871A (en) * 2013-08-29 2015-03-18 中兴通讯股份有限公司 Method and device for realizing remote calling
CN104270257A (en) * 2014-09-10 2015-01-07 烽火通信科技股份有限公司 Network element level network management service configuration adaptive system and method based on PB and XPATH

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
关孝峰: "《深入理解C++11 C++11新特性解析与应用》", 30 June 2013, 科学出版社 *

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106528259A (en) * 2016-11-04 2017-03-22 网易(杭州)网络有限公司 Data sending method, data receiving method, data sending device and data receiving device
CN106528259B (en) * 2016-11-04 2019-07-09 网易(杭州)网络有限公司 Data sending, receiving method and its device
CN107040539A (en) * 2017-04-20 2017-08-11 广州华多网络科技有限公司 A kind of protocol data bag construction method, device and computer system
CN110339575A (en) * 2018-04-08 2019-10-18 腾讯科技(深圳)有限公司 It practises fraud in a kind of determining online game the method and device of user
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
CN109343836A (en) * 2018-08-31 2019-02-15 阿里巴巴集团控股有限公司 Data Serialization, data antitone sequence method, device and equipment
CN109343836B (en) * 2018-08-31 2021-09-10 创新先进技术有限公司 Data serialization and data deserialization method, device and equipment
CN113839902A (en) * 2020-06-08 2021-12-24 腾讯科技(深圳)有限公司 Communication protocol adaptation method, device, computer equipment and storage medium
CN114697402A (en) * 2020-12-29 2022-07-01 中移物联网有限公司 Internet of things protocol serialization method and device and electronic equipment
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
CN115237415A (en) * 2022-09-22 2022-10-25 南京雷电信息技术有限公司 Method for realizing situation duplication under GIS platform

Also Published As

Publication number Publication date
CN105573956B (en) 2019-06-21

Similar Documents

Publication Publication Date Title
CN105573956A (en) Serialization method and serialization-based network communication method
KR101238511B1 (en) Publishing the status of and updating firmware components
US8527613B2 (en) Provisioned firmware updates using object identifiers
CN103678319B (en) Resource file update method, device and system and server
CN105512324B (en) A kind of front-end module loader of packaging file local updating
CN105068854B (en) A kind of method that the control to different product is realized using same rule
CN106713423B (en) The processing method and processing device of distributed data in a kind of cloud access base site controller
US11977637B2 (en) Technique for authentication and prerequisite checks for software updates
CN106095432B (en) Method for identifying application type
CN104008158A (en) Data verification method, verification device and mobile terminal
CN106878391A (en) The system and method for internet-of-things terminal firmware upgrade in LAN
CN107193917A (en) Whole station CONFIG.SYS lossless data update method based on IID
CN105049546B (en) A kind of Dynamic Host Configuration Protocol server is the method and device of client distribution IP address
CN103812946B (en) Method and system for online cloud updating of AR application program
WO2019169982A1 (en) Url abnormality positioning method and device, and server and storage medium
CN109617713A (en) The implementation method and server of resource dissemination
US20090187601A1 (en) Automation process system and method to upgrade from non-unicode transformation support to unicode data transformation support
CN105634863A (en) Application protocol detection method and device
CN104298521A (en) Window updating method and device
CN107438017A (en) Server system interface expander firmware upgrade method and system
CN105867974A (en) Offline updating method of CS framework application
CN102624736A (en) TL1 (transaction language 1) command verification method and TL1 command verification device
CN105516134A (en) Authentication method and system for system integration
CN105681367A (en) Method, server and client for sharing file contents
CN103744963B (en) The treating method and apparatus of target pages conversion

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