Context
I'm have a file with the following structure:
[ProtoContract]
public class Data
{
[ProtoMember(1)]
public string Header { get; set; }
[ProtoMember(2)]
public byte[] Body { get; set; }
}
The code that reads / writes the data to a file is running on a asp.net mvc webapi context. I'm trying to keep every blocking IO async to minimize blocking and achieve the best scalability. Reading and writing from files does support ReadAsync, WriteAsync and CopyToAsync.
The body can be reasonably large (>> header) and I only need to read the body if the header matches some specific criteria.
I can partially read and deserialize the header synchronously and read and deserialize the body the same way by using the approach explained in Deserialize part of a binary file
Problem
How can I use asynchronous file IO to do exactly the same, reading and deserializing the header Async and reading and deserializing the body the same way?
I've read Asynchronous protobuf serialization is not an option.