12bf88351SAaron Miller## Couchstore Data Types
22bf88351SAaron Miller
32bf88351SAaron MillerStruct members not listed should be considered internal to Couchstore.
42bf88351SAaron Miller
50689f161SAaron Miller### sized\_buf
62bf88351SAaron Miller    struct sized_buf {
72bf88351SAaron Miller        char* buf;
82bf88351SAaron Miller        size_t size;
92bf88351SAaron Miller    }
102bf88351SAaron Miller
110689f161SAaron MillerCouchstore uses `sized_buf`s to point to data buffers.
122bf88351SAaron Miller
132bf88351SAaron Miller### DocInfo
142bf88351SAaron Miller    struct DocInfo {
152bf88351SAaron Miller        sized_buf id;
162bf88351SAaron Miller        uint64_t db_seq;
172bf88351SAaron Miller        uint64_t rev_seq;
182bf88351SAaron Miller        sized_buf rev_meta;
192bf88351SAaron Miller        int deleted;
202bf88351SAaron Miller        uint8_t content_meta;
212bf88351SAaron Miller    }
222bf88351SAaron Miller
232bf88351SAaron Miller* `id` - Document ID
242bf88351SAaron Miller* `db_seq` - Change sequence number the document was inserted at.
252bf88351SAaron Miller* `rev_seq` - The version number of the document
262bf88351SAaron Miller* `rev_meta` - Revision metadata. Used by ep-engine to store CAS value, expiry time, and flags
272bf88351SAaron Miller* `deleted` - 1 if document should be considered "deleted" and not subject to indexing, otherwise 0.
282bf88351SAaron Miller* `content_meta` - Number field used to store flags indicating metadata about the document content (is it JSON, etc.)
292bf88351SAaron Miller
300689f161SAaron Miller#### The `content_meta` field
31245f7f5cSAaron Miller
32245f7f5cSAaron Miller* The least-significant two bits are used to encode why/whether the body is or is not JSON
330689f161SAaron Miller    * 0 - Document body *is* JSON
340689f161SAaron Miller    * 1 - Inserted data was not valid JSON
350689f161SAaron Miller    * 2 - Inserted data was valid JSON, but contained a key reserved for internal use, such as one with a `$` prefix.
360689f161SAaron Miller    * 3 - The document was inserted in non-JSON mode.
370689f161SAaron Miller* If the most-significant bit is set the document body data has been compressed with snappy.
38245f7f5cSAaron Miller
392bf88351SAaron MillerWhen saving documents with `save_doc` or `save_docs`, `id`, `rev_seq`, `rev_meta`, `deleted`, and `content_meta` must be set on the `DocInfo`s passed to Couchstore. The `db_seq` is determined at insert time.
402bf88351SAaron Miller
410689f161SAaron Miller#### The `rev_meta` field
420689f161SAaron Miller
430689f161SAaron Miller[128 bit binary value]
440689f161SAaron Miller| 64 bits  | 32 bits    | 32 bits    |
450689f161SAaron Miller-----------|------------|------------|
460689f161SAaron Miller CAS Value | Expiration | User flags |
470689f161SAaron Miller
480689f161SAaron Miller All values are Big Endian.
490689f161SAaron Miller
500689f161SAaron Miller * CAS Value - Random nonce value set by Memcached, used to allow ensuring value has not been modified since it was read when writing.
510689f161SAaron Miller * Expiration - 32 bit timestamp for value expiry time. 0 if item does not expire.
520689f161SAaron Miller * User flags - Memcache API allows users to set this 32 bit number along with values, it is not used by memcached internally.
532bf88351SAaron Miller
542bf88351SAaron Miller### Doc
552bf88351SAaron Miller    struct Doc {
562bf88351SAaron Miller        sized_buf id;
572bf88351SAaron Miller        sized_buf data;
582bf88351SAaron Miller    }
592bf88351SAaron Miller
60acc8d8c5SAaron Miller`id` contains the document ID, `data` contains the document body data. Couchstore does not compress or modify the body data in any way, unless the COMPRESS_DOC_BODIES or DECOMPRESS_DOC_BODIES flags are passed to the read and write functions, then it will check the `content_meta` of the corresponding doc info to see if it should compress or decompress the doc data.
612bf88351SAaron Miller
622bf88351SAaron Miller### LocalDoc
632bf88351SAaron Miller    struct LocalDoc {
642bf88351SAaron Miller        sized_buf id;
652bf88351SAaron Miller        sized_buf json;
662bf88351SAaron Miller        int deleted;
672bf88351SAaron Miller    }
682bf88351SAaron Miller
692bf88351SAaron Miller* `id`  - The local document ID, it must start with `_local/`
702bf88351SAaron Miller* `json` - The local document body.
712bf88351SAaron Miller* `deleted` - if set to 1 on a LocalDoc passed to save_local_doc, `json` will be ignored, and the local document with the ID in `id` will be removed, if it exists.
722bf88351SAaron Miller
732bf88351SAaron Miller
742bf88351SAaron Miller## C API
752bf88351SAaron Miller
762bf88351SAaron MillerDocumented in `include/libcouchstore/couch_db.h`
772bf88351SAaron Miller
78