Generating DMatrix in binary format



I generally create my data sets in csv or libsvm format, create an DMatrix, and save it in binary format for quicker re-loading when I want to re-use the data.

I was wondering if it would be possible/easy to directly generate the data in binary format to avoid having to do this. Is there a specification of the binary format, or some example code that read/writes the binary format?