mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-19 21:31:04 +02:00
tlv: add TlvType method to RecordT
This will be useful when decoding optional TLV records, as we can use this to look up in the `typeMap` for a given field to see if we decoded it or not.
This commit is contained in:
parent
09afc92215
commit
aec2f9bf08
@ -80,6 +80,13 @@ func (t *RecordT[T, V]) Record() Record {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TlvType returns the type of the record. This is the value used to identify
|
||||||
|
// this type on the wire. This value is bound to the specified TlvType type
|
||||||
|
// param.
|
||||||
|
func (t *RecordT[T, V]) TlvType() Type {
|
||||||
|
return t.recordType.TypeVal()
|
||||||
|
}
|
||||||
|
|
||||||
// OptionalRecordT is a high-order type that represents an optional TLV record.
|
// OptionalRecordT is a high-order type that represents an optional TLV record.
|
||||||
// This can be used when a TLV record doesn't always need to be present (ok to
|
// This can be used when a TLV record doesn't always need to be present (ok to
|
||||||
// be odd).
|
// be odd).
|
||||||
@ -87,6 +94,14 @@ type OptionalRecordT[T TlvType, V any] struct {
|
|||||||
fn.Option[RecordT[T, V]]
|
fn.Option[RecordT[T, V]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TlvType returns the type of the record. This is the value used to identify
|
||||||
|
// this type on the wire. This value is bound to the specified TlvType type
|
||||||
|
// param.
|
||||||
|
func (t *OptionalRecordT[T, V]) TlvType() Type {
|
||||||
|
zeroRecord := ZeroRecordT[T, V]()
|
||||||
|
return zeroRecord.TlvType()
|
||||||
|
}
|
||||||
|
|
||||||
// ZeroRecordT returns a zero value of the RecordT type.
|
// ZeroRecordT returns a zero value of the RecordT type.
|
||||||
func ZeroRecordT[T TlvType, V any]() RecordT[T, V] {
|
func ZeroRecordT[T TlvType, V any]() RecordT[T, V] {
|
||||||
var v V
|
var v V
|
||||||
|
Loading…
x
Reference in New Issue
Block a user