Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,916 changes: 1,188 additions & 728 deletions crates/wit-bindgen-go/src/interface.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/wit-bindgen-rust/tests/codegen_no_std.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Like `codegen_tests` in codegen.rs, but with no_std.
//! Like `codegen_tests` in codegen.rs, but with `no_std`.
//!
//! We use `std_feature` and don't enable the "std" feature.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ func Hello(ctx__ context.Context, wrpc__ wrpc.Client) (r0__ string, close__ func
if err__ != nil {
return fmt.Errorf("failed to write empty parameters: %w", err__)
}
r0__, err__ = func(r wrpc.ByteReader) (string, error) {
r0__, err__ = func(r interface {
io.ByteReader
io.Reader
}) (string, error) {
var x uint32
var s uint
for i := 0; i < 5; i++ {
Expand Down
5 changes: 4 additions & 1 deletion examples/go/hello-client/cmd/hello-client-nats/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ func run() (err error) {

for _, prefix := range os.Args[1:] {
wrpc := wrpcnats.NewClient(nc, prefix)
greeting, err := handler.Hello(context.Background(), wrpc)
greeting, cleanup, err := handler.Hello(context.Background(), wrpc)
if err != nil {
return fmt.Errorf("failed to call `wrpc-examples:hello/handler.hello`: %w", err)
}
fmt.Printf("%s: %s\n", prefix, greeting)
if err := cleanup(); err != nil {
return fmt.Errorf("failed to shutdown `wrpc-examples:hello/handler.hello` invocation: %w", err)
}
}
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
fmt "fmt"
wrpc "github.com/wrpc/wrpc/go"
errgroup "golang.org/x/sync/errgroup"
io "io"
slog "log/slog"
math "math"
)
Expand Down Expand Up @@ -35,26 +36,26 @@ func ServeInterface(c wrpc.Client, h Handler) (stop func() error, err error) {

var buf bytes.Buffer
writes := make(map[uint32]func(wrpc.IndexWriter) error, 1)
write0, err := func(v string, w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) {
write0, err := (func(wrpc.IndexWriter) error)(nil), func(v string, w io.Writer) (err error) {
n := len(v)
if n > math.MaxUint32 {
return nil, fmt.Errorf("string byte length of %d overflows a 32-bit integer", n)
return fmt.Errorf("string byte length of %d overflows a 32-bit integer", n)
}
if err := func(v int, w wrpc.ByteWriter) error {
if err = func(v int, w io.Writer) error {
b := make([]byte, binary.MaxVarintLen32)
i := binary.PutUvarint(b, uint64(v))
slog.Debug("writing string byte length", "len", n)
_, err := w.Write(b[:i])
_, err = w.Write(b[:i])
return err
}(n, w); err != nil {
return nil, fmt.Errorf("failed to write string length of %d: %w", n, err)
return fmt.Errorf("failed to write string byte length of %d: %w", n, err)
}
slog.Debug("writing string bytes")
_, err := w.Write([]byte(v))
_, err = w.Write([]byte(v))
if err != nil {
return nil, fmt.Errorf("failed to write string bytes: %w", err)
return fmt.Errorf("failed to write string bytes: %w", err)
}
return nil, nil
return nil
}(r0, &buf)
if err != nil {
return fmt.Errorf("failed to write result value 0: %w", err)
Expand Down
1 change: 1 addition & 0 deletions examples/go/hello-server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22.2
require (
github.com/nats-io/nats.go v1.34.1
github.com/wrpc/wrpc/go v0.0.0-unpublished
golang.org/x/sync v0.7.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions examples/go/hello-server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
4 changes: 2 additions & 2 deletions examples/go/http-outgoing-nats-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ type trailerReceiver <-chan []*wrpc.Tuple2[string, [][]byte]
func (r trailerReceiver) Receive() ([]*wrpc.Tuple2[string, [][]byte], error) {
trailers, ok := <-r
if !ok {
return nil, errors.New("trailer receiver channel closed")
return nil, io.EOF
}
return trailers, nil
}

func (r trailerReceiver) Ready() bool {
func (r trailerReceiver) IsComplete() bool {
return false
}

Expand Down
Loading