Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private class PayloadHeader
- {
- private readonly uint value;
- public ushort Length => (ushort)((value >> 20) << 4);
- public uint Channel => 0b000_0000_0000_1111_1111_1111_1111_1111 & value;
- public PayloadHeader(uint length, uint channel)
- {
- if ((length & 15) > 0) throw new Exception("Length must be a multiple of 16"); else length >>= 4;
- if (length > 3840) throw new Exception("Length cannot be greater than 61,440");
- if (channel > 1048575) throw new Exception("Channel cannot be greater than 1,048,575");
- value = (length << 20) | channel;
- }
- public PayloadHeader(byte[] data)
- {
- if (data.Length == 4) value = BitConverter.ToUInt32(data, 0);
- else throw new Exception("PayloadHeader must be 4 bytes in length");
- }
- public byte[] ToArray() => BitConverter.GetBytes(value);
- }
Advertisement
Add Comment
Please, Sign In to add comment