Embedded SDK
Embedded SDK
Functions
varint.c File Reference
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "varint.h"
#include "write.h"
#include "read.h"
Include dependency graph for varint.c:

Go to the source code of this file.

Functions

uint8_t varint_size (uint64_t value)
 
int varint_read (const uint8_t *in, size_t in_len, uint64_t *value)
 
int varint_write (uint8_t *out, size_t offset, uint64_t value)
 

Function Documentation

◆ varint_read()

int varint_read ( const uint8_t in,
size_t  in_len,
uint64_t *  value 
)

Read Bitcoin-like varint from byte buffer.

See also
https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer
Parameters
[in]inPointer to input byte buffer.
[in]in_lenLength of the input byte buffer.
[out]valuePointer to 64-bit unsigned integer to output varint.
Returns
number of bytes read (1, 3, 5 or 9 bytes), -1 otherwise.

Definition at line 42 of file varint.c.

◆ varint_size()

uint8_t varint_size ( uint64_t  value)

Size of value represented as Bitcoin-like varint.

See also
https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer
Parameters
[in]value64-bit unsigned integer to compute varint size.
Returns
number of bytes to write value as varint (1, 3, 5 or 9 bytes).

Definition at line 25 of file varint.c.

◆ varint_write()

int varint_write ( uint8_t out,
size_t  offset,
uint64_t  value 
)

Write Bitcoin-like varint to byte buffer.

See also
https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer
Parameters
[out]outPointer to output byte buffer.
[in]offsetOffset in the output byte buffer.
[in]value64-bit unsigned integer to write as varint.
Returns
number of bytes written (1, 3, 5 or 9 bytes), -1 otherwise.

Definition at line 79 of file varint.c.