diff --git a/capnpc-go/fileparts.go b/capnpc-go/fileparts.go index f1629bc6..b27bb9f2 100644 --- a/capnpc-go/fileparts.go +++ b/capnpc-go/fileparts.go @@ -21,7 +21,6 @@ var ( {path: flowcontrolImport, name: "fc"}, // stdlib imports - {path: "fmt", name: "fmt"}, {path: "context", name: "context"}, {path: "math", name: "math"}, {path: "strconv", name: "strconv"}, @@ -106,10 +105,6 @@ func (i *imports) FlowControl() string { return i.add(importSpec{path: flowcontrolImport, name: "fc"}) } -func (i *imports) Fmt() string { - return i.add(importSpec{path: "fmt", name: "fmt"}) -} - func (i *imports) Context() string { return i.add(importSpec{path: "context", name: "context"}) } diff --git a/capnpc-go/templates/interfaceClient b/capnpc-go/templates/interfaceClient index f76e1611..f43c31e3 100644 --- a/capnpc-go/templates/interfaceClient +++ b/capnpc-go/templates/interfaceClient @@ -39,7 +39,7 @@ func (c {{$.Node.Name}}) WaitStreaming() error { // should not be used to compare clients. Use IsSame to compare clients // for equality. func (c {{$.Node.Name}}) String() string { - return {{$.G.Imports.Fmt}}.Sprintf("%T(%v)", c, capnp.Client(c)) + return "{{$.Node.Name}}(" + capnp.Client(c).String() + ")" } // AddRef creates a new Client that refers to the same capability as c. diff --git a/encoding/text/marshal.go b/encoding/text/marshal.go index 8c955f76..c10881e9 100644 --- a/encoding/text/marshal.go +++ b/encoding/text/marshal.go @@ -3,7 +3,7 @@ package text import ( "bytes" - "fmt" + "errors" "io" "math" "strconv" @@ -11,6 +11,7 @@ import ( "capnproto.org/go/capnp/v3" "capnproto.org/go/capnp/v3/internal/nodemap" "capnproto.org/go/capnp/v3/internal/schema" + "capnproto.org/go/capnp/v3/internal/str" "capnproto.org/go/capnp/v3/internal/strquote" "capnproto.org/go/capnp/v3/schemas" ) @@ -119,7 +120,7 @@ func (enc *Encoder) marshalStruct(typeID uint64, s capnp.Struct) error { return err } if !n.IsValid() || n.Which() != schema.Node_Which_structNode { - return fmt.Errorf("cannot find struct type %#x", typeID) + return errors.New("cannot find struct type " + str.UToHex(typeID)) } var discriminant uint16 if n.StructNode().DiscriminantCount() > 0 { @@ -171,7 +172,11 @@ func (enc *Encoder) marshalFieldValue(s capnp.Struct, f schema.Field) error { } if dv.IsValid() && int(typ.Which()) != int(dv.Which()) { name, _ := f.Name() - return fmt.Errorf("marshal field %s: default value is a %v, want %v", name, dv.Which(), typ.Which()) + return errors.New( + "marshal field " + name + + ": default value is a " + dv.Which().String() + + ", want " + typ.Which().String(), + ) } switch typ.Which() { case schema.Type_Which_void: @@ -277,7 +282,7 @@ func (enc *Encoder) marshalFieldValue(s capnp.Struct, f schema.Field) error { case schema.Type_Which_anyPointer: enc.w.WriteString(anyPointerMarker) default: - return fmt.Errorf("unknown field type %v", typ.Which()) + return errors.New("unknown field type " + typ.Which().String()) } return nil } @@ -394,7 +399,7 @@ func (enc *Encoder) marshalList(elem schema.Type, l capnp.List) error { } enc.w.WriteByte(']') default: - return fmt.Errorf("unknown list type %v", elem.Which()) + return errors.New("unknown list type " + elem.Which().String()) } return nil } @@ -405,7 +410,9 @@ func (enc *Encoder) marshalEnum(typ uint64, val uint16) error { return err } if n.Which() != schema.Node_Which_enum { - return fmt.Errorf("marshaling enum of type @%#x: type is not an enum", typ) + return errors.New( + "marshaling enum of type @" + str.UToHex(typ) + ": type is not an enum", + ) } enums, err := n.Enum().Enumerants() if err != nil { diff --git a/flowcontrol/internal/test-tool/writer.capnp.go b/flowcontrol/internal/test-tool/writer.capnp.go index 7094056a..876595bc 100644 --- a/flowcontrol/internal/test-tool/writer.capnp.go +++ b/flowcontrol/internal/test-tool/writer.capnp.go @@ -9,7 +9,6 @@ import ( schemas "capnproto.org/go/capnp/v3/schemas" server "capnproto.org/go/capnp/v3/server" context "context" - fmt "fmt" ) type Writer capnp.Client @@ -46,7 +45,7 @@ func (c Writer) WaitStreaming() error { // should not be used to compare clients. Use IsSame to compare clients // for equality. func (c Writer) String() string { - return fmt.Sprintf("%T(%v)", c, capnp.Client(c)) + return "Writer(" + capnp.Client(c).String() + ")" } // AddRef creates a new Client that refers to the same capability as c. diff --git a/internal/aircraftlib/aircraft.capnp.go b/internal/aircraftlib/aircraft.capnp.go index 35e87cb2..6eb42ac1 100644 --- a/internal/aircraftlib/aircraft.capnp.go +++ b/internal/aircraftlib/aircraft.capnp.go @@ -9,7 +9,6 @@ import ( schemas "capnproto.org/go/capnp/v3/schemas" server "capnproto.org/go/capnp/v3/server" context "context" - fmt "fmt" math "math" strconv "strconv" ) @@ -5082,7 +5081,7 @@ func (c Echo) WaitStreaming() error { // should not be used to compare clients. Use IsSame to compare clients // for equality. func (c Echo) String() string { - return fmt.Sprintf("%T(%v)", c, capnp.Client(c)) + return "Echo(" + capnp.Client(c).String() + ")" } // AddRef creates a new Client that refers to the same capability as c. @@ -5876,7 +5875,7 @@ func (c CallSequence) WaitStreaming() error { // should not be used to compare clients. Use IsSame to compare clients // for equality. func (c CallSequence) String() string { - return fmt.Sprintf("%T(%v)", c, capnp.Client(c)) + return "CallSequence(" + capnp.Client(c).String() + ")" } // AddRef creates a new Client that refers to the same capability as c. @@ -6194,7 +6193,7 @@ func (c Pipeliner) WaitStreaming() error { // should not be used to compare clients. Use IsSame to compare clients // for equality. func (c Pipeliner) String() string { - return fmt.Sprintf("%T(%v)", c, capnp.Client(c)) + return "Pipeliner(" + capnp.Client(c).String() + ")" } // AddRef creates a new Client that refers to the same capability as c. diff --git a/list.go b/list.go index fe69e3f7..326da572 100644 --- a/list.go +++ b/list.go @@ -1,9 +1,7 @@ package capnp import ( - "bytes" "errors" - "fmt" "math" "strconv" @@ -1080,20 +1078,6 @@ func (s StructList[T]) Set(i int, v T) error { return List(s).SetStruct(i, Struct(v)) } -// String returns the list in Cap'n Proto schema format (e.g. "[(x = 1), (x = 2)]"). -func (s StructList[T]) String() string { - buf := &bytes.Buffer{} - buf.WriteByte('[') - for i := 0; i < s.Len(); i++ { - if i > 0 { - buf.WriteString(", ") - } - fmt.Fprint(buf, s.At(i)) - } - buf.WriteByte(']') - return buf.String() -} - // A list of some Cap'n Proto capability type T. type CapList[T ~ClientKind] PointerList diff --git a/rpc/internal/testcapnp/test.capnp.go b/rpc/internal/testcapnp/test.capnp.go index e68dcdce..0840d923 100644 --- a/rpc/internal/testcapnp/test.capnp.go +++ b/rpc/internal/testcapnp/test.capnp.go @@ -10,7 +10,6 @@ import ( server "capnproto.org/go/capnp/v3/server" stream "capnproto.org/go/capnp/v3/std/capnp/stream" context "context" - fmt "fmt" ) type PingPong capnp.Client @@ -47,7 +46,7 @@ func (c PingPong) WaitStreaming() error { // should not be used to compare clients. Use IsSame to compare clients // for equality. func (c PingPong) String() string { - return fmt.Sprintf("%T(%v)", c, capnp.Client(c)) + return "PingPong(" + capnp.Client(c).String() + ")" } // AddRef creates a new Client that refers to the same capability as c. @@ -350,7 +349,7 @@ func (c StreamTest) WaitStreaming() error { // should not be used to compare clients. Use IsSame to compare clients // for equality. func (c StreamTest) String() string { - return fmt.Sprintf("%T(%v)", c, capnp.Client(c)) + return "StreamTest(" + capnp.Client(c).String() + ")" } // AddRef creates a new Client that refers to the same capability as c. @@ -608,7 +607,7 @@ func (c CapArgsTest) WaitStreaming() error { // should not be used to compare clients. Use IsSame to compare clients // for equality. func (c CapArgsTest) String() string { - return fmt.Sprintf("%T(%v)", c, capnp.Client(c)) + return "CapArgsTest(" + capnp.Client(c).String() + ")" } // AddRef creates a new Client that refers to the same capability as c. @@ -1100,7 +1099,7 @@ func (c PingPongProvider) WaitStreaming() error { // should not be used to compare clients. Use IsSame to compare clients // for equality. func (c PingPongProvider) String() string { - return fmt.Sprintf("%T(%v)", c, capnp.Client(c)) + return "PingPongProvider(" + capnp.Client(c).String() + ")" } // AddRef creates a new Client that refers to the same capability as c. diff --git a/schemas/schemas.go b/schemas/schemas.go index b5b8cdd4..f0477bb2 100644 --- a/schemas/schemas.go +++ b/schemas/schemas.go @@ -12,12 +12,12 @@ import ( "bytes" "compress/zlib" "errors" - "fmt" "io" "io/ioutil" "strings" "sync" + "capnproto.org/go/capnp/v3/internal/str" "capnproto.org/go/capnp/v3/packed" ) @@ -164,7 +164,7 @@ type dupeError struct { } func (e *dupeError) Error() string { - return fmt.Sprintf("schemas: registered @%#x twice", e.id) + return "schemas: registered @" + str.UToHex(e.id) + " twice" } type notFoundError struct { @@ -172,7 +172,7 @@ type notFoundError struct { } func (e *notFoundError) Error() string { - return fmt.Sprintf("schemas: could not find @%#x", e.id) + return "schemas: could not find @" + str.UToHex(e.id) } type decompressError struct { @@ -181,5 +181,5 @@ type decompressError struct { } func (e *decompressError) Error() string { - return fmt.Sprintf("schemas: decompressing schema for @%#x: %v", e.id, e.err) + return "schemas: decompressing schema for @" + str.UToHex(e.id) + ": " + e.err.Error() } diff --git a/std/capnp/persistent/persistent.capnp.go b/std/capnp/persistent/persistent.capnp.go index 9a7ab855..e4282066 100644 --- a/std/capnp/persistent/persistent.capnp.go +++ b/std/capnp/persistent/persistent.capnp.go @@ -9,7 +9,6 @@ import ( schemas "capnproto.org/go/capnp/v3/schemas" server "capnproto.org/go/capnp/v3/server" context "context" - fmt "fmt" ) const PersistentAnnotation = uint64(0xf622595091cafb67) @@ -48,7 +47,7 @@ func (c Persistent) WaitStreaming() error { // should not be used to compare clients. Use IsSame to compare clients // for equality. func (c Persistent) String() string { - return fmt.Sprintf("%T(%v)", c, capnp.Client(c)) + return "Persistent(" + capnp.Client(c).String() + ")" } // AddRef creates a new Client that refers to the same capability as c.