Skip to content

Commit

Permalink
RegisterSchema per golang package #490: include all schema nodes (#545)
Browse files Browse the repository at this point in the history
Fixes #490 after
2a85fea
collected the node IDs incorrectly.

This uses the list of IDs after `resolveName()` has recursively
scanned the nodeMap and gathered all the IDs in the capnp file.
The previous commit used only the top-level file ID.

For example,
https://github.com/capnproto/go-capnp/blob/main/flowcontrol/internal/test-tool/writer.capnp.go
now gets generated with:

```
func RegisterSchema(reg *schemas.Registry) {
	reg.Register(&schemas.Schema{
		String: schema_aca73f831c7ebfdd,
		Nodes: []uint64{
			0xf82e58b4a78f136b,
		},
		Compressed: true,
	})
}
```

This commit fixes the above generated code, and includes the following:

`0x80b8cd5f44e3c477,`

`0xd939de8c6024e7f8,`
  • Loading branch information
davidhubbard committed Sep 14, 2023
1 parent 2a85fea commit ee48d50
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions capnpc-go/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,8 @@ func makeNodeTrees(req schema.CodeGeneratorRequest) (nodeTrees, error) {
f.pkg = ann.Package
f.imp = ann.Import
nnodes, _ := f.NestedNodes()
ids := make([]uint64, nnodes.Len())
for i := 0; i < nnodes.Len(); i++ {
nn := nnodes.At(i)
ids[i] = nn.Id()
if ni := ret.nodes[nn.Id()]; ni != nil {
nname, _ := nn.Name()
if err := resolveName(ret.nodes, ni, "", nname, f); err != nil {
Expand All @@ -294,7 +292,9 @@ func makeNodeTrees(req schema.CodeGeneratorRequest) (nodeTrees, error) {
}
// Note that this can collect ids from multiple files if they are in the
// same $Go.package.
pkg.nodeId = append(pkg.nodeId, ids...)
for _, n := range f.nodes {
pkg.nodeId = append(pkg.nodeId, n.Id())
}
ret.pkgs[f.pkg] = pkg
}
return ret, nil
Expand Down

0 comments on commit ee48d50

Please sign in to comment.