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:
Olaoluwa Osuntokun 2024-01-02 17:05:00 -08:00
parent 09afc92215
commit aec2f9bf08
No known key found for this signature in database
GPG Key ID: 3BBD59E99B280306

View File

@ -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.
// This can be used when a TLV record doesn't always need to be present (ok to
// be odd).
@ -87,6 +94,14 @@ type OptionalRecordT[T TlvType, V any] struct {
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.
func ZeroRecordT[T TlvType, V any]() RecordT[T, V] {
var v V