mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
varint: Add helper function for getting varlen size
Needed to calculate somethings for building dual funding txs
This commit is contained in:
parent
cb2cad8c94
commit
496d2cae5f
@ -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;
|
||||
|
@ -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…
Reference in New Issue
Block a user