public async Task <TPayload> DeserializeAsync <TPayload>(byte[] payload) { using (var stream = new MemoryStream(payload)) { var buf = new byte[sizeof(uint)]; stream.Seek(sizeof(byte), SeekOrigin.Begin); stream.Read(buf, 0, sizeof(uint)); if (BitConverter.IsLittleEndian) { Array.Reverse(buf); } var uintSchemaId = BitConverter.ToUInt32(buf, 0); var schema = await _schemaRegistryClient.GetByIDAsync((int)uintSchemaId); var serializer = GetDeserializer <TPayload>(schema.ToString()); //stream.Seek(sizeof(byte) + sizeof(uint), SeekOrigin.Begin); return(serializer.Deserialize(stream)); } }