mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-22 15:57:49 +02:00
tlv: make TlvType method for TlvType interface public
With this change, callers can now examine a struct instance of the `TlvType` instance to figure out programmatically which integer type is maps to. This'll be useful when decoding optional TLV types into a wire struct (knowing when to set it to Some vs None).
This commit is contained in:
@@ -20,10 +20,12 @@ package tlv
|
|||||||
|
|
||||||
type tlvType{{ $index }} struct{}
|
type tlvType{{ $index }} struct{}
|
||||||
|
|
||||||
func (t *tlvType{{ $index }}) typeVal() Type {
|
func (t *tlvType{{ $index }}) TypeVal() Type {
|
||||||
return {{ $index }}
|
return {{ $index }}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *tlvType{{ $index }}) tlv() {}
|
||||||
|
|
||||||
type TlvType{{ $index }} = *tlvType{{ $index }}
|
type TlvType{{ $index }} = *tlvType{{ $index }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
`
|
`
|
||||||
|
@@ -62,7 +62,7 @@ func (t *RecordT[T, V]) Record() Record {
|
|||||||
tlvRecord, ok := any(&t.Val).(RecordProducer)
|
tlvRecord, ok := any(&t.Val).(RecordProducer)
|
||||||
if !ok {
|
if !ok {
|
||||||
return MakePrimitiveRecord(
|
return MakePrimitiveRecord(
|
||||||
t.recordType.typeVal(), &t.Val,
|
t.recordType.TypeVal(), &t.Val,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ func (t *RecordT[T, V]) Record() Record {
|
|||||||
|
|
||||||
return Record{
|
return Record{
|
||||||
value: ogRecord.value,
|
value: ogRecord.value,
|
||||||
typ: t.recordType.typeVal(),
|
typ: t.recordType.TypeVal(),
|
||||||
staticSize: ogRecord.staticSize,
|
staticSize: ogRecord.staticSize,
|
||||||
sizeFunc: ogRecord.sizeFunc,
|
sizeFunc: ogRecord.sizeFunc,
|
||||||
encoder: ogRecord.encoder,
|
encoder: ogRecord.encoder,
|
||||||
|
@@ -5,7 +5,13 @@ import "fmt"
|
|||||||
// TlvType is an interface used to enable binding the integer type of a TLV
|
// TlvType is an interface used to enable binding the integer type of a TLV
|
||||||
// record to the type at compile time.
|
// record to the type at compile time.
|
||||||
type TlvType interface {
|
type TlvType interface {
|
||||||
typeVal() Type
|
// TypeVal returns the integer TLV type that this TlvType struct
|
||||||
|
// instance maps to.
|
||||||
|
TypeVal() Type
|
||||||
|
|
||||||
|
// tlv is an internal method to make this a "sealed" interface, meaning
|
||||||
|
// only this package can declare new instances.
|
||||||
|
tlv()
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate go run internal/gen/gen_tlv_types.go -o tlv_types_generated.go
|
//go:generate go run internal/gen/gen_tlv_types.go -o tlv_types_generated.go
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user