Skip to content

Commit

Permalink
Merge pull request #9171 from ellemouton/genUnsignedTLVRanges
Browse files Browse the repository at this point in the history
tlv: generate types for gossip unsigned range
  • Loading branch information
guggero authored Oct 16, 2024
2 parents fb5e7f4 + 63d5e92 commit af6b88a
Show file tree
Hide file tree
Showing 2 changed files with 4,547 additions and 507 deletions.
26 changes: 23 additions & 3 deletions tlv/internal/gen/gen_tlv_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@ import (
)

const (
numberOfTypes uint32 = 100
numberOfTypes uint32 = 300

// customTypeStart defines the beginning of the custom TLV type range as
// defined in BOLT-01.
customTypeStart uint32 = 65536
defaultOutputFile = "tlv_types_generated.go"
customTypeStart uint32 = 65536

// pureTLVSecondSignedTypeRangeStart defines the first TLV type of the
// second defined signed TLV range used in pure TLV messages.
pureTLVSecondSignedTypeRangeStart uint32 = 1000000000

// pureTLVSecondUnsignedTypeRangeStart defines the first TLV type of the
// second defined unsigned TLV range used in pure TLV messages.
pureTLVSecondUnsignedTypeRangeStart uint32 = 3000000000

defaultOutputFile = "tlv_types_generated.go"
)

// typeMarkers defines any adhoc TLV types we want to generate.
var typeMarkers = map[uint32]struct{}{
pureTLVSecondSignedTypeRangeStart: {},
pureTLVSecondUnsignedTypeRangeStart: {},
}

const typeCodeTemplate = `// Code generated by tlv/internal/gen; DO NOT EDIT.
package tlv
Expand Down Expand Up @@ -50,6 +65,11 @@ func main() {
items[i] = struct{}{}
}

// We'll also generate any marker types.
for t := range typeMarkers {
items[t] = struct{}{}
}

tpl, err := template.New("tlv").Parse(typeCodeTemplate)
if err != nil {
panic(err)
Expand Down
Loading

0 comments on commit af6b88a

Please sign in to comment.