Browse Source

varint: Add helper function for getting varlen size

Needed to calculate somethings for building dual funding txs
travis-debug
lisa neigut 5 years ago
committed by Rusty Russell
parent
commit
496d2cae5f
  1. 11
      bitcoin/varint.c
  2. 3
      bitcoin/varint.h

11
bitcoin/varint.c

@ -1,5 +1,16 @@
#include "varint.h"
size_t varint_size(varint_t v)
{
if (v < 0xfd)
return 1;
if (v <= 0xffff)
return 3;
if (v <= 0xffffffff)
return 5;
return 9;
}
size_t varint_put(u8 buf[VARINT_MAX_LEN], varint_t v)
{
u8 *p = buf;

3
bitcoin/varint.h

@ -9,6 +9,9 @@
#define VARINT_MAX_LEN 9
/* Calculate bytes used (up to 9) */
size_t varint_size(varint_t v);
/* Returns bytes used (up to 9) */
size_t varint_put(u8 buf[VARINT_MAX_LEN], varint_t v);

Loading…
Cancel
Save