Skip to content

Commit

Permalink
Merge pull request #276 from zenhack/embed-client
Browse files Browse the repository at this point in the history
Embed capnp.Client in generated interface types.
  • Loading branch information
zenhack authored Jul 30, 2022
2 parents 32723ce + c74c17b commit a609dc7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 42 deletions.
6 changes: 1 addition & 5 deletions capnpc-go/templates/interfaceClient
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{with .Annotations.Doc -}}
// {{.}}
{{end -}}
type {{.Node.Name}} struct { Client {{.G.Capnp}}.Client }
type {{.Node.Name}} struct { {{.G.Capnp}}.Client }

{{ template "_typeid" .Node }}

Expand All @@ -26,7 +26,3 @@ func (c {{$.Node.Name}}) AddRef() {{$.Node.Name}} {
Client: c.Client.AddRef(),
}
}

func (c {{$.Node.Name}}) Release() {
c.Client.Release()
}
18 changes: 3 additions & 15 deletions internal/aircraftlib/aircraft.capnp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ func (s StructList[T]) String() string {
return buf.String()
}

type CapList[T ~struct{ Client Client }] PointerList
type CapList[T ~struct{ Client }] PointerList

func (c CapList[T]) At(i int) (T, error) {
ptr, err := PointerList(c).At(i)
Expand All @@ -1050,7 +1050,7 @@ func (c CapList[T]) At(i int) (T, error) {
func (c CapList[T]) Set(i int, v T) error {
pl := PointerList(c)
seg := pl.List.Segment()
capId := seg.Message().AddCap(struct{ Client Client }(v).Client)
capId := seg.Message().AddCap(struct{ Client }(v).Client)
return pl.Set(i, NewInterface(seg, capId).ToPtr())
}

Expand Down
18 changes: 3 additions & 15 deletions rpc/internal/testcapnp/test.capnp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions std/capnp/persistent/persistent.capnp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a609dc7

Please sign in to comment.