tlv: generate TLV types for custom ranges

This commit is contained in:
Oliver Gugger
2024-05-13 16:44:39 +02:00
parent 4256260544
commit 454f56d4a8
2 changed files with 1028 additions and 5 deletions

View File

@@ -8,8 +8,12 @@ import (
)
const (
numberOfTypes = 100
defaultOutputFile = "tlv_types_generated.go"
numberOfTypes uint32 = 100
// customTypeStart defines the beginning of the custom TLV type range as
// defined in BOLT-01.
customTypeStart uint32 = 65536
defaultOutputFile = "tlv_types_generated.go"
)
const typeCodeTemplate = `// Code generated by tlv/internal/gen; DO NOT EDIT.
@@ -32,9 +36,18 @@ type TlvType{{ $index }} = *tlvType{{ $index }}
func main() {
// Create a slice of items that the template can range over.
var items []struct{}
for i := uint16(0); i <= numberOfTypes; i++ {
items = append(items, struct{}{})
//
// We'll generate 100 elements from the lower end of the TLV range
// first.
items := make(map[uint32]struct{})
for i := uint32(0); i <= numberOfTypes; i++ {
items[i] = struct{}{}
}
// With the lower end generated, we'll now generate 100 records in the
// upper end of the range.
for i := customTypeStart; i <= customTypeStart+numberOfTypes; i++ {
items[i] = struct{}{}
}
tpl, err := template.New("tlv").Parse(typeCodeTemplate)

File diff suppressed because it is too large Load Diff