Merge pull request #8748 from guggero/custom-tlv-types

tlv: generate TLV types for custom ranges
This commit is contained in:
Oliver Gugger 2024-05-14 09:02:32 +02:00 committed by GitHub
commit 9d358bc649
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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