varint: Add helper function for getting varlen size

Needed to calculate somethings for building dual funding txs
This commit is contained in:
lisa neigut 2019-09-18 19:03:13 -05:00 committed by Rusty Russell
parent cb2cad8c94
commit 496d2cae5f
2 changed files with 14 additions and 0 deletions

View File

@ -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;

View File

@ -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);