From aec2f9bf0872ba06f95dd27d45164d3f6020846b Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 2 Jan 2024 17:05:00 -0800 Subject: [PATCH] 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. --- tlv/record_type.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tlv/record_type.go b/tlv/record_type.go index 4c7b7906c..071716835 100644 --- a/tlv/record_type.go +++ b/tlv/record_type.go @@ -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