Summary of the invention
The shortcoming that the objective of the invention is to overcome prior art provides a kind of cross-platform communication means with not enough, through unified transfer standard, makes things convenient for the communication between the different platform.
Another object of the present invention is to, a kind of cross-platform communication system is provided.
In order to achieve the above object, the present invention adopts following technical scheme to realize:
A kind of cross-platform communication means carries out unifiedly to the object of different platform and the transfer standard between the binary stream, said communication means may further comprise the steps:
First platform carry out object sequenceization, converts the object of structure to binary stream by transfer standard;
Binary stream passes through Network Transmission to second platform;
Second platform carries out the object unserializing, converts the binary stream that receives to object that second platform can use by transfer standard.
Preferably, object includes at least two each and every one attribute: unique identification-UUID, and other attribute-character type when this object needs cross-platform transmission, need convert binary stream earlier to, and concrete steps are following:
Use fixing length to deposit coded format, convert binary system to;
Convert unique identification to binary system, be appended to the coded format back;
Convert other attribute to binary system, be appended to the unique identification back;
Preferably, said transfer standard is the length of frequently-used data type in internal memory of definition object properties.
Preferably, said frequently-used data type comprises Boolean, Char, Double, Float, Int, Long, Short and UUID.
Preferably, the length of said frequently-used data type in internal memory is defined as: Boolean is that 1 byte, Char are that 2 bytes, Double are that 8 bytes, Float are that 4 bytes, Int are that 4 bytes, Long are that 8 bytes, Short are that 2 bytes, UUID are 16 bytes.
In order to reach above-mentioned another purpose, the present invention adopts following technical scheme:
A kind of cross-platform communication system; Comprise the object parsing module of changing between object that at least one is used for different platform and the binary stream; Said object explanation module is arranged on that communication system operates on the client of different platform on the client of each platform, is used for the object of different platform and the transfer standard between the binary stream are unified.
Preferably, said client comprises Android client, Iphone client, Windows Mobile client, Symbian client or Web client.
Preferably, said transfer standard is the length of frequently-used data type in internal memory of definition object properties.
Preferably, said frequently-used data type comprises Boolean, Char, Double, Float, Int, Long, Short and UUID.
Preferably, the length of said frequently-used data type in internal memory is defined as: Boolean is that 1 byte, Char are that 2 bytes, Double are that 8 bytes, Float are that 4 bytes, Int are that 4 bytes, Long are that 8 bytes, Short are that 2 bytes, UUID are 16 bytes.In order to reach above-mentioned another purpose, the present invention adopts following technical scheme:
The present invention has following advantage and effect with respect to prior art:
1, the invention solves otherness between the different platform, made things convenient for the transmission and the reduction of object, thereby made things convenient for the communication between the different platform.
Embodiment
Below in conjunction with embodiment and accompanying drawing the present invention is described in further detail, but execution mode of the present invention is not limited thereto.
Embodiment
The flow chart of cross-platform communication means as shown in Figure 1, first platform and second platform are provided with cross-platform communication system, and said communication system includes the object parsing module.The object of first platform structure carry out object sequenceization through the object parsing module, converts binary stream to and passes through Network Transmission to second platform.The object parsing module of second platform carries out unserializing, converts the binary stream that receives to object that second platform can use.
Said object includes three attribute: unique identification-UUID, name-character type, sex-character type.When this object needs cross-platform transmission, need convert binary stream earlier to, step is following:
Use fixing length to deposit coded format, represent with 10001, convert binary system to like UTF-8;
Convert unique identification to binary system, be appended to the coded format back;
Convert name to binary system, be appended to the unique identification back;
Convert sex to binary system, be appended to the name back.
Object converts to behind the binary system as shown in the table:
4 bytes |
16 bytes |
4 bytes |
4 bytes |
Coded format |
Unique identification |
Name |
Sex |
Receiving platform adopts identical transformation rule, just reduciblely goes out object.Above-mentioned object also can be provided with different attributes according to the situation of reality, and unique identification is to exist, and except that unique identification, other attribute all is character type datas.
The present invention is applied to the topological as shown in Figure 2 of portable terminal.The client of different platform (Android, Iphone, Windows Mobile, Symbian, Web) all is provided with the object parsing module, and gateway server also is provided with the object parsing module.Different platforms is used different computer languages, and inner communication standard is also different.The object parsing module becomes binary stream with the object of platform structure with unified standard handovers; Binary stream transmits through network; The object parsing module of receiving platform converts the binary stream that receives to object that platform can use; Thereby solved the otherness between the different platform, made things convenient for cross-platform communication.
The A platform adopts Java language, and the B platform adopts C# language, if object of the Java of A platform structure need let the C# of B platform use, changes through the object parsing module.Because each object all is made up of the attribute of fundamental type, so the present invention defines the length of data type in internal memory commonly used, the definition standard is as shown in the table:
Data type |
Definition length |
Boolean |
1 byte |
Char |
2 bytes |
Double |
8 bytes |
?Float |
4 bytes |
?Int |
4 bytes |
?Long |
8 bytes |
?Short |
2 bytes |
?UUID |
16 bytes |
All use this definition standard between two platforms, then can realize the cross-platform transmission of object.
The attribute and the corresponding data types of A platform structure object " client a " are as shown in the table:
Name |
Zhang San |
?String |
Sex |
The man |
?String |
The address |
Guangzhou |
?String |
Age |
|
40 |
?Int |
Party member whether |
Be |
?Boolean |
The consumption amount of money |
400000000.24 |
?Double |
Binary stream structure after changing through the object parsing module of A platform is as shown in Figure 3.
After the object parsing module of B platform receives binary stream, take out one by one, convert the object that C# can use to according to memory block.
The foregoing description is a preferred implementation of the present invention; But execution mode of the present invention is not restricted to the described embodiments; Other any do not deviate from change, the modification done under spirit of the present invention and the principle, substitutes, combination, simplify; All should be the substitute mode of equivalence, be included within protection scope of the present invention.