1. xml
The longest way to use, this standard is also very good. Needless to say.
< Protocol >
< Move >
< From >
< Point > 0, 0
< Point />
</ From >
< To >
< Point > 30,30
</ Point >
</ To >
</ Mvoe >
< Attack >
....
....
....
</ Attack >
</ Protocol >
2. JSON
[{0}/* from */, {30, 30}/* to */}/* move */, {0, 0}/* from */{30, 30}/* to */}/* attack */]
Of course, the above JSON is not a good definition method, not very object-oriented, but it is still a feasible and resolvable method. Careful friends can carefully study the differences with XML.
3. Binary
FFFF (length) 0001 (MOVE) 00000000 (from: x = 0) 00000000 (from Y = 0) 00011110 (to X = 30) 00011110 to (y = 30) 0010 (attack) 00000000 (00000000 00000000 00000000 0010 zookeeper
The Protocol definition is so simple that it is actually more complex and complete.
Start with the several-byte Definition
The type of the first protocol uses 4 bits, such as 0001 move, 0010 attack
- Move from X, a byte,
- From y of the move Protocol, one byte,
- X of the move protocol to, one byte,
- Y of the move Protocol, one byte.
- Next is the second protocol. 0010, attack
The preceding three methods are commonly used to define data structures.
Resolution and analysis follow up later...