// 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__clocks__monotonic_clock "github.com/wrpc/wit-bindgen-wrpc/examples/go/http-outgoing-server/bindings/wasi/clocks/monotonic_clock" wasi__http__types "github.com/wrpc/wit-bindgen-wrpc/examples/go/http-outgoing-server/bindings/wasi/http/types" wrpc__http__types "github.com/wrpc/wit-bindgen-wrpc/examples/go/http-outgoing-server/bindings/wrpc/http/types" wrpc "github.com/wrpc/wrpc/go" io "io" slog "log/slog" sync "sync" atomic "sync/atomic" 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 type Handler interface { Handle(ctx__ context.Context, request *wrpc__http__types.Request, options *RequestOptions) (*wrpc.Result[Response, ErrorCode], error) } func ServeInterface(s wrpc.Server, h Handler) (stop func() error, err error) { stops := make([]func() error, 0, 1) stop = func() error { for _, stop := range stops { if err := stop(); err != nil { return err } } return nil } stop0, err := s.Serve("wrpc:http/outgoing-handler@0.1.0", "handle", func(ctx context.Context, w wrpc.IndexWriter, r wrpc.IndexReadCloser) error { slog.DebugContext(ctx, "reading parameter", "i", 0) p0, err := func() (*Request, error) { v, err := func(r wrpc.IndexReader, path ...uint32) (*wrpc__http__types.Request, error) { v := &wrpc__http__types.Request{} 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 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 "", 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 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 "", 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 "", 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 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 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 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 { var wg sync.WaitGroup var wgErr atomic.Value for index, write := range writes { wg.Add(1) w, err := w.Index(index) if err != nil { return fmt.Errorf("failed to index writer: %w", err) } write := write go func() { defer wg.Done() if err := write(w); err != nil { wgErr.Store(err) } }() } wg.Wait() err := wgErr.Load() if err == nil { return nil } return err.(error) } return nil }, wrpc.NewSubscribePath().Index(0).Index(0), wrpc.NewSubscribePath().Index(0).Index(1)) if err != nil { return nil, fmt.Errorf("failed to serve `wrpc:http/outgoing-handler@0.1.0.handle`: %w", err) } stops = append(stops, stop0) return stop, nil }