Skip to content

Commit

Permalink
Remove more uses of fmt.
Browse files Browse the repository at this point in the history
Only a few left.
  • Loading branch information
zenhack committed Feb 18, 2023
1 parent f72f371 commit 0c2fc6f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
30 changes: 25 additions & 5 deletions rawpointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package capnp

import (
"fmt"

"capnproto.org/go/capnp/v3/internal/str"
)

// pointerOffset is an address offset in multiples of word size.
Expand Down Expand Up @@ -201,7 +203,11 @@ func (p rawPointer) GoString() string {
}
switch p.pointerType() {
case structPointer:
return fmt.Sprintf("rawStructPointer(%d, %#v)", p.offset(), p.structSize())
return "rawStructPointer(" +
str.Itod(p.offset()) +
" , " +
p.structSize().String() +
")"
case listPointer:
var lt string
switch p.listType() {
Expand All @@ -222,16 +228,30 @@ func (p rawPointer) GoString() string {
case compositeList:
lt = "compositeList"
}
return fmt.Sprintf("rawListPointer(%d, %s, %d)", p.offset(), lt, p.numListElements())
return "rawListPointer(" +
str.Itod(p.offset()) +
", " +
lt +
", " +
str.Itod(p.numListElements()) +
")"
case farPointer:
return fmt.Sprintf("rawFarPointer(%d, %v)", p.farSegment(), p.farAddress())
return "rawFarPointer(" +
str.Utod(p.farSegment()) +
", " +
p.farAddress().String() +
")"
case doubleFarPointer:
return fmt.Sprintf("rawDoubleFarPointer(%d, %v)", p.farSegment(), p.farAddress())
return "rawDoubleFarPointer(" +
str.Utod(p.farSegment()) +
", " +
p.farAddress().String() +
")"
default:
// other pointer
if p.otherPointerType() != 0 {
return fmt.Sprintf("rawPointer(%#016x)", uint64(p))
}
return fmt.Sprintf("rawInterfacePointer(%d)", p.capabilityIndex())
return "rawInterfacePointer(" + str.Utod(p.capabilityIndex()) + ")"
}
}
4 changes: 1 addition & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package server // import "capnproto.org/go/capnp/v3/server"

import (
"context"
"fmt"
"sort"
"sync"

Expand Down Expand Up @@ -275,8 +274,7 @@ func sendArgsToStruct(s capnp.Send) (capnp.Struct, error) {
}
if err := s.PlaceArgs(st); err != nil {
st.Message().Reset(nil)
// Using fmt.Errorf to ensure sendArgsToStruct returns a generic error.
return capnp.Struct{}, fmt.Errorf("place args: %w", err)
return capnp.Struct{}, exc.WrapError("place args", err)
}
return st, nil
}
Expand Down

0 comments on commit 0c2fc6f

Please sign in to comment.