File tree Expand file tree Collapse file tree 7 files changed +64
-5
lines changed Expand file tree Collapse file tree 7 files changed +64
-5
lines changed Original file line number Diff line number Diff line change @@ -540,6 +540,13 @@ func (pc PipelineClient) Brand() Brand {
540
540
func (pc PipelineClient ) Shutdown () {
541
541
}
542
542
543
+ func (pc PipelineClient ) String () string {
544
+ return "PipelineClient{transform: " +
545
+ str .Slice (pc .transform ) +
546
+ ", promise: 0x" + str .PtrToHex (pc .p ) +
547
+ "}"
548
+ }
549
+
543
550
// A PipelineOp describes a step in transforming a pipeline.
544
551
// It maps closely with the PromisedAnswer.Op struct in rpc.capnp.
545
552
type PipelineOp struct {
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package capnp
3
3
import (
4
4
"context"
5
5
"errors"
6
- "fmt"
7
6
"runtime"
8
7
"strconv"
9
8
"sync"
@@ -606,9 +605,9 @@ func (c Client) String() string {
606
605
}
607
606
var s string
608
607
if c .h .isResolved () {
609
- s = fmt . Sprintf ( "<client %T@%p>" , c .h .ClientHook , c . h )
608
+ s = "<client " + c .h .ClientHook . String () + ">"
610
609
} else {
611
- s = fmt . Sprintf ( "<unresolved client %T@%p>" , c .h .ClientHook , c . h )
610
+ s = "<unresolved client " + c .h .ClientHook . String () + ">"
612
611
}
613
612
c .h .mu .Unlock ()
614
613
c .mu .Unlock ()
@@ -876,6 +875,9 @@ type ClientHook interface {
876
875
// Shutdown is undefined. It is expected for the ClientHook to reject
877
876
// any outstanding call futures.
878
877
Shutdown ()
878
+
879
+ // String formats the hook as a string (same as fmt.Stringer)
880
+ String () string
879
881
}
880
882
881
883
// Send is the input to ClientHook.Send.
@@ -1049,4 +1051,8 @@ func (ec errorClient) Brand() Brand {
1049
1051
func (ec errorClient ) Shutdown () {
1050
1052
}
1051
1053
1054
+ func (ec errorClient ) String () string {
1055
+ return "errorClient{" + ec .e .Error () + "}"
1056
+ }
1057
+
1052
1058
var closedSignal = make (chan struct {})
Original file line number Diff line number Diff line change 2
2
// of environments that care about minimizing executable size.
3
3
package str
4
4
5
- import "strconv"
5
+ import (
6
+ "strconv"
7
+ "strings"
8
+
9
+ "unsafe" // Only for formatting pointers as integers; we don't actually do anything unsafe.
10
+ )
6
11
7
12
// Utod formats unsigned integers as decimals.
8
13
func Utod [T Uint ](n T ) string {
@@ -19,6 +24,10 @@ func UToHex[T Uint](n T) string {
19
24
return strconv .FormatUint (uint64 (n ), 16 )
20
25
}
21
26
27
+ func PtrToHex [T any ](p * T ) string {
28
+ return UToHex (uintptr (unsafe .Pointer (p )))
29
+ }
30
+
22
31
// ZeroPad pads value to the left with zeros, making the resulting string
23
32
// count bytes long.
24
33
func ZeroPad (count int , value string ) string {
@@ -34,8 +43,27 @@ func ZeroPad(count int, value string) string {
34
43
return string (buf )
35
44
}
36
45
46
+ // Slice formats a slice of values which themselves implement Stringer.
47
+ func Slice [T Stringer ](s []T ) string {
48
+ var b strings.Builder
49
+ b .WriteRune ('{' )
50
+ for i , v := range s {
51
+ if i > 0 {
52
+ b .WriteString (", " )
53
+ }
54
+ b .WriteString (v .String ())
55
+ }
56
+ b .WriteRune ('}' )
57
+ return b .String ()
58
+ }
59
+
60
+ // Stringer is equivalent to fmt.Stringer
61
+ type Stringer interface {
62
+ String () string
63
+ }
64
+
37
65
type Uint interface {
38
- ~ uint8 | ~ uint16 | ~ uint32 | ~ uint64 | ~ uint
66
+ ~ uint8 | ~ uint16 | ~ uint32 | ~ uint64 | ~ uint | ~ uintptr
39
67
}
40
68
41
69
type Int interface {
Original file line number Diff line number Diff line change @@ -208,6 +208,10 @@ type embargo struct {
208
208
lifted chan struct {}
209
209
}
210
210
211
+ func (e embargo ) String () string {
212
+ return "embargo{c: " + e .c .String () + ", 0x" + str .PtrToHex (e .p ) + "}"
213
+ }
214
+
211
215
// embargo creates a new embargoed client, stealing the reference.
212
216
//
213
217
// The caller must be holding onto c.mu.
Original file line number Diff line number Diff line change 5
5
"errors"
6
6
7
7
"capnproto.org/go/capnp/v3"
8
+ "capnproto.org/go/capnp/v3/internal/str"
8
9
"capnproto.org/go/capnp/v3/internal/syncutil"
9
10
rpccp "capnproto.org/go/capnp/v3/std/capnp/rpc"
10
11
)
@@ -84,6 +85,10 @@ type importClient struct {
84
85
generation uint64
85
86
}
86
87
88
+ func (ic * importClient ) String () string {
89
+ return "importClient{c: 0x" + str .PtrToHex (ic .c ) + ", id: " + str .Utod (ic .id ) + "}"
90
+ }
91
+
87
92
func (ic * importClient ) Send (ctx context.Context , s capnp.Send ) (* capnp.Answer , capnp.ReleaseFunc ) {
88
93
return withLockedConn2 (ic .c , func (c * lockedConn ) (* capnp.Answer , capnp.ReleaseFunc ) {
89
94
if ! c .startTask () {
Original file line number Diff line number Diff line change @@ -332,6 +332,10 @@ type bootstrapClient struct {
332
332
cancel context.CancelFunc
333
333
}
334
334
335
+ func (bc bootstrapClient ) String () string {
336
+ return "bootstrapClient{c: " + bc .c .String () + "}"
337
+ }
338
+
335
339
func (bc bootstrapClient ) Send (ctx context.Context , s capnp.Send ) (* capnp.Answer , capnp.ReleaseFunc ) {
336
340
return bc .c .SendCall (ctx , s )
337
341
}
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
10
10
"capnproto.org/go/capnp/v3"
11
11
"capnproto.org/go/capnp/v3/exc"
12
12
"capnproto.org/go/capnp/v3/exp/mpsc"
13
+ "capnproto.org/go/capnp/v3/internal/str"
13
14
)
14
15
15
16
// A Method describes a single capability method on a server object.
@@ -104,6 +105,10 @@ type Server struct {
104
105
HandleUnknownMethod func (m capnp.Method ) * Method
105
106
}
106
107
108
+ func (s * Server ) String () string {
109
+ return "*Server@0x" + str .PtrToHex (s )
110
+ }
111
+
107
112
// New returns a client hook that makes calls to a set of methods.
108
113
// If shutdown is nil then the server's shutdown is a no-op. The server
109
114
// guarantees message delivery order by blocking each call on the
You can’t perform that action at this time.
0 commit comments