protected override async Task InitializeAsync(IMessageBufferReader reader, CancellationToken cancellationToken) { await base.InitializeAsync(reader, cancellationToken); Value = await reader.PushByteFromStreamAsync(cancellationToken) == 0xFF; if (await reader.PushByteFromStreamAsync(cancellationToken) != 0x00) { throw new InvalidOperationException(); } }
protected override async Task InitializeAsync(IMessageBufferReader reader, CancellationToken cancellationToken) { await base.InitializeAsync(reader, cancellationToken); Count = await reader.PushShortFromStreamAsync(cancellationToken); var byteCount = await reader.PushByteFromStreamAsync(cancellationToken); await reader.PushFromStreamAsync(byteCount, cancellationToken); MessageBuffer = new MessageBufferSpan(reader.Buffer, (ushort)(reader.Buffer.Length - byteCount - 2), byteCount); }
public static async Task <int> PushShortFromStreamAsync(this IMessageBufferReader reader, CancellationToken cancellationToken) => (int)((await reader.PushByteFromStreamAsync(cancellationToken) << 8) + (await reader.PushByteFromStreamAsync(cancellationToken) << 0));