'\" t .\" Title: mtbl_varint .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Generator: DocBook XSL Stylesheets v1.78.1 .\" Date: 01/31/2014 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" .TH "MTBL_VARINT" "3" "01/31/2014" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" mtbl_varint \- Variable\-width encoding and decoding of 32 and 64 bit integers .SH "SYNOPSIS" .sp \fB#include \fR .sp \fBunsigned mtbl_varint_length(uint64_t \fR\fB\fIvalue\fR\fR\fB);\fR .sp \fBunsigned mtbl_varint_length_packed(const uint8_t *\fR\fB\fIbuf\fR\fR\fB, size_t \fR\fB\fIlen_buf\fR\fR\fB);\fR .sp \fBsize_t mtbl_varint_encode32(uint8_t *\fR\fB\fIptr\fR\fR\fB, uint32_t \fR\fB\fIvalue\fR\fR\fB);\fR .sp \fBsize_t mtbl_varint_encode64(uint8_t *\fR\fB\fIptr\fR\fR\fB, uint64_t \fR\fB\fIvalue\fR\fR\fB);\fR .sp \fBsize_t mtbl_varint_decode32(const uint8_t *\fR\fB\fIptr\fR\fR\fB, uint32_t *\fR\fB\fIvalue\fR\fR\fB);\fR .sp \fBsize_t mtbl_varint_decode64(const uint8_t *\fR\fB\fIptr\fR\fR\fB, uint64_t *\fR\fB\fIvalue\fR\fR\fB);\fR .SH "DESCRIPTION" .sp \fBmtbl_varint_encode32\fR() and \fBmtbl_varint_encode64\fR() write the 32 or 64 bit quantity, respectively, in the argument \fIvalue\fR to the buffer in the argument \fIdst\fR\&. The quantity will be written in using a variable\-width encoding that uses at most 5 bytes for a 32 bit quantity or 10 bytes for a 64 bit quantity\&. .sp \fBmtbl_varint_decode32\fR() and \fBmtbl_varint_decode64\fR() read the 32 or 64 bit varint quantity, respectively, in the argument \fIptr\fR\&. The quantity read will be placed in the argument \fIvalue\fR\&. .sp Bounds checking must be performed by the caller\&. .SH "RETURN VALUE" .sp \fBmtbl_varint_encode32\fR() and \fBmtbl_varint_encode64\fR() return the number of bytes written to \fIdst\fR\&. .sp \fBmtbl_varint_decode32\fR() and \fBmtbl_varint_decode64\fR() return the number of bytes read from \fIptr\fR\&. .sp \fBmtbl_varint_length\fR() returns the number of bytes that its argument \fIvalue\fR would require in the variable\-width encoding\&. .sp \fBmtbl_varint_length_packed\fR() returns the number of bytes consumed by the variable\-width encoded quantity at its argument \fIdata\fR\&. It will read at most \fIlen_buf\fR bytes from \fIdata\fR\&. The value 0 is returned if a valid varint is not present\&.