Method PersistedOctetsOf
- Namespace
- MailFathom.Infrastructure.Persistence.Settings
- Assembly
- MailFathom.Infrastructure.dll
PersistedOctetsOf(string)
Measures a candidate as the database will store it rather than as it was composed.
public static int PersistedOctetsOf(string json)
Parameters
jsonstringThe candidate document.
Returns
- int
An upper bound on the octets the stored document occupies.
Remarks
The two directions have to agree, because there is one bound and the read is what enforces the other half of it:
the reader measures octet_length("Document"::text), which is PostgreSQL's own rendering of the value, and
that rendering is not the compact form a candidate is composed as. It puts a space after every colon and after
every comma, so a document of many small keys is stored materially larger than it was written — and a candidate
accepted just under the bound on its compact length would persist a row the next start refuses to read.
An upper bound rather than the exact figure, and deliberately so. Two properties per pair is one octet more than the first pair of each object actually takes, and the rendering can only shrink a document elsewhere — duplicate keys are dropped and insignificant whitespace is removed, neither of which a candidate composed here carries. The slack is a handful of octets against a megabyte, and it errs towards refusing a document early rather than storing one that cannot be read back.
Exceptions
- ArgumentNullException
Thrown when
jsonis null.- JsonException
Thrown when the candidate is not JSON at all.