Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tlv/record_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,30 @@ func ZeroRecordT[T TlvType, V any]() RecordT[T, V] {
Val: v,
}
}

// BigSizeT is a high-order type that represents a TLV record that encodes an
// integer as a BigSize value in the stream.
type BigSizeT[T constraints.Integer] struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🫡

// We'll store the base value in the struct as a uin64, but then expose
// a public method to cast to the specified type.
v uint64
}

// NewBigSizeT creates a new BigSizeT type from a given integer type.
func NewBigSizeT[T constraints.Integer](val T) BigSizeT[T] {
return BigSizeT[T]{
v: uint64(val),
}
}

// Int returns the underlying integer value of the BigSize record.
func (b BigSizeT[T]) Int() T {
return T(b.v)
}

// Record returns the underlying record interface for the record type.
func (t *BigSizeT[T]) Record() Record {
// We use a zero value for the type here as this should be used with
// the higher order RecordT type.
return MakeBigSizeRecord(0, &t.v)
}