From a0ca8e87d0ba5525efaadd23705e6f6c733bf61c Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Wed, 2 Oct 2024 21:04:16 +0200 Subject: [PATCH] chore: update wRPC Signed-off-by: Roman Volosatovs --- examples/http-server/bindings/server.wrpc.go | 2 +- .../clocks/monotonic_clock/bindings.wrpc.go | 125 ++- .../bindings/wasi/http/types/bindings.wrpc.go | 787 ++++++++---------- .../bindings/wasi/io/error/bindings.wrpc.go | 2 +- .../bindings/wasi/io/poll/bindings.wrpc.go | 6 +- .../bindings/wasi/io/streams/bindings.wrpc.go | 286 +++---- .../http/incoming_handler/bindings.wrpc.go | 115 +-- .../bindings/wrpc/http/types/bindings.wrpc.go | 136 ++- examples/http-server/go.mod | 2 +- examples/http-server/go.sum | 4 +- .../wrpc/keyvalue/store/bindings.wrpc.go | 157 ++-- .../keyvalue-inmemory/bindings/server.wrpc.go | 2 +- .../bindings/testing/testing.wrpc.go | 2 +- .../wrpc/keyvalue/store/bindings.wrpc.go | 38 +- examples/keyvalue-inmemory/go.mod | 2 +- examples/keyvalue-inmemory/go.sum | 16 +- go.mod | 2 +- go.sum | 4 +- internal/internal.wrpc.go | 2 +- .../clocks/monotonic_clock/bindings.wrpc.go | 125 ++- internal/wasi/http/types/bindings.wrpc.go | 787 ++++++++---------- internal/wasi/io/error/bindings.wrpc.go | 2 +- internal/wasi/io/poll/bindings.wrpc.go | 6 +- internal/wasi/io/streams/bindings.wrpc.go | 286 +++---- .../http/incoming_handler/bindings.wrpc.go | 512 ++++++------ internal/wrpc/http/types/bindings.wrpc.go | 136 ++- wrpchttp/incoming_test.go | 6 +- 27 files changed, 1652 insertions(+), 1898 deletions(-) diff --git a/examples/http-server/bindings/server.wrpc.go b/examples/http-server/bindings/server.wrpc.go index 5bb27a5..3ab772d 100644 --- a/examples/http-server/bindings/server.wrpc.go +++ b/examples/http-server/bindings/server.wrpc.go @@ -1,3 +1,3 @@ -// Generated by `wit-bindgen-wrpc-go` 0.8.0. DO NOT EDIT! +// Generated by `wit-bindgen-wrpc-go` 0.9.1. DO NOT EDIT! // server package contains wRPC bindings for `server` world package server diff --git a/examples/http-server/bindings/wasi/clocks/monotonic_clock/bindings.wrpc.go b/examples/http-server/bindings/wasi/clocks/monotonic_clock/bindings.wrpc.go index 052f4c3..ad55ef9 100644 --- a/examples/http-server/bindings/wasi/clocks/monotonic_clock/bindings.wrpc.go +++ b/examples/http-server/bindings/wasi/clocks/monotonic_clock/bindings.wrpc.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen-wrpc-go` 0.8.0. DO NOT EDIT! +// Generated by `wit-bindgen-wrpc-go` 0.9.1. DO NOT EDIT! package monotonic_clock import ( @@ -10,7 +10,6 @@ import ( wasi__io__poll "github.com/wasmCloud/provider-sdk-go/examples/http-server/bindings/wasi/io/poll" io "io" slog "log/slog" - utf8 "unicode/utf8" wrpc "wrpc.io/go" ) @@ -44,33 +43,29 @@ func Now(ctx__ context.Context, wrpc__ wrpc.Invoker) (r0__ uint64, err__ error) if cErr__ := w__.Close(); cErr__ != nil { slog.DebugContext(ctx__, "failed to close outgoing stream", "instance", "wasi:clocks/monotonic-clock@0.2.0", "name", "now", "err", cErr__) } - r0__, err__ = func() (Instant, error) { - v, err := func(r io.ByteReader) (uint64, error) { - var x uint64 - var s uint8 - for i := 0; i < 10; i++ { - slog.Debug("reading u64 byte", "i", i) - b, err := r.ReadByte() - if err != nil { - if i > 0 && err == io.EOF { - err = io.ErrUnexpectedEOF - } - return x, fmt.Errorf("failed to read u64 byte: %w", err) - } - if s == 63 && b > 0x01 { - return x, errors.New("varint overflows a 64-bit integer") - } - if b < 0x80 { - return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF } - x |= uint64(b&0x7f) << s - s += 7 + return x, fmt.Errorf("failed to read u64 byte: %w", err) } - return x, errors.New("varint overflows a 64-bit integer") - }(r__) - return (Instant)(v), err - }() - + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { - err = io.ErrUnexpectedEOF - } - return x, fmt.Errorf("failed to read u64 byte: %w", err) - } - if s == 63 && b > 0x01 { - return x, errors.New("varint overflows a 64-bit integer") - } - if b < 0x80 { - return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF } - x |= uint64(b&0x7f) << s - s += 7 + return x, fmt.Errorf("failed to read u64 byte: %w", err) } - return x, errors.New("varint overflows a 64-bit integer") - }(r__) - return (Duration)(v), err - }() - + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { - err = io.ErrUnexpectedEOF - } - return x, fmt.Errorf("failed to read u16 byte: %w", err) - } - if s == 14 && b > 0x03 { - return x, errors.New("varint overflows a 16-bit integer") - } - if b < 0x80 { - return x | uint16(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF } - x |= uint16(b&0x7f) << s - s += 7 + return x, fmt.Errorf("failed to read u16 byte: %w", err) } - return x, errors.New("varint overflows a 16-bit integer") - }(r__) - return (StatusCode)(v), err - }() - + if s == 14 && b > 0x03 { + return x, errors.New("varint overflows a 16-bit integer") + } + if b < 0x80 { + return x | uint16(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { - err = io.ErrUnexpectedEOF - } - return x, fmt.Errorf("failed to read u16 byte: %w", err) - } - if s == 14 && b > 0x03 { - return x, errors.New("varint overflows a 16-bit integer") - } - if b < 0x80 { - return x | uint16(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF } - x |= uint16(b&0x7f) << s - s += 7 + return x, fmt.Errorf("failed to read u16 byte: %w", err) } - return x, errors.New("varint overflows a 16-bit integer") - }(r__) - return (StatusCode)(v), err - }() - + if s == 14 && b > 0x03 { + return x, errors.New("varint overflows a 16-bit integer") + } + if b < 0x80 { + return x | uint16(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 { + var err error + r, err = r.Index(path...) + if err != nil { + return nil, fmt.Errorf("failed to index nested byte stream reader: %w", err) + } } return wrpc.NewByteStreamReader(r), nil case 1: @@ -145,7 +148,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, fmt.Errorf("failed to read ready byte stream contents: %w", err) } slog.Debug("read ready byte stream contents", "len", len(buf)) - return bytes.NewReader(buf), nil + return io.NopCloser(bytes.NewReader(buf)), nil default: return nil, fmt.Errorf("invalid stream status byte %d", status) } @@ -154,7 +157,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, fmt.Errorf("failed to read `body` field: %w", err) } slog.Debug("reading field", "name", "trailers") - v.Trailers, err = func(r wrpc.IndexReader, path ...uint32) (wrpc.Receiver[[]*wrpc.Tuple2[string, [][]uint8]], error) { + v.Trailers, err = func(r wrpc.IndexReadCloser, path ...uint32) (wrpc.Receiver[[]*wrpc.Tuple2[string, [][]uint8]], error) { slog.Debug("reading future status byte") status, err := r.ReadByte() if err != nil { @@ -162,13 +165,17 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ } switch status { case 0: - r, err := r.Index(path...) - if err != nil { - return nil, fmt.Errorf("failed to index reader: %w", err) + slog.Debug("indexing pending future reader") + if len(path) > 0 { + var err error + r, err = r.Index(path...) + if err != nil { + return nil, fmt.Errorf("failed to index nested future reader: %w", err) + } } - return wrpc.NewDecodeReceiver(r, func(r wrpc.IndexReader) ([]*wrpc.Tuple2[string, [][]uint8], error) { + return wrpc.NewDecodeReceiver(r, func(r wrpc.IndexReadCloser) ([]*wrpc.Tuple2[string, [][]uint8], error) { slog.Debug("reading pending future element") - v, err := func(r wrpc.IndexReader, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { + v, err := func(r wrpc.IndexReadCloser, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -179,7 +186,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, nil case 1: slog.Debug("reading `option::some` payload") - v, err := func(r wrpc.IndexReader, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { + v, err := func(r wrpc.IndexReadCloser, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { var x uint32 var s uint for i := 0; i < 5; i++ { @@ -199,7 +206,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ vs := make([]*wrpc.Tuple2[string, [][]uint8], x) for i := range vs { slog.Debug("reading list element", "i", i) - vs[i], err = func(r wrpc.IndexReader, path ...uint32) (*wrpc.Tuple2[string, [][]uint8], error) { + vs[i], err = func(r wrpc.IndexReadCloser, path ...uint32) (*wrpc.Tuple2[string, [][]uint8], error) { v := &wrpc.Tuple2[string, [][]uint8]{} var err error slog.Debug("reading tuple element 0") @@ -243,7 +250,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, fmt.Errorf("failed to read tuple element 0: %w", err) } slog.Debug("reading tuple element 1") - v.V1, err = func(r wrpc.IndexReader, path ...uint32) ([][]uint8, error) { + v.V1, err = func(r wrpc.IndexReadCloser, path ...uint32) ([][]uint8, error) { var x uint32 var s uint for i := 0; i < 5; i++ { @@ -339,7 +346,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ case 1: slog.Debug("reading ready future contents") v, err := - func(r wrpc.IndexReader, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { + func(r wrpc.IndexReadCloser, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -350,7 +357,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, nil case 1: slog.Debug("reading `option::some` payload") - v, err := func(r wrpc.IndexReader, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { + v, err := func(r wrpc.IndexReadCloser, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { var x uint32 var s uint for i := 0; i < 5; i++ { @@ -370,7 +377,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ vs := make([]*wrpc.Tuple2[string, [][]uint8], x) for i := range vs { slog.Debug("reading list element", "i", i) - vs[i], err = func(r wrpc.IndexReader, path ...uint32) (*wrpc.Tuple2[string, [][]uint8], error) { + vs[i], err = func(r wrpc.IndexReadCloser, path ...uint32) (*wrpc.Tuple2[string, [][]uint8], error) { v := &wrpc.Tuple2[string, [][]uint8]{} var err error slog.Debug("reading tuple element 0") @@ -414,7 +421,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, fmt.Errorf("failed to read tuple element 0: %w", err) } slog.Debug("reading tuple element 1") - v.V1, err = func(r wrpc.IndexReader, path ...uint32) ([][]uint8, error) { + v.V1, err = func(r wrpc.IndexReadCloser, path ...uint32) ([][]uint8, error) { var x uint32 var s uint for i := 0; i < 5; i++ { @@ -541,7 +548,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, fmt.Errorf("failed to read `status` field: %w", err) } slog.Debug("reading field", "name", "headers") - v.Headers, err = func(r wrpc.IndexReader, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { + v.Headers, err = func(r wrpc.IndexReadCloser, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { var x uint32 var s uint for i := 0; i < 5; i++ { @@ -561,7 +568,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ vs := make([]*wrpc.Tuple2[string, [][]uint8], x) for i := range vs { slog.Debug("reading list element", "i", i) - vs[i], err = func(r wrpc.IndexReader, path ...uint32) (*wrpc.Tuple2[string, [][]uint8], error) { + vs[i], err = func(r wrpc.IndexReadCloser, path ...uint32) (*wrpc.Tuple2[string, [][]uint8], error) { v := &wrpc.Tuple2[string, [][]uint8]{} var err error slog.Debug("reading tuple element 0") @@ -605,7 +612,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, fmt.Errorf("failed to read tuple element 0: %w", err) } slog.Debug("reading tuple element 1") - v.V1, err = func(r wrpc.IndexReader, path ...uint32) ([][]uint8, error) { + v.V1, err = func(r wrpc.IndexReadCloser, path ...uint32) ([][]uint8, error) { var x uint32 var s uint for i := 0; i < 5; i++ { @@ -702,7 +709,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ v, err := func() (*ErrorCode, error) { v, err := func() (*wrpc__http__types.ErrorCode, error) { v, err := func() (*wrpc__http__types.WasiErrorCode, error) { - v, err := func(r wrpc.IndexReader, path ...uint32) (*wasi__http__types.ErrorCode, error) { + v, err := func(r wrpc.IndexReadCloser, path ...uint32) (*wasi__http__types.ErrorCode, error) { v := &wasi__http__types.ErrorCode{} n, err := func(r io.ByteReader) (uint8, error) { var x uint8 @@ -734,11 +741,11 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ case wasi__http__types.ErrorCodeDnsTimeout: return v.SetDnsTimeout(), nil case wasi__http__types.ErrorCodeDnsError: - payload, err := func(r wrpc.IndexReader, path ...uint32) (*wasi__http__types.DnsErrorPayload, error) { + payload, err := func(r wrpc.IndexReadCloser, path ...uint32) (*wasi__http__types.DnsErrorPayload, error) { v := &wasi__http__types.DnsErrorPayload{} var err error slog.Debug("reading field", "name", "rcode") - v.Rcode, err = func(r wrpc.IndexReader, path ...uint32) (*string, error) { + v.Rcode, err = func(r wrpc.IndexReadCloser, path ...uint32) (*string, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -797,7 +804,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, fmt.Errorf("failed to read `rcode` field: %w", err) } slog.Debug("reading field", "name", "info-code") - v.InfoCode, err = func(r wrpc.IndexReader, path ...uint32) (*uint16, error) { + v.InfoCode, err = func(r wrpc.IndexReadCloser, path ...uint32) (*uint16, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -873,11 +880,11 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ case wasi__http__types.ErrorCodeTlsCertificateError: return v.SetTlsCertificateError(), nil case wasi__http__types.ErrorCodeTlsAlertReceived: - payload, err := func(r wrpc.IndexReader, path ...uint32) (*wasi__http__types.TlsAlertReceivedPayload, error) { + payload, err := func(r wrpc.IndexReadCloser, path ...uint32) (*wasi__http__types.TlsAlertReceivedPayload, error) { v := &wasi__http__types.TlsAlertReceivedPayload{} var err error slog.Debug("reading field", "name", "alert-id") - v.AlertId, err = func(r wrpc.IndexReader, path ...uint32) (*uint8, error) { + v.AlertId, err = func(r wrpc.IndexReadCloser, path ...uint32) (*uint8, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -908,7 +915,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, fmt.Errorf("failed to read `alert-id` field: %w", err) } slog.Debug("reading field", "name", "alert-message") - v.AlertMessage, err = func(r wrpc.IndexReader, path ...uint32) (*string, error) { + v.AlertMessage, err = func(r wrpc.IndexReadCloser, path ...uint32) (*string, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -977,7 +984,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ case wasi__http__types.ErrorCodeHttpRequestLengthRequired: return v.SetHttpRequestLengthRequired(), nil case wasi__http__types.ErrorCodeHttpRequestBodySize: - payload, err := func(r wrpc.IndexReader, path ...uint32) (*uint64, error) { + payload, err := func(r wrpc.IndexReadCloser, path ...uint32) (*uint64, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1030,7 +1037,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ case wasi__http__types.ErrorCodeHttpRequestUriTooLong: return v.SetHttpRequestUriTooLong(), nil case wasi__http__types.ErrorCodeHttpRequestHeaderSectionSize: - payload, err := func(r wrpc.IndexReader, path ...uint32) (*uint32, error) { + payload, err := func(r wrpc.IndexReadCloser, path ...uint32) (*uint32, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1077,7 +1084,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ } return v.SetHttpRequestHeaderSectionSize(payload), nil case wasi__http__types.ErrorCodeHttpRequestHeaderSize: - payload, err := func(r wrpc.IndexReader, path ...uint32) (*wasi__http__types.FieldSizePayload, error) { + payload, err := func(r wrpc.IndexReadCloser, path ...uint32) (*wasi__http__types.FieldSizePayload, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1088,11 +1095,11 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, nil case 1: slog.Debug("reading `option::some` payload") - v, err := func(r wrpc.IndexReader, path ...uint32) (*wasi__http__types.FieldSizePayload, error) { + v, err := func(r wrpc.IndexReadCloser, path ...uint32) (*wasi__http__types.FieldSizePayload, error) { v := &wasi__http__types.FieldSizePayload{} var err error slog.Debug("reading field", "name", "field-name") - v.FieldName, err = func(r wrpc.IndexReader, path ...uint32) (*string, error) { + v.FieldName, err = func(r wrpc.IndexReadCloser, path ...uint32) (*string, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1151,7 +1158,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, fmt.Errorf("failed to read `field-name` field: %w", err) } slog.Debug("reading field", "name", "field-size") - v.FieldSize, err = func(r wrpc.IndexReader, path ...uint32) (*uint32, error) { + v.FieldSize, err = func(r wrpc.IndexReadCloser, path ...uint32) (*uint32, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1211,7 +1218,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ } return v.SetHttpRequestHeaderSize(payload), nil case wasi__http__types.ErrorCodeHttpRequestTrailerSectionSize: - payload, err := func(r wrpc.IndexReader, path ...uint32) (*uint32, error) { + payload, err := func(r wrpc.IndexReadCloser, path ...uint32) (*uint32, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1258,11 +1265,11 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ } return v.SetHttpRequestTrailerSectionSize(payload), nil case wasi__http__types.ErrorCodeHttpRequestTrailerSize: - payload, err := func(r wrpc.IndexReader, path ...uint32) (*wasi__http__types.FieldSizePayload, error) { + payload, err := func(r wrpc.IndexReadCloser, path ...uint32) (*wasi__http__types.FieldSizePayload, error) { v := &wasi__http__types.FieldSizePayload{} var err error slog.Debug("reading field", "name", "field-name") - v.FieldName, err = func(r wrpc.IndexReader, path ...uint32) (*string, error) { + v.FieldName, err = func(r wrpc.IndexReadCloser, path ...uint32) (*string, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1321,7 +1328,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, fmt.Errorf("failed to read `field-name` field: %w", err) } slog.Debug("reading field", "name", "field-size") - v.FieldSize, err = func(r wrpc.IndexReader, path ...uint32) (*uint32, error) { + v.FieldSize, err = func(r wrpc.IndexReadCloser, path ...uint32) (*uint32, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1375,7 +1382,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ case wasi__http__types.ErrorCodeHttpResponseIncomplete: return v.SetHttpResponseIncomplete(), nil case wasi__http__types.ErrorCodeHttpResponseHeaderSectionSize: - payload, err := func(r wrpc.IndexReader, path ...uint32) (*uint32, error) { + payload, err := func(r wrpc.IndexReadCloser, path ...uint32) (*uint32, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1422,11 +1429,11 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ } return v.SetHttpResponseHeaderSectionSize(payload), nil case wasi__http__types.ErrorCodeHttpResponseHeaderSize: - payload, err := func(r wrpc.IndexReader, path ...uint32) (*wasi__http__types.FieldSizePayload, error) { + payload, err := func(r wrpc.IndexReadCloser, path ...uint32) (*wasi__http__types.FieldSizePayload, error) { v := &wasi__http__types.FieldSizePayload{} var err error slog.Debug("reading field", "name", "field-name") - v.FieldName, err = func(r wrpc.IndexReader, path ...uint32) (*string, error) { + v.FieldName, err = func(r wrpc.IndexReadCloser, path ...uint32) (*string, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1485,7 +1492,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, fmt.Errorf("failed to read `field-name` field: %w", err) } slog.Debug("reading field", "name", "field-size") - v.FieldSize, err = func(r wrpc.IndexReader, path ...uint32) (*uint32, error) { + v.FieldSize, err = func(r wrpc.IndexReadCloser, path ...uint32) (*uint32, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1537,7 +1544,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ } return v.SetHttpResponseHeaderSize(payload), nil case wasi__http__types.ErrorCodeHttpResponseBodySize: - payload, err := func(r wrpc.IndexReader, path ...uint32) (*uint64, error) { + payload, err := func(r wrpc.IndexReadCloser, path ...uint32) (*uint64, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1584,7 +1591,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ } return v.SetHttpResponseBodySize(payload), nil case wasi__http__types.ErrorCodeHttpResponseTrailerSectionSize: - payload, err := func(r wrpc.IndexReader, path ...uint32) (*uint32, error) { + payload, err := func(r wrpc.IndexReadCloser, path ...uint32) (*uint32, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1631,11 +1638,11 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ } return v.SetHttpResponseTrailerSectionSize(payload), nil case wasi__http__types.ErrorCodeHttpResponseTrailerSize: - payload, err := func(r wrpc.IndexReader, path ...uint32) (*wasi__http__types.FieldSizePayload, error) { + payload, err := func(r wrpc.IndexReadCloser, path ...uint32) (*wasi__http__types.FieldSizePayload, error) { v := &wasi__http__types.FieldSizePayload{} var err error slog.Debug("reading field", "name", "field-name") - v.FieldName, err = func(r wrpc.IndexReader, path ...uint32) (*string, error) { + v.FieldName, err = func(r wrpc.IndexReadCloser, path ...uint32) (*string, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1694,7 +1701,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, fmt.Errorf("failed to read `field-name` field: %w", err) } slog.Debug("reading field", "name", "field-size") - v.FieldSize, err = func(r wrpc.IndexReader, path ...uint32) (*uint32, error) { + v.FieldSize, err = func(r wrpc.IndexReadCloser, path ...uint32) (*uint32, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1746,7 +1753,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ } return v.SetHttpResponseTrailerSize(payload), nil case wasi__http__types.ErrorCodeHttpResponseTransferCoding: - payload, err := func(r wrpc.IndexReader, path ...uint32) (*string, error) { + payload, err := func(r wrpc.IndexReadCloser, path ...uint32) (*string, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1806,7 +1813,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ } return v.SetHttpResponseTransferCoding(payload), nil case wasi__http__types.ErrorCodeHttpResponseContentCoding: - payload, err := func(r wrpc.IndexReader, path ...uint32) (*string, error) { + payload, err := func(r wrpc.IndexReadCloser, path ...uint32) (*string, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1876,7 +1883,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ case wasi__http__types.ErrorCodeConfigurationError: return v.SetConfigurationError(), nil case wasi__http__types.ErrorCodeInternalError: - payload, err := func(r wrpc.IndexReader, path ...uint32) (*string, error) { + payload, err := func(r wrpc.IndexReadCloser, path ...uint32) (*string, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { diff --git a/examples/http-server/bindings/wrpc/http/types/bindings.wrpc.go b/examples/http-server/bindings/wrpc/http/types/bindings.wrpc.go index f2745ab..33f976f 100644 --- a/examples/http-server/bindings/wrpc/http/types/bindings.wrpc.go +++ b/examples/http-server/bindings/wrpc/http/types/bindings.wrpc.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen-wrpc-go` 0.8.0. DO NOT EDIT! +// Generated by `wit-bindgen-wrpc-go` 0.9.1. DO NOT EDIT! package types import ( @@ -146,7 +146,7 @@ func (v *RequestOptions) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested record writer: %w", err) } write := write go func() { @@ -168,7 +168,7 @@ func (v *RequestOptions) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) } type Request struct { - Body io.Reader + Body io.ReadCloser Trailers wrpc.Receiver[[]*wrpc.Tuple2[string, [][]uint8]] Method *wasi__http__types.Method PathWithQuery *string @@ -182,7 +182,7 @@ func (v *Request) String() string { return "Request" } func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { writes := make(map[uint32]func(wrpc.IndexWriter) error, 7) slog.Debug("writing field", "name", "body") - write0, err := func(v io.Reader, w interface { + write0, err := func(v io.ReadCloser, w interface { io.ByteWriter io.Writer }) (write func(wrpc.IndexWriter) error, err error) { @@ -192,14 +192,12 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, } return func(w wrpc.IndexWriter) (err error) { defer func() { - body, ok := v.(io.Closer) - if ok { - if cErr := body.Close(); cErr != nil { - if err == nil { - err = fmt.Errorf("failed to close pending byte stream: %w", cErr) - } else { - slog.Warn("failed to close pending byte stream", "err", cErr) - } + slog.Debug("closing byte list stream writer") + if cErr := v.Close(); cErr != nil { + if err == nil { + err = fmt.Errorf("failed to close pending byte stream: %w", cErr) + } else { + slog.Warn("failed to close pending byte stream", "err", cErr) } } }() @@ -217,13 +215,15 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, if n > math.MaxUint32 { return fmt.Errorf("pending byte stream chunk length of %d overflows a 32-bit integer", n) } - slog.Debug("writing pending byte stream chunk length", "len", n) - if err := wrpc.WriteUint32(uint32(n), w); err != nil { - return fmt.Errorf("failed to write pending byte stream chunk length of %d: %w", n, err) - } - _, err = w.Write(chunk[:n]) - if err != nil { - return fmt.Errorf("failed to write pending byte stream chunk contents: %w", err) + if n > 0 { + slog.Debug("writing pending byte stream chunk length", "len", n) + if err := wrpc.WriteUint32(uint32(n), w); err != nil { + return fmt.Errorf("failed to write pending byte stream chunk length of %d: %w", n, err) + } + _, err = w.Write(chunk[:n]) + if err != nil { + return fmt.Errorf("failed to write pending byte stream chunk contents: %w", err) + } } if end { if err := w.WriteByte(0); err != nil { @@ -251,14 +251,12 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, } return func(w wrpc.IndexWriter) (err error) { defer func() { - body, ok := v.(io.Closer) - if ok { - if cErr := body.Close(); cErr != nil { - if err == nil { - err = fmt.Errorf("failed to close pending future: %w", cErr) - } else { - slog.Warn("failed to close pending future", "err", cErr) - } + slog.Debug("closing future writer") + if cErr := v.Close(); cErr != nil { + if err == nil { + err = fmt.Errorf("failed to close pending future: %w", cErr) + } else { + slog.Warn("failed to close pending future", "err", cErr) } } }() @@ -397,7 +395,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -432,7 +430,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -466,7 +464,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested tuple writer: %w", err) } write := write go func() { @@ -501,7 +499,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -790,7 +788,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -825,7 +823,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -859,7 +857,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested tuple writer: %w", err) } write := write go func() { @@ -894,7 +892,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -929,7 +927,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested record writer: %w", err) } write := write go func() { @@ -951,7 +949,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, } type Response struct { - Body io.Reader + Body io.ReadCloser Trailers wrpc.Receiver[[]*wrpc.Tuple2[string, [][]uint8]] Status uint16 Headers []*wrpc.Tuple2[string, [][]uint8] @@ -962,7 +960,7 @@ func (v *Response) String() string { return "Response" } func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { writes := make(map[uint32]func(wrpc.IndexWriter) error, 4) slog.Debug("writing field", "name", "body") - write0, err := func(v io.Reader, w interface { + write0, err := func(v io.ReadCloser, w interface { io.ByteWriter io.Writer }) (write func(wrpc.IndexWriter) error, err error) { @@ -972,14 +970,12 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error } return func(w wrpc.IndexWriter) (err error) { defer func() { - body, ok := v.(io.Closer) - if ok { - if cErr := body.Close(); cErr != nil { - if err == nil { - err = fmt.Errorf("failed to close pending byte stream: %w", cErr) - } else { - slog.Warn("failed to close pending byte stream", "err", cErr) - } + slog.Debug("closing byte list stream writer") + if cErr := v.Close(); cErr != nil { + if err == nil { + err = fmt.Errorf("failed to close pending byte stream: %w", cErr) + } else { + slog.Warn("failed to close pending byte stream", "err", cErr) } } }() @@ -997,13 +993,15 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error if n > math.MaxUint32 { return fmt.Errorf("pending byte stream chunk length of %d overflows a 32-bit integer", n) } - slog.Debug("writing pending byte stream chunk length", "len", n) - if err := wrpc.WriteUint32(uint32(n), w); err != nil { - return fmt.Errorf("failed to write pending byte stream chunk length of %d: %w", n, err) - } - _, err = w.Write(chunk[:n]) - if err != nil { - return fmt.Errorf("failed to write pending byte stream chunk contents: %w", err) + if n > 0 { + slog.Debug("writing pending byte stream chunk length", "len", n) + if err := wrpc.WriteUint32(uint32(n), w); err != nil { + return fmt.Errorf("failed to write pending byte stream chunk length of %d: %w", n, err) + } + _, err = w.Write(chunk[:n]) + if err != nil { + return fmt.Errorf("failed to write pending byte stream chunk contents: %w", err) + } } if end { if err := w.WriteByte(0); err != nil { @@ -1031,14 +1029,12 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error } return func(w wrpc.IndexWriter) (err error) { defer func() { - body, ok := v.(io.Closer) - if ok { - if cErr := body.Close(); cErr != nil { - if err == nil { - err = fmt.Errorf("failed to close pending future: %w", cErr) - } else { - slog.Warn("failed to close pending future", "err", cErr) - } + slog.Debug("closing future writer") + if cErr := v.Close(); cErr != nil { + if err == nil { + err = fmt.Errorf("failed to close pending future: %w", cErr) + } else { + slog.Warn("failed to close pending future", "err", cErr) } } }() @@ -1177,7 +1173,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -1212,7 +1208,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -1246,7 +1242,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested tuple writer: %w", err) } write := write go func() { @@ -1281,7 +1277,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -1449,7 +1445,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -1484,7 +1480,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -1518,7 +1514,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested tuple writer: %w", err) } write := write go func() { @@ -1553,7 +1549,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -1588,7 +1584,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested record writer: %w", err) } write := write go func() { diff --git a/examples/http-server/go.mod b/examples/http-server/go.mod index 034b13d..b50cb6c 100644 --- a/examples/http-server/go.mod +++ b/examples/http-server/go.mod @@ -4,7 +4,7 @@ go 1.22.3 require ( go.wasmcloud.dev/provider v0.0.0-20240124183610-1a92f8d04935 - wrpc.io/go v0.0.3 + wrpc.io/go v0.1.0 ) require ( diff --git a/examples/http-server/go.sum b/examples/http-server/go.sum index f07611f..4913ffe 100644 --- a/examples/http-server/go.sum +++ b/examples/http-server/go.sum @@ -75,5 +75,5 @@ google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6h google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -wrpc.io/go v0.0.3 h1:clf0KiO8WTjYwkyorrZQ4sSf7k/7xP5gdL4934A4L7s= -wrpc.io/go v0.0.3/go.mod h1:3EZdmAh0pp6uNJ8RG4aciP3LLIDWlT2fJP6qd9Z/O6U= +wrpc.io/go v0.1.0 h1:D1mT5rGtoM6EXZYBFis5jQ2xc4BulJzNbk0Onb5qqEc= +wrpc.io/go v0.1.0/go.mod h1:3EZdmAh0pp6uNJ8RG4aciP3LLIDWlT2fJP6qd9Z/O6U= diff --git a/examples/keyvalue-inmemory/bindings/exports/wrpc/keyvalue/store/bindings.wrpc.go b/examples/keyvalue-inmemory/bindings/exports/wrpc/keyvalue/store/bindings.wrpc.go index 5d46021..ad62174 100644 --- a/examples/keyvalue-inmemory/bindings/exports/wrpc/keyvalue/store/bindings.wrpc.go +++ b/examples/keyvalue-inmemory/bindings/exports/wrpc/keyvalue/store/bindings.wrpc.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen-wrpc-go` 0.8.0. DO NOT EDIT! +// Generated by `wit-bindgen-wrpc-go` 0.9.1. DO NOT EDIT! package store import ( @@ -161,7 +161,7 @@ func (v *Error) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, e return func(w wrpc.IndexWriter) error { w, err := w.Index(2) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested variant writer: %w", err) } return write(w) }, nil @@ -242,7 +242,7 @@ func (v *KeyResponse) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) er wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -312,7 +312,7 @@ func (v *KeyResponse) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) er wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested record writer: %w", err) } write := write go func() { @@ -587,7 +587,7 @@ func ServeInterface(s wrpc.Server, h Handler) (stop func() error, err error) { wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -636,7 +636,7 @@ func ServeInterface(s wrpc.Server, h Handler) (stop func() error, err error) { } }(r0, &buf) if err != nil { - slog.WarnContext(ctx, "failed to write result value", "i", 0, "wrpc:keyvalue/store@0.2.0-draft", "name", "get", "err", err) + slog.WarnContext(ctx, "failed to write result value", "i", 0, "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "get", "err", err) return } if write0 != nil { @@ -645,23 +645,26 @@ func ServeInterface(s wrpc.Server, h Handler) (stop func() error, err error) { slog.DebugContext(ctx, "transmitting `wrpc:keyvalue/store@0.2.0-draft.get` result") _, err = w.Write(buf.Bytes()) if err != nil { - slog.WarnContext(ctx, "failed to write result", "wrpc:keyvalue/store@0.2.0-draft", "name", "get", "err", err) + slog.WarnContext(ctx, "failed to write result", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "get", "err", err) return } if len(writes) > 0 { for index, write := range writes { - w, err := w.Index(index) - if err != nil { - slog.ErrorContext(ctx, "failed to index writer", "index", index, "wrpc:keyvalue/store@0.2.0-draft", "name", "get", "err", err) - return - } - index := index - write := write - go func() { - if err := write(w); err != nil { - slog.WarnContext(ctx, "failed to write nested result value", "index", index, "wrpc:keyvalue/store@0.2.0-draft", "name", "get", "err", err) + _ = write + switch index { + case 0: + w, err := w.Index(0) + if err != nil { + slog.ErrorContext(ctx, "failed to index result writer", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "get", "err", err) + return } - }() + write := write + go func() { + if err := write(w); err != nil { + slog.WarnContext(ctx, "failed to write nested result value", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "get", "err", err) + } + }() + } } } }) @@ -854,7 +857,7 @@ func ServeInterface(s wrpc.Server, h Handler) (stop func() error, err error) { } }(r0, &buf) if err != nil { - slog.WarnContext(ctx, "failed to write result value", "i", 0, "wrpc:keyvalue/store@0.2.0-draft", "name", "set", "err", err) + slog.WarnContext(ctx, "failed to write result value", "i", 0, "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "set", "err", err) return } if write0 != nil { @@ -863,23 +866,26 @@ func ServeInterface(s wrpc.Server, h Handler) (stop func() error, err error) { slog.DebugContext(ctx, "transmitting `wrpc:keyvalue/store@0.2.0-draft.set` result") _, err = w.Write(buf.Bytes()) if err != nil { - slog.WarnContext(ctx, "failed to write result", "wrpc:keyvalue/store@0.2.0-draft", "name", "set", "err", err) + slog.WarnContext(ctx, "failed to write result", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "set", "err", err) return } if len(writes) > 0 { for index, write := range writes { - w, err := w.Index(index) - if err != nil { - slog.ErrorContext(ctx, "failed to index writer", "index", index, "wrpc:keyvalue/store@0.2.0-draft", "name", "set", "err", err) - return - } - index := index - write := write - go func() { - if err := write(w); err != nil { - slog.WarnContext(ctx, "failed to write nested result value", "index", index, "wrpc:keyvalue/store@0.2.0-draft", "name", "set", "err", err) + _ = write + switch index { + case 0: + w, err := w.Index(0) + if err != nil { + slog.ErrorContext(ctx, "failed to index result writer", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "set", "err", err) + return } - }() + write := write + go func() { + if err := write(w); err != nil { + slog.WarnContext(ctx, "failed to write nested result value", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "set", "err", err) + } + }() + } } } }) @@ -1030,7 +1036,7 @@ func ServeInterface(s wrpc.Server, h Handler) (stop func() error, err error) { } }(r0, &buf) if err != nil { - slog.WarnContext(ctx, "failed to write result value", "i", 0, "wrpc:keyvalue/store@0.2.0-draft", "name", "delete", "err", err) + slog.WarnContext(ctx, "failed to write result value", "i", 0, "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "delete", "err", err) return } if write0 != nil { @@ -1039,23 +1045,26 @@ func ServeInterface(s wrpc.Server, h Handler) (stop func() error, err error) { slog.DebugContext(ctx, "transmitting `wrpc:keyvalue/store@0.2.0-draft.delete` result") _, err = w.Write(buf.Bytes()) if err != nil { - slog.WarnContext(ctx, "failed to write result", "wrpc:keyvalue/store@0.2.0-draft", "name", "delete", "err", err) + slog.WarnContext(ctx, "failed to write result", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "delete", "err", err) return } if len(writes) > 0 { for index, write := range writes { - w, err := w.Index(index) - if err != nil { - slog.ErrorContext(ctx, "failed to index writer", "index", index, "wrpc:keyvalue/store@0.2.0-draft", "name", "delete", "err", err) - return - } - index := index - write := write - go func() { - if err := write(w); err != nil { - slog.WarnContext(ctx, "failed to write nested result value", "index", index, "wrpc:keyvalue/store@0.2.0-draft", "name", "delete", "err", err) + _ = write + switch index { + case 0: + w, err := w.Index(0) + if err != nil { + slog.ErrorContext(ctx, "failed to index result writer", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "delete", "err", err) + return } - }() + write := write + go func() { + if err := write(w); err != nil { + slog.WarnContext(ctx, "failed to write nested result value", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "delete", "err", err) + } + }() + } } } }) @@ -1221,7 +1230,7 @@ func ServeInterface(s wrpc.Server, h Handler) (stop func() error, err error) { } }(r0, &buf) if err != nil { - slog.WarnContext(ctx, "failed to write result value", "i", 0, "wrpc:keyvalue/store@0.2.0-draft", "name", "exists", "err", err) + slog.WarnContext(ctx, "failed to write result value", "i", 0, "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "exists", "err", err) return } if write0 != nil { @@ -1230,23 +1239,26 @@ func ServeInterface(s wrpc.Server, h Handler) (stop func() error, err error) { slog.DebugContext(ctx, "transmitting `wrpc:keyvalue/store@0.2.0-draft.exists` result") _, err = w.Write(buf.Bytes()) if err != nil { - slog.WarnContext(ctx, "failed to write result", "wrpc:keyvalue/store@0.2.0-draft", "name", "exists", "err", err) + slog.WarnContext(ctx, "failed to write result", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "exists", "err", err) return } if len(writes) > 0 { for index, write := range writes { - w, err := w.Index(index) - if err != nil { - slog.ErrorContext(ctx, "failed to index writer", "index", index, "wrpc:keyvalue/store@0.2.0-draft", "name", "exists", "err", err) - return - } - index := index - write := write - go func() { - if err := write(w); err != nil { - slog.WarnContext(ctx, "failed to write nested result value", "index", index, "wrpc:keyvalue/store@0.2.0-draft", "name", "exists", "err", err) + _ = write + switch index { + case 0: + w, err := w.Index(0) + if err != nil { + slog.ErrorContext(ctx, "failed to index result writer", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "exists", "err", err) + return } - }() + write := write + go func() { + if err := write(w); err != nil { + slog.WarnContext(ctx, "failed to write nested result value", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "exists", "err", err) + } + }() + } } } }) @@ -1307,7 +1319,7 @@ func ServeInterface(s wrpc.Server, h Handler) (stop func() error, err error) { return } slog.DebugContext(ctx, "reading parameter", "i", 1) - p1, err := func(r wrpc.IndexReader, path ...uint32) (*uint64, error) { + p1, err := func(r wrpc.IndexReadCloser, path ...uint32) (*uint64, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1411,7 +1423,7 @@ func ServeInterface(s wrpc.Server, h Handler) (stop func() error, err error) { } }(r0, &buf) if err != nil { - slog.WarnContext(ctx, "failed to write result value", "i", 0, "wrpc:keyvalue/store@0.2.0-draft", "name", "list-keys", "err", err) + slog.WarnContext(ctx, "failed to write result value", "i", 0, "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "list-keys", "err", err) return } if write0 != nil { @@ -1420,23 +1432,26 @@ func ServeInterface(s wrpc.Server, h Handler) (stop func() error, err error) { slog.DebugContext(ctx, "transmitting `wrpc:keyvalue/store@0.2.0-draft.list-keys` result") _, err = w.Write(buf.Bytes()) if err != nil { - slog.WarnContext(ctx, "failed to write result", "wrpc:keyvalue/store@0.2.0-draft", "name", "list-keys", "err", err) + slog.WarnContext(ctx, "failed to write result", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "list-keys", "err", err) return } if len(writes) > 0 { for index, write := range writes { - w, err := w.Index(index) - if err != nil { - slog.ErrorContext(ctx, "failed to index writer", "index", index, "wrpc:keyvalue/store@0.2.0-draft", "name", "list-keys", "err", err) - return - } - index := index - write := write - go func() { - if err := write(w); err != nil { - slog.WarnContext(ctx, "failed to write nested result value", "index", index, "wrpc:keyvalue/store@0.2.0-draft", "name", "list-keys", "err", err) + _ = write + switch index { + case 0: + w, err := w.Index(0) + if err != nil { + slog.ErrorContext(ctx, "failed to index result writer", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "list-keys", "err", err) + return } - }() + write := write + go func() { + if err := write(w); err != nil { + slog.WarnContext(ctx, "failed to write nested result value", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "list-keys", "err", err) + } + }() + } } } }) diff --git a/examples/keyvalue-inmemory/bindings/server.wrpc.go b/examples/keyvalue-inmemory/bindings/server.wrpc.go index 605d264..fa2c20b 100644 --- a/examples/keyvalue-inmemory/bindings/server.wrpc.go +++ b/examples/keyvalue-inmemory/bindings/server.wrpc.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen-wrpc-go` 0.8.0. DO NOT EDIT! +// Generated by `wit-bindgen-wrpc-go` 0.9.1. DO NOT EDIT! // server package contains wRPC bindings for `server` world package server diff --git a/examples/keyvalue-inmemory/bindings/testing/testing.wrpc.go b/examples/keyvalue-inmemory/bindings/testing/testing.wrpc.go index 917d428..fdcc7b4 100644 --- a/examples/keyvalue-inmemory/bindings/testing/testing.wrpc.go +++ b/examples/keyvalue-inmemory/bindings/testing/testing.wrpc.go @@ -1,3 +1,3 @@ -// Generated by `wit-bindgen-wrpc-go` 0.8.0. DO NOT EDIT! +// Generated by `wit-bindgen-wrpc-go` 0.9.1. DO NOT EDIT! // testing package contains wRPC bindings for `testing` world package testing diff --git a/examples/keyvalue-inmemory/bindings/testing/wrpc/keyvalue/store/bindings.wrpc.go b/examples/keyvalue-inmemory/bindings/testing/wrpc/keyvalue/store/bindings.wrpc.go index be761b8..7d07636 100644 --- a/examples/keyvalue-inmemory/bindings/testing/wrpc/keyvalue/store/bindings.wrpc.go +++ b/examples/keyvalue-inmemory/bindings/testing/wrpc/keyvalue/store/bindings.wrpc.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen-wrpc-go` 0.8.0. DO NOT EDIT! +// Generated by `wit-bindgen-wrpc-go` 0.9.1. DO NOT EDIT! package store import ( @@ -161,7 +161,7 @@ func (v *Error) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, e return func(w wrpc.IndexWriter) error { w, err := w.Index(2) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested variant writer: %w", err) } return write(w) }, nil @@ -242,7 +242,7 @@ func (v *KeyResponse) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) er wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -312,7 +312,7 @@ func (v *KeyResponse) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) er wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested record writer: %w", err) } write := write go func() { @@ -430,7 +430,7 @@ func Get(ctx__ context.Context, wrpc__ wrpc.Invoker, bucket string, key string) if cErr__ := w__.Close(); cErr__ != nil { slog.DebugContext(ctx__, "failed to close outgoing stream", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "get", "err", cErr__) } - r0__, err__ = func(r wrpc.IndexReader, path ...uint32) (*wrpc.Result[[]uint8, Error], error) { + r0__, err__ = func(r wrpc.IndexReadCloser, path ...uint32) (*wrpc.Result[[]uint8, Error], error) { slog.Debug("reading result status byte") status, err := r.ReadByte() if err != nil { @@ -439,7 +439,7 @@ func Get(ctx__ context.Context, wrpc__ wrpc.Invoker, bucket string, key string) switch status { case 0: slog.Debug("reading `result::ok` payload") - v, err := func(r wrpc.IndexReader, path ...uint32) ([]uint8, error) { + v, err := func(r wrpc.IndexReadCloser, path ...uint32) ([]uint8, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -497,7 +497,7 @@ func Get(ctx__ context.Context, wrpc__ wrpc.Invoker, bucket string, key string) return &wrpc.Result[[]uint8, Error]{Ok: &v}, nil case 1: slog.Debug("reading `result::err` payload") - v, err := func(r wrpc.IndexReader, path ...uint32) (*Error, error) { + v, err := func(r wrpc.IndexReadCloser, path ...uint32) (*Error, error) { v := &Error{} n, err := func(r io.ByteReader) (uint8, error) { var x uint8 @@ -687,7 +687,7 @@ func Set(ctx__ context.Context, wrpc__ wrpc.Invoker, bucket string, key string, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -738,7 +738,7 @@ func Set(ctx__ context.Context, wrpc__ wrpc.Invoker, bucket string, key string, if cErr__ := w__.Close(); cErr__ != nil { slog.DebugContext(ctx__, "failed to close outgoing stream", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "set", "err", cErr__) } - r0__, err__ = func(r wrpc.IndexReader, path ...uint32) (*wrpc.Result[struct{}, Error], error) { + r0__, err__ = func(r wrpc.IndexReadCloser, path ...uint32) (*wrpc.Result[struct{}, Error], error) { slog.Debug("reading result status byte") status, err := r.ReadByte() if err != nil { @@ -750,7 +750,7 @@ func Set(ctx__ context.Context, wrpc__ wrpc.Invoker, bucket string, key string, return &wrpc.Result[struct{}, Error]{Ok: &v}, nil case 1: slog.Debug("reading `result::err` payload") - v, err := func(r wrpc.IndexReader, path ...uint32) (*Error, error) { + v, err := func(r wrpc.IndexReadCloser, path ...uint32) (*Error, error) { v := &Error{} n, err := func(r io.ByteReader) (uint8, error) { var x uint8 @@ -923,7 +923,7 @@ func Delete(ctx__ context.Context, wrpc__ wrpc.Invoker, bucket string, key strin if cErr__ := w__.Close(); cErr__ != nil { slog.DebugContext(ctx__, "failed to close outgoing stream", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "delete", "err", cErr__) } - r0__, err__ = func(r wrpc.IndexReader, path ...uint32) (*wrpc.Result[struct{}, Error], error) { + r0__, err__ = func(r wrpc.IndexReadCloser, path ...uint32) (*wrpc.Result[struct{}, Error], error) { slog.Debug("reading result status byte") status, err := r.ReadByte() if err != nil { @@ -935,7 +935,7 @@ func Delete(ctx__ context.Context, wrpc__ wrpc.Invoker, bucket string, key strin return &wrpc.Result[struct{}, Error]{Ok: &v}, nil case 1: slog.Debug("reading `result::err` payload") - v, err := func(r wrpc.IndexReader, path ...uint32) (*Error, error) { + v, err := func(r wrpc.IndexReadCloser, path ...uint32) (*Error, error) { v := &Error{} n, err := func(r io.ByteReader) (uint8, error) { var x uint8 @@ -1109,7 +1109,7 @@ func Exists(ctx__ context.Context, wrpc__ wrpc.Invoker, bucket string, key strin if cErr__ := w__.Close(); cErr__ != nil { slog.DebugContext(ctx__, "failed to close outgoing stream", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "exists", "err", cErr__) } - r0__, err__ = func(r wrpc.IndexReader, path ...uint32) (*wrpc.Result[bool, Error], error) { + r0__, err__ = func(r wrpc.IndexReadCloser, path ...uint32) (*wrpc.Result[bool, Error], error) { slog.Debug("reading result status byte") status, err := r.ReadByte() if err != nil { @@ -1140,7 +1140,7 @@ func Exists(ctx__ context.Context, wrpc__ wrpc.Invoker, bucket string, key strin return &wrpc.Result[bool, Error]{Ok: &v}, nil case 1: slog.Debug("reading `result::err` payload") - v, err := func(r wrpc.IndexReader, path ...uint32) (*Error, error) { + v, err := func(r wrpc.IndexReadCloser, path ...uint32) (*Error, error) { v := &Error{} n, err := func(r io.ByteReader) (uint8, error) { var x uint8 @@ -1331,7 +1331,7 @@ func ListKeys(ctx__ context.Context, wrpc__ wrpc.Invoker, bucket string, cursor if cErr__ := w__.Close(); cErr__ != nil { slog.DebugContext(ctx__, "failed to close outgoing stream", "instance", "wrpc:keyvalue/store@0.2.0-draft", "name", "list-keys", "err", cErr__) } - r0__, err__ = func(r wrpc.IndexReader, path ...uint32) (*wrpc.Result[KeyResponse, Error], error) { + r0__, err__ = func(r wrpc.IndexReadCloser, path ...uint32) (*wrpc.Result[KeyResponse, Error], error) { slog.Debug("reading result status byte") status, err := r.ReadByte() if err != nil { @@ -1340,11 +1340,11 @@ func ListKeys(ctx__ context.Context, wrpc__ wrpc.Invoker, bucket string, cursor switch status { case 0: slog.Debug("reading `result::ok` payload") - v, err := func(r wrpc.IndexReader, path ...uint32) (*KeyResponse, error) { + v, err := func(r wrpc.IndexReadCloser, path ...uint32) (*KeyResponse, error) { v := &KeyResponse{} var err error slog.Debug("reading field", "name", "keys") - v.Keys, err = func(r wrpc.IndexReader, path ...uint32) ([]string, error) { + v.Keys, err = func(r wrpc.IndexReadCloser, path ...uint32) ([]string, error) { var x uint32 var s uint for i := 0; i < 5; i++ { @@ -1415,7 +1415,7 @@ func ListKeys(ctx__ context.Context, wrpc__ wrpc.Invoker, bucket string, cursor return nil, fmt.Errorf("failed to read `keys` field: %w", err) } slog.Debug("reading field", "name", "cursor") - v.Cursor, err = func(r wrpc.IndexReader, path ...uint32) (*uint64, error) { + v.Cursor, err = func(r wrpc.IndexReadCloser, path ...uint32) (*uint64, error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -1468,7 +1468,7 @@ func ListKeys(ctx__ context.Context, wrpc__ wrpc.Invoker, bucket string, cursor return &wrpc.Result[KeyResponse, Error]{Ok: v}, nil case 1: slog.Debug("reading `result::err` payload") - v, err := func(r wrpc.IndexReader, path ...uint32) (*Error, error) { + v, err := func(r wrpc.IndexReadCloser, path ...uint32) (*Error, error) { v := &Error{} n, err := func(r io.ByteReader) (uint8, error) { var x uint8 diff --git a/examples/keyvalue-inmemory/go.mod b/examples/keyvalue-inmemory/go.mod index 2d922f3..4b473bb 100644 --- a/examples/keyvalue-inmemory/go.mod +++ b/examples/keyvalue-inmemory/go.mod @@ -12,7 +12,7 @@ require ( go.opentelemetry.io/otel v1.28.0 go.opentelemetry.io/otel/trace v1.28.0 go.wasmcloud.dev/provider v0.0.0-20240124183610-1a92f8d04935 - wrpc.io/go v0.0.3 + wrpc.io/go v0.1.0 ) require ( diff --git a/examples/keyvalue-inmemory/go.sum b/examples/keyvalue-inmemory/go.sum index b0a3643..4b1e0e4 100644 --- a/examples/keyvalue-inmemory/go.sum +++ b/examples/keyvalue-inmemory/go.sum @@ -52,6 +52,10 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= @@ -84,6 +88,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/shirou/gopsutil/v3 v3.23.12 h1:z90NtUkp3bMtmICZKpC4+WaknU1eXtp5vtbQ11DgpE4= github.com/shirou/gopsutil/v3 v3.23.12/go.mod h1:1FrWgea594Jp7qmjHUUPlJDTPgcsb9mGnXDxavtikzM= github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= @@ -95,14 +101,14 @@ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVs github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/testcontainers/testcontainers-go v0.33.0 h1:zJS9PfXYT5O0ZFXM2xxXfk4J5UMw/kRiISng037Gxdw= -github.com/testcontainers/testcontainers-go v0.33.0/go.mod h1:W80YpTa8D5C3Yy16icheD01UTDu+LmXIA2Keo+jWtT8= github.com/testcontainers/testcontainers-go v0.33.1-0.20240912084704-b60497e9c792 h1:FY0JalUwwym1EK0rmDcBh5w+kZcBJ1NR5o7PVQei5fI= github.com/testcontainers/testcontainers-go v0.33.1-0.20240912084704-b60497e9c792/go.mod h1:rM5A56wRZcJhnk0CRNYGU4CQYjECaGXbTzHB2/R8p2s= github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= @@ -200,10 +206,12 @@ google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjr google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= -wrpc.io/go v0.0.3 h1:clf0KiO8WTjYwkyorrZQ4sSf7k/7xP5gdL4934A4L7s= -wrpc.io/go v0.0.3/go.mod h1:3EZdmAh0pp6uNJ8RG4aciP3LLIDWlT2fJP6qd9Z/O6U= +wrpc.io/go v0.1.0 h1:D1mT5rGtoM6EXZYBFis5jQ2xc4BulJzNbk0Onb5qqEc= +wrpc.io/go v0.1.0/go.mod h1:3EZdmAh0pp6uNJ8RG4aciP3LLIDWlT2fJP6qd9Z/O6U= diff --git a/go.mod b/go.mod index 0d83120..fb792dc 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( go.opentelemetry.io/otel/sdk v1.28.0 go.opentelemetry.io/otel/sdk/log v0.4.0 go.opentelemetry.io/otel/sdk/metric v1.28.0 - wrpc.io/go v0.0.3 + wrpc.io/go v0.1.0 ) require ( diff --git a/go.sum b/go.sum index f07611f..4913ffe 100644 --- a/go.sum +++ b/go.sum @@ -75,5 +75,5 @@ google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6h google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -wrpc.io/go v0.0.3 h1:clf0KiO8WTjYwkyorrZQ4sSf7k/7xP5gdL4934A4L7s= -wrpc.io/go v0.0.3/go.mod h1:3EZdmAh0pp6uNJ8RG4aciP3LLIDWlT2fJP6qd9Z/O6U= +wrpc.io/go v0.1.0 h1:D1mT5rGtoM6EXZYBFis5jQ2xc4BulJzNbk0Onb5qqEc= +wrpc.io/go v0.1.0/go.mod h1:3EZdmAh0pp6uNJ8RG4aciP3LLIDWlT2fJP6qd9Z/O6U= diff --git a/internal/internal.wrpc.go b/internal/internal.wrpc.go index 88cc99c..88187e9 100644 --- a/internal/internal.wrpc.go +++ b/internal/internal.wrpc.go @@ -1,3 +1,3 @@ -// Generated by `wit-bindgen-wrpc-go` 0.8.0. DO NOT EDIT! +// Generated by `wit-bindgen-wrpc-go` 0.9.1. DO NOT EDIT! // internal package contains wRPC bindings for `internal` world package internal diff --git a/internal/wasi/clocks/monotonic_clock/bindings.wrpc.go b/internal/wasi/clocks/monotonic_clock/bindings.wrpc.go index ae9bd07..f27f8a7 100644 --- a/internal/wasi/clocks/monotonic_clock/bindings.wrpc.go +++ b/internal/wasi/clocks/monotonic_clock/bindings.wrpc.go @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen-wrpc-go` 0.8.0. DO NOT EDIT! +// Generated by `wit-bindgen-wrpc-go` 0.9.1. DO NOT EDIT! package monotonic_clock import ( @@ -10,7 +10,6 @@ import ( wasi__io__poll "go.wasmcloud.dev/provider/internal/wasi/io/poll" io "io" slog "log/slog" - utf8 "unicode/utf8" wrpc "wrpc.io/go" ) @@ -44,33 +43,29 @@ func Now(ctx__ context.Context, wrpc__ wrpc.Invoker) (r0__ uint64, err__ error) if cErr__ := w__.Close(); cErr__ != nil { slog.DebugContext(ctx__, "failed to close outgoing stream", "instance", "wasi:clocks/monotonic-clock@0.2.0", "name", "now", "err", cErr__) } - r0__, err__ = func() (Instant, error) { - v, err := func(r io.ByteReader) (uint64, error) { - var x uint64 - var s uint8 - for i := 0; i < 10; i++ { - slog.Debug("reading u64 byte", "i", i) - b, err := r.ReadByte() - if err != nil { - if i > 0 && err == io.EOF { - err = io.ErrUnexpectedEOF - } - return x, fmt.Errorf("failed to read u64 byte: %w", err) - } - if s == 63 && b > 0x01 { - return x, errors.New("varint overflows a 64-bit integer") - } - if b < 0x80 { - return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF } - x |= uint64(b&0x7f) << s - s += 7 + return x, fmt.Errorf("failed to read u64 byte: %w", err) } - return x, errors.New("varint overflows a 64-bit integer") - }(r__) - return (Instant)(v), err - }() - + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { - err = io.ErrUnexpectedEOF - } - return x, fmt.Errorf("failed to read u64 byte: %w", err) - } - if s == 63 && b > 0x01 { - return x, errors.New("varint overflows a 64-bit integer") - } - if b < 0x80 { - return x | uint64(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF } - x |= uint64(b&0x7f) << s - s += 7 + return x, fmt.Errorf("failed to read u64 byte: %w", err) } - return x, errors.New("varint overflows a 64-bit integer") - }(r__) - return (Duration)(v), err - }() - + if s == 63 && b > 0x01 { + return x, errors.New("varint overflows a 64-bit integer") + } + if b < 0x80 { + return x | uint64(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { - err = io.ErrUnexpectedEOF - } - return x, fmt.Errorf("failed to read u16 byte: %w", err) - } - if s == 14 && b > 0x03 { - return x, errors.New("varint overflows a 16-bit integer") - } - if b < 0x80 { - return x | uint16(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF } - x |= uint16(b&0x7f) << s - s += 7 + return x, fmt.Errorf("failed to read u16 byte: %w", err) } - return x, errors.New("varint overflows a 16-bit integer") - }(r__) - return (StatusCode)(v), err - }() - + if s == 14 && b > 0x03 { + return x, errors.New("varint overflows a 16-bit integer") + } + if b < 0x80 { + return x | uint16(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { - err = io.ErrUnexpectedEOF - } - return x, fmt.Errorf("failed to read u16 byte: %w", err) - } - if s == 14 && b > 0x03 { - return x, errors.New("varint overflows a 16-bit integer") - } - if b < 0x80 { - return x | uint16(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF } - x |= uint16(b&0x7f) << s - s += 7 + return x, fmt.Errorf("failed to read u16 byte: %w", err) } - return x, errors.New("varint overflows a 16-bit integer") - }(r__) - return (StatusCode)(v), err - }() - + if s == 14 && b > 0x03 { + return x, errors.New("varint overflows a 16-bit integer") + } + if b < 0x80 { + return x | uint16(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } - return "", fmt.Errorf("failed to read owned resource ID length byte: %w", err) + return nil, fmt.Errorf("failed to read owned resource handle length byte: %w", err) } if b < 0x80 { if i == 4 && b > 1 { - return "", errors.New("owned resource ID length overflows a 32-bit integer") + return nil, errors.New("owned resource handle length overflows a 32-bit integer") } x = x | uint32(b)< 0 { + var err error + r, err = r.Index(path...) + if err != nil { + return nil, fmt.Errorf("failed to index nested byte stream reader: %w", err) + } } return wrpc.NewByteStreamReader(r), nil case 1: slog.Debug("reading ready byte stream contents") - buf, err := func(r interface { - io.ByteReader - io.Reader - }, - ) ([]byte, error) { - var x uint32 - var s uint - for i := 0; i < 5; i++ { - slog.Debug("reading byte list length", "i", i) - b, err := r.ReadByte() - if err != nil { - if i > 0 && err == io.EOF { - err = io.ErrUnexpectedEOF - } - return nil, fmt.Errorf("failed to read byte list length byte: %w", err) - } - if b < 0x80 { - if i == 4 && b > 1 { - return nil, errors.New("byte list length overflows a 32-bit integer") - } - x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return nil, fmt.Errorf("failed to read byte list length byte: %w", err) } - return buf, nil + if b < 0x80 { + if i == 4 && b > 1 { + return nil, errors.New("byte list length overflows a 32-bit integer") + } + x = x | uint32(b)< 0 { + var err error + r, err = r.Index(path...) + if err != nil { + return nil, fmt.Errorf("failed to index nested future reader: %w", err) + } } - return wrpc.NewDecodeReceiver(r, func(r wrpc.IndexReader) ([]*wrpc.Tuple2[string, [][]uint8], error) { + return wrpc.NewDecodeReceiver(r, func(r wrpc.IndexReadCloser) ([]*wrpc.Tuple2[string, [][]uint8], error) { slog.Debug("reading pending future element") - v, err := func(r wrpc.IndexReader, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { + v, err := func(r wrpc.IndexReadCloser, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { slog.Debug("reading option status byte") status, err := r.ReadByte() if err != nil { @@ -182,7 +186,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, nil case 1: slog.Debug("reading `option::some` payload") - v, err := func(r wrpc.IndexReader, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { + v, err := func(r wrpc.IndexReadCloser, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { var x uint32 var s uint for i := 0; i < 5; i++ { @@ -202,15 +206,14 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ vs := make([]*wrpc.Tuple2[string, [][]uint8], x) for i := range vs { slog.Debug("reading list element", "i", i) - vs[i], err = func(r wrpc.IndexReader, path ...uint32) (*wrpc.Tuple2[string, [][]uint8], error) { + vs[i], err = func(r wrpc.IndexReadCloser, path ...uint32) (*wrpc.Tuple2[string, [][]uint8], error) { v := &wrpc.Tuple2[string, [][]uint8]{} var err error slog.Debug("reading tuple element 0") v.V0, err = func(r interface { io.ByteReader io.Reader - }, - ) (string, error) { + }) (string, error) { var x uint32 var s uint8 for i := 0; i < 5; i++ { @@ -247,7 +250,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ return nil, fmt.Errorf("failed to read tuple element 0: %w", err) } slog.Debug("reading tuple element 1") - v.V1, err = func(r wrpc.IndexReader, path ...uint32) ([][]uint8, error) { + v.V1, err = func(r wrpc.IndexReadCloser, path ...uint32) ([][]uint8, error) { var x uint32 var s uint for i := 0; i < 5; i++ { @@ -270,8 +273,7 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ vs[i], err = func(r interface { io.ByteReader io.Reader - }, - ) ([]byte, error) { + }) ([]byte, error) { var x uint32 var s uint for i := 0; i < 5; i++ { @@ -343,171 +345,170 @@ func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__typ }), nil case 1: slog.Debug("reading ready future contents") - v, err := func(r wrpc.IndexReader, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { - slog.Debug("reading option status byte") - status, err := r.ReadByte() - if err != nil { - return nil, fmt.Errorf("failed to read option status byte: %w", err) - } - switch status { - case 0: - return nil, nil - case 1: - slog.Debug("reading `option::some` payload") - v, err := func(r wrpc.IndexReader, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { - var x uint32 - var s uint - for i := 0; i < 5; i++ { - slog.Debug("reading list length byte", "i", i) - b, err := r.ReadByte() - if err != nil { - if i > 0 && err == io.EOF { - err = io.ErrUnexpectedEOF - } - return nil, fmt.Errorf("failed to read list length byte: %w", err) - } - if b < 0x80 { - if i == 4 && b > 1 { - return nil, errors.New("list length overflows a 32-bit integer") + v, err := + func(r wrpc.IndexReadCloser, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { + slog.Debug("reading option status byte") + status, err := r.ReadByte() + if err != nil { + return nil, fmt.Errorf("failed to read option status byte: %w", err) + } + switch status { + case 0: + return nil, nil + case 1: + slog.Debug("reading `option::some` payload") + v, err := func(r wrpc.IndexReadCloser, path ...uint32) ([]*wrpc.Tuple2[string, [][]uint8], error) { + var x uint32 + var s uint + for i := 0; i < 5; i++ { + slog.Debug("reading list length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return nil, fmt.Errorf("failed to read list length byte: %w", err) } - x = x | uint32(b)< 0 && err == io.EOF { - err = io.ErrUnexpectedEOF - } - return "", fmt.Errorf("failed to read string length byte: %w", err) - } - if s == 28 && b > 0x0f { - return "", errors.New("string length overflows a 32-bit integer") - } - if b < 0x80 { - x = x | uint32(b)< 1 { + return nil, errors.New("list length overflows a 32-bit integer") + } + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return "", fmt.Errorf("failed to read string length byte: %w", err) } - if !utf8.Valid(buf) { - return string(buf), errors.New("string is not valid UTF-8") + if s == 28 && b > 0x0f { + return "", errors.New("string length overflows a 32-bit integer") } - return string(buf), nil - } - x |= uint32(b&0x7f) << s - s += 7 - } - return "", errors.New("string length overflows a 32-bit integer") - }(r) - if err != nil { - return nil, fmt.Errorf("failed to read tuple element 0: %w", err) - } - slog.Debug("reading tuple element 1") - v.V1, err = func(r wrpc.IndexReader, path ...uint32) ([][]uint8, error) { - var x uint32 - var s uint - for i := 0; i < 5; i++ { - slog.Debug("reading list length byte", "i", i) - b, err := r.ReadByte() - if err != nil { - if i > 0 && err == io.EOF { - err = io.ErrUnexpectedEOF + if b < 0x80 { + x = x | uint32(b)< 1 { - return nil, errors.New("list length overflows a 32-bit integer") + return "", errors.New("string length overflows a 32-bit integer") + }(r) + if err != nil { + return nil, fmt.Errorf("failed to read tuple element 0: %w", err) + } + slog.Debug("reading tuple element 1") + v.V1, err = func(r wrpc.IndexReadCloser, path ...uint32) ([][]uint8, error) { + var x uint32 + var s uint + for i := 0; i < 5; i++ { + slog.Debug("reading list length byte", "i", i) + b, err := r.ReadByte() + if err != nil { + if i > 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return nil, fmt.Errorf("failed to read list length byte: %w", err) } - x = x | uint32(b)< 0 && err == io.EOF { - err = io.ErrUnexpectedEOF - } - return nil, fmt.Errorf("failed to read byte list length byte: %w", err) - } - if b < 0x80 { - if i == 4 && b > 1 { - return nil, errors.New("byte list length overflows a 32-bit integer") - } - x = x | uint32(b)< 1 { + return nil, errors.New("list length overflows a 32-bit integer") + } + x = x | uint32(b)< 0 && err == io.EOF { + err = io.ErrUnexpectedEOF + } + return nil, fmt.Errorf("failed to read byte list length byte: %w", err) } - return buf, nil + if b < 0x80 { + if i == 4 && b > 1 { + return nil, errors.New("byte list length overflows a 32-bit integer") + } + x = x | uint32(b)< math.MaxUint32 { return fmt.Errorf("pending byte stream chunk length of %d overflows a 32-bit integer", n) } - slog.Debug("writing pending byte stream chunk length", "len", n) - if err := wrpc.WriteUint32(uint32(n), w); err != nil { - return fmt.Errorf("failed to write pending byte stream chunk length of %d: %w", n, err) - } - _, err = w.Write(chunk[:n]) - if err != nil { - return fmt.Errorf("failed to write pending byte stream chunk contents: %w", err) + if n > 0 { + slog.Debug("writing pending byte stream chunk length", "len", n) + if err := wrpc.WriteUint32(uint32(n), w); err != nil { + return fmt.Errorf("failed to write pending byte stream chunk length of %d: %w", n, err) + } + _, err = w.Write(chunk[:n]) + if err != nil { + return fmt.Errorf("failed to write pending byte stream chunk contents: %w", err) + } } if end { if err := w.WriteByte(0); err != nil { @@ -251,14 +251,12 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, } return func(w wrpc.IndexWriter) (err error) { defer func() { - body, ok := v.(io.Closer) - if ok { - if cErr := body.Close(); cErr != nil { - if err == nil { - err = fmt.Errorf("failed to close pending future: %w", cErr) - } else { - slog.Warn("failed to close pending future", "err", cErr) - } + slog.Debug("closing future writer") + if cErr := v.Close(); cErr != nil { + if err == nil { + err = fmt.Errorf("failed to close pending future: %w", cErr) + } else { + slog.Warn("failed to close pending future", "err", cErr) } } }() @@ -397,7 +395,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -432,7 +430,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -466,7 +464,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested tuple writer: %w", err) } write := write go func() { @@ -501,7 +499,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -790,7 +788,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -825,7 +823,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -859,7 +857,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested tuple writer: %w", err) } write := write go func() { @@ -894,7 +892,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -929,7 +927,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested record writer: %w", err) } write := write go func() { @@ -951,7 +949,7 @@ func (v *Request) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, } type Response struct { - Body io.Reader + Body io.ReadCloser Trailers wrpc.Receiver[[]*wrpc.Tuple2[string, [][]uint8]] Status uint16 Headers []*wrpc.Tuple2[string, [][]uint8] @@ -962,7 +960,7 @@ func (v *Response) String() string { return "Response" } func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error, error) { writes := make(map[uint32]func(wrpc.IndexWriter) error, 4) slog.Debug("writing field", "name", "body") - write0, err := func(v io.Reader, w interface { + write0, err := func(v io.ReadCloser, w interface { io.ByteWriter io.Writer }) (write func(wrpc.IndexWriter) error, err error) { @@ -972,14 +970,12 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error } return func(w wrpc.IndexWriter) (err error) { defer func() { - body, ok := v.(io.Closer) - if ok { - if cErr := body.Close(); cErr != nil { - if err == nil { - err = fmt.Errorf("failed to close pending byte stream: %w", cErr) - } else { - slog.Warn("failed to close pending byte stream", "err", cErr) - } + slog.Debug("closing byte list stream writer") + if cErr := v.Close(); cErr != nil { + if err == nil { + err = fmt.Errorf("failed to close pending byte stream: %w", cErr) + } else { + slog.Warn("failed to close pending byte stream", "err", cErr) } } }() @@ -997,13 +993,15 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error if n > math.MaxUint32 { return fmt.Errorf("pending byte stream chunk length of %d overflows a 32-bit integer", n) } - slog.Debug("writing pending byte stream chunk length", "len", n) - if err := wrpc.WriteUint32(uint32(n), w); err != nil { - return fmt.Errorf("failed to write pending byte stream chunk length of %d: %w", n, err) - } - _, err = w.Write(chunk[:n]) - if err != nil { - return fmt.Errorf("failed to write pending byte stream chunk contents: %w", err) + if n > 0 { + slog.Debug("writing pending byte stream chunk length", "len", n) + if err := wrpc.WriteUint32(uint32(n), w); err != nil { + return fmt.Errorf("failed to write pending byte stream chunk length of %d: %w", n, err) + } + _, err = w.Write(chunk[:n]) + if err != nil { + return fmt.Errorf("failed to write pending byte stream chunk contents: %w", err) + } } if end { if err := w.WriteByte(0); err != nil { @@ -1031,14 +1029,12 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error } return func(w wrpc.IndexWriter) (err error) { defer func() { - body, ok := v.(io.Closer) - if ok { - if cErr := body.Close(); cErr != nil { - if err == nil { - err = fmt.Errorf("failed to close pending future: %w", cErr) - } else { - slog.Warn("failed to close pending future", "err", cErr) - } + slog.Debug("closing future writer") + if cErr := v.Close(); cErr != nil { + if err == nil { + err = fmt.Errorf("failed to close pending future: %w", cErr) + } else { + slog.Warn("failed to close pending future", "err", cErr) } } }() @@ -1177,7 +1173,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -1212,7 +1208,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -1246,7 +1242,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested tuple writer: %w", err) } write := write go func() { @@ -1281,7 +1277,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -1449,7 +1445,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -1484,7 +1480,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -1518,7 +1514,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested tuple writer: %w", err) } write := write go func() { @@ -1553,7 +1549,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested list writer: %w", err) } write := write go func() { @@ -1588,7 +1584,7 @@ func (v *Response) WriteToIndex(w wrpc.ByteWriter) (func(wrpc.IndexWriter) error wg.Add(1) w, err := w.Index(index) if err != nil { - return fmt.Errorf("failed to index writer: %w", err) + return fmt.Errorf("failed to index nested record writer: %w", err) } write := write go func() { diff --git a/wrpchttp/incoming_test.go b/wrpchttp/incoming_test.go index 0811af2..3913459 100644 --- a/wrpchttp/incoming_test.go +++ b/wrpchttp/incoming_test.go @@ -98,6 +98,10 @@ func (f fakeReceiver) Receive() ([]*wrpc.Tuple2[string, [][]uint8], error) { return HttpHeaderToWrpc(f.headers), nil } +func (fakeReceiver) Close() error { + return nil +} + func TestRoundtrip(t *testing.T) { reqBody := "hello request" respBody := "hello response" @@ -159,7 +163,7 @@ func TestRoundtrip(t *testing.T) { resp := wrpctypes.Response{ Status: http.StatusOK, Headers: HttpHeaderToWrpc(http.Header{"X-Custom": []string{"x-value"}}), - Body: bytes.NewReader([]byte(respBody)), + Body: io.NopCloser(bytes.NewReader([]byte(respBody))), Trailers: fakeReceiver{headers: http.Header{}}, }