Skip to content

Serialization and deserialization of binary data streams in networks for Unity / NetCore

License

Notifications You must be signed in to change notification settings

dudu502/protocol_structure_generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Protocol Structures Serialization and Deserialization

Introduce

Supported types:

Protocol C#
int32 int
uint32 uint
int16 short
uint16 ushort
byte byte
int64 long
uint64 ulong
float float
double double
string string
bool bool

How to generate protocol structures?

  • Use Generator.exe in CMD to generator protocol structures.
Generator.exe -s [protocol_source_file_path.yaml] -o [output_folder_path]

Generated data structures

Examples generated from a protocols.yaml

How to use protocol structures?

Array format For example PtInt32List:

PtInt32List int32List = new PtInt32List();
int32List.SetElements(new List<int>() { 0, 1, 2, 3, 4, 5, 6 });
byte[] bytes = PtInt32List.Write(int32List);
File.WriteAllBytes(Path.Combine(Environment.CurrentDirectory, "int32list.bin"),bytes);
//----Binary data in int32list.bin----
//0107 0000 0000 0000 0001 0000 0002 0000
//0003 0000 0004 0000 0005 0000 0006 0000
//00 
PtInt32List newInt32List = PtInt32List.Read( File.ReadAllBytes(Path.Combine(Environment.CurrentDirectory, "int32list.bin")));
Console.WriteLine(string.Join(" ", newInt32List.Elements)); // 0 1 2 3 4 5 6

Nested structure for exmaple PtRoomList:

PtRoomList ptRoomList = new PtRoomList();
List<PtRoom> ptRooms = new List<PtRoom>();
PtRoom room = new PtRoom();
room.SetMapId(100);
room.SetMaxPlayerCount(12);
List<PtRoomPlayer> ptRoomPlayers = new List<PtRoomPlayer>();
PtRoomPlayer ptRoomPlayer = new PtRoomPlayer();
ptRoomPlayer.Setheight(20.3f);
ptRoomPlayer.SetEnable(true);
ptRoomPlayer.SetEntityId(2001);
ptRoomPlayer.SetNickName("Jerry");
ptRoomPlayer.SetPassword("*123");
ptRoomPlayer.Setpower(39999.4455);
ptRoomPlayer.SetStatus(30);
ptRoomPlayer.SetTeamId(1);
ptRoomPlayer.SetUserId(93999);
ptRoomPlayer.SetUUID(99999999999);
ptRoomPlayers.Add(ptRoomPlayer);
room.SetPlayers(ptRoomPlayers);
room.SetRoomId(3);
room.SetRoomOwnerUserId("room user abc");
room.SetStatus(20);
ptRooms.Add(room);
ptRoomList.SetRooms(ptRooms);
var bytes = PtRoomList.Write(ptRoomList);
File.WriteAllBytes(Path.Combine(Environment.CurrentDirectory, "roomList.bin"), bytes);
//----Binary data in roomList.bin----
//0101 0000 0000 523f 0300 0000 1464 0000
//0000 0d72 6f6f 6d20 7573 6572 2061 6263
//0c01 0000 0000 32ff 03d1 0700 0001 0005
//4a65 7272 792f 6f01 0000 0000 00ff e776
//4817 0000 0000 042a 3132 331e 0166 66a2
//414c 3789 41ee 87e3 40
var newRoomList = PtRoomList.Read(bytes);

About

Serialization and deserialization of binary data streams in networks for Unity / NetCore

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages