Skip to content

Commit

Permalink
Merge pull request #8748 from guggero/custom-tlv-types
Browse files Browse the repository at this point in the history
tlv: generate TLV types for custom ranges
  • Loading branch information
guggero committed May 14, 2024
2 parents 130c499 + 454f56d commit 9d358bc
Show file tree
Hide file tree
Showing 2 changed files with 1,028 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tlv/internal/gen/gen_tlv_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit 9d358bc

Please sign in to comment.