| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL.CRDT; |
| | 4 | |
|
| | 5 | | namespace KernelCommunication |
| | 6 | | { |
| | 7 | | // Deserialize kernel binary messages (BigEndian) |
| | 8 | | public static class KernelBinaryMessageDeserializer |
| | 9 | | { |
| | 10 | | public static IEnumerator<object> Deserialize(IntPtr intPtr, int messageLength) |
| | 11 | | { |
| 3 | 12 | | return Deserialize(new UnmanagedMemoryReader(intPtr, messageLength)); |
| | 13 | | } |
| | 14 | |
|
| | 15 | | public static IEnumerator<object> Deserialize(byte[] bytes) |
| | 16 | | { |
| 6 | 17 | | return Deserialize(new ByteArrayReader(bytes)); |
| | 18 | | } |
| | 19 | |
|
| | 20 | | public static IEnumerator<object> Deserialize(IBinaryReader reader) |
| | 21 | | { |
| | 22 | | const int headerLength = 8; |
| | 23 | |
|
| 38 | 24 | | while (reader.CanRead()) |
| | 25 | | { |
| 25 | 26 | | int messageLength = reader.ReadInt32(); |
| 25 | 27 | | CrdtMessageType messageType = (CrdtMessageType)reader.ReadInt32(); |
| | 28 | |
|
| 25 | 29 | | if (messageLength <= BinaryMessageConstants.MESSAGE_HEADER_LENGTH) |
| | 30 | | { |
| | 31 | | continue; |
| | 32 | | } |
| | 33 | |
|
| | 34 | | switch (messageType) |
| | 35 | | { |
| | 36 | | case CrdtMessageType.PUT_COMPONENT: |
| | 37 | | case CrdtMessageType.DELETE_COMPONENT: |
| 19 | 38 | | yield return CRDTDeserializer.Deserialize(reader, messageType); |
| 17 | 39 | | break; |
| | 40 | | default: |
| 6 | 41 | | reader.Skip(messageLength - headerLength); |
| | 42 | | break; |
| | 43 | | } |
| | 44 | | } |
| 13 | 45 | | } |
| | 46 | | } |
| | 47 | | } |