tlv+record+routing: add payload size calculation

This commit is contained in:
Joost Jager
2019-12-16 21:34:29 +01:00
parent 72a6383975
commit e8fd05e8e3
4 changed files with 121 additions and 1 deletions

View File

@@ -4,6 +4,8 @@ import (
"encoding/binary"
"errors"
"io"
"github.com/btcsuite/btcd/wire"
)
// ErrVarIntNotCanonical signals that the decoded varint was not minimally encoded.
@@ -107,3 +109,8 @@ func WriteVarInt(w io.Writer, val uint64, buf *[8]byte) error {
_, err := w.Write(buf[:length])
return err
}
// VarIntSize returns the required number of bytes to encode a var int.
func VarIntSize(val uint64) uint64 {
return uint64(wire.VarIntSerializeSize(val))
}