tlv: add new RecordT[T, V] utility type

In this commit, we add a new type, `RecordT[T, V]` to reduce some of the
common boiler plate for TLV types. This type lets you take either a
primitive type, or an existing Record, and gain common methods used to
create tlv streams.

It also serves as extra type annotation as well, since wire structs can
use this to wrap any existing type and gain the relevant record methods.

This implementation ensures that the very definition of the field also
binds the TLV type value. It does this by using the generated code to
map a struct like TlvType1 to an actually Type like Type(1).
This commit is contained in:
Olaoluwa Osuntokun
2023-10-27 18:44:48 -07:00
parent c304c2a8bb
commit 63e86b72c5
4 changed files with 187 additions and 3 deletions

View File

@@ -5,7 +5,9 @@ require (
github.com/btcsuite/btcd/btcec/v2 v2.1.3
github.com/davecgh/go-spew v1.1.1
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1
github.com/lightningnetwork/lnd/fn v1.0.0
github.com/stretchr/testify v1.8.2
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
)
require (
@@ -14,7 +16,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/sys v0.13.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)