Re-implemented binary storage format from Couchbase Java 1.x SDK.

Change-Id: I1034443cdded728ec9a44933ad0241381dd2a027