/// <summary> /// Method marshals byte array back into <see cref="ListNode"/>. /// Take a look at <see cref="ToBytesAsync"/> description to understand <see cref="PackedListNode"/> structure. /// </summary> public PackedListNode FromBuffer(byte[] buffer, int offset) { try { var currentId = MarshalHelper.ReadLongFromBuffer(buffer, offset); var nextId = MarshalHelper.ReadLongFromBuffer(buffer, sizeof(long) + offset); var randomId = MarshalHelper.ReadLongFromBuffer(buffer, sizeof(long) * 2 + offset); var dataSize = MarshalHelper.ReadIntFromBuffer(buffer, sizeof(long) * 3 + offset); var data = MarshalHelper.ReadUtf8StringFromBuffer(buffer, sizeof(long) * 3 + sizeof(int) + offset, dataSize); return(new PackedListNode { CurrentNodeId = currentId, NextNodeId = nextId, RandomNodeId = randomId, Data = data, ByteSize = sizeof(long) * 3 + sizeof(int) + dataSize }); } catch (Exception e) { Debug.WriteLine(e); throw new ArgumentException("Invalid data has given", e); } }