// Generated by `wit-bindgen-wrpc-go` 0.1.1. DO NOT EDIT! package outgoing_handler import ( bytes "bytes" context "context" errors "errors" fmt "fmt" wasi__http__types "github.com/wrpc/http/examples/go/http-outgoing-client/bindings/wasi/http/types" wrpc__http__types "github.com/wrpc/http/examples/go/http-outgoing-client/bindings/wrpc/http/types" wrpc "github.com/wrpc/wrpc/go" io "io" slog "log/slog" utf8 "unicode/utf8" ) type Request = wrpc__http__types.Request type Response = wrpc__http__types.Response type ErrorCode = wrpc__http__types.ErrorCode type RequestOptions = wrpc__http__types.RequestOptions func Handle(ctx__ context.Context, wrpc__ wrpc.Invoker, request *wrpc__http__types.Request, options *RequestOptions) (r0__ *wrpc.Result[Response, ErrorCode], close__ func() error, err__ error) { if err__ = wrpc__.Invoke(ctx__, "wrpc:http/outgoing-handler@0.1.0", "handle", func(w__ wrpc.IndexWriter, r__ wrpc.IndexReadCloser) error { close__ = r__.Close var buf__ bytes.Buffer writes__ := make(map[uint32]func(wrpc.IndexWriter) error, 2) write0__, err__ := (request).WriteToIndex(&buf__) if err__ != nil { return fmt.Errorf("failed to write `request` parameter: %w", err__) } if write0__ != nil { writes__[0] = write0__ } write1__, err__ := func(v *RequestOptions, w interface { io.ByteWriter io.Writer }) (func(wrpc.IndexWriter) error, error) { if v == nil { slog.Debug("writing `option::none` status byte") if err := w.WriteByte(0); err != nil { return nil, fmt.Errorf("failed to write `option::none` byte: %w", err) } return nil, nil } slog.Debug("writing `option::some` status byte") if err := w.WriteByte(1); err != nil { return nil, fmt.Errorf("failed to write `option::some` status byte: %w", err) } slog.Debug("writing `option::some` payload") write, err := (v).WriteToIndex(w) if err != nil { return nil, fmt.Errorf("failed to write `option::some` payload: %w", err) } return write, nil }(options, &buf__) if err__ != nil { return fmt.Errorf("failed to write `options` parameter: %w", err__) } if write1__ != nil { writes__[1] = write1__ } _, err__ = w__.Write(buf__.Bytes()) if err__ != nil { return fmt.Errorf("failed to write parameters: %w", err__) } r0__, err__ = func(r wrpc.IndexReader, path ...uint32) (*wrpc.Result[Response, ErrorCode], error) { slog.Debug("reading result status byte") status, err := r.ReadByte() if err != nil { return nil, fmt.Errorf("failed to read result status byte: %w", err) } switch status { case 0: slog.Debug("reading `result::ok` payload") v, err := func() (*Response, error) { v, err := func(r wrpc.IndexReader, path ...uint32) (*wrpc__http__types.Response, error) { v := &wrpc__http__types.Response{} var err error slog.Debug("reading field", "name", "body") v.Body, err = func(r wrpc.IndexReader, path ...uint32) (wrpc.ReadCompleter, error) { slog.Debug("reading byte stream status byte") status, err := r.ReadByte() if err != nil { return nil, fmt.Errorf("failed to read byte stream status byte: %w", err) } switch status { case 0: if len(path) > 0 { r, err = r.Index(path...) if err != nil { return nil, fmt.Errorf("failed to index reader: %w", err) } } return wrpc.NewByteStreamReader(wrpc.NewPendingByteReader(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 { r, err = r.Index(path...) if err != nil { return nil, fmt.Errorf("failed to index reader: %w", err) } } return wrpc.NewDecodeReceiver(r, func(r wrpc.IndexReader) ([]*wrpc.Tuple2[string, [][]uint8], error) { slog.Debug("reading pending future element") 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") } 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)< 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") } 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)< 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") } 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)< 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") } 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)< 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 } 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") } 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)< 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") } 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)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } return x, fmt.Errorf("failed to read u8 discriminant byte: %w", err) } if s == 7 && b > 0x01 { return x, errors.New("discriminant overflows an 8-bit integer") } if b < 0x80 { return x | uint8(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)< 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 } 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)< 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 } return x, fmt.Errorf("failed to read u32 byte: %w", err) } if s == 28 && b > 0x0f { return x, errors.New("varint overflows a 32-bit integer") } if b < 0x80 { return 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)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } return x, fmt.Errorf("failed to read u32 byte: %w", err) } if s == 28 && b > 0x0f { return x, errors.New("varint overflows a 32-bit integer") } if b < 0x80 { return x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } return x, fmt.Errorf("failed to read u32 byte: %w", err) } if s == 28 && b > 0x0f { return x, errors.New("varint overflows a 32-bit integer") } if b < 0x80 { return 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)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } return x, fmt.Errorf("failed to read u32 byte: %w", err) } if s == 28 && b > 0x0f { return x, errors.New("varint overflows a 32-bit integer") } if b < 0x80 { return x | uint32(b)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } return x, fmt.Errorf("failed to read u32 byte: %w", err) } if s == 28 && b > 0x0f { return x, errors.New("varint overflows a 32-bit integer") } if b < 0x80 { return 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)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } return x, fmt.Errorf("failed to read u32 byte: %w", err) } if s == 28 && b > 0x0f { return x, errors.New("varint overflows a 32-bit integer") } if b < 0x80 { return x | uint32(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 } return x, fmt.Errorf("failed to read u32 byte: %w", err) } if s == 28 && b > 0x0f { return x, errors.New("varint overflows a 32-bit integer") } if b < 0x80 { return 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)< 0 && err == io.EOF { err = io.ErrUnexpectedEOF } return x, fmt.Errorf("failed to read u32 byte: %w", err) } if s == 28 && b > 0x0f { return x, errors.New("varint overflows a 32-bit integer") } if b < 0x80 { return 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)< 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)< 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)<