/// <summary> /// Deserializes a ErrorProtectedBlock from a byte array. /// </summary> /// <param name="bytes">The byte array to deserialize from.</param> /// <returns></returns> public static ErrorProtectedBlock Deserialize(byte[] bytes) { ErrorProtectedBlock ret = new ErrorProtectedBlock { errorProtectionType = (ErrorProtectionType)bytes[0], data = new byte[BitConverter.ToUInt16(bytes, 1)] }; Array.Copy(bytes, 3, ret.data, 0, ret.data.Length); byte len = GetErrorProtectionLength(ret.errorProtectionType); Array.Copy(bytes, 3 + ret.data.Length, ret.errorProtection, 0, len); return(ret); }
/// <summary> /// Serializes a given ErrorProtectedBlock to a byte array. /// </summary> /// <param name="block"></param> /// <returns></returns> public static byte[] Serialize(ErrorProtectedBlock block) { /* * i - l - name * 0 - 1 - protection type * 1 - 2 - data len * 3 - X - data * X - X - error protection */ byte[] ret = new byte[3 + block.data.Length + block.errorProtection.Length]; ret[0] = (byte)block.errorProtectionType; Array.Copy(BitConverter.GetBytes((ushort)block.data.Length), 0, ret, 1, 2); Array.Copy(block.data, 0, ret, 3, block.data.Length); Array.Copy(block.errorProtection, 0, ret, 3 + block.data.Length, block.errorProtection.Length); return(ret); }