bytecodealliance / bytecodealliance/go-pkg

Feature: Make streams implement the existing Go io interfaces.

Open
#9 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
0
Forks
5
Avg merge
1h 24m
Merged PRs (30d)
2

Description

# Description
In order to make bindings more Go idiomatic we should make streams implement the `io.Reader`, `io.Writer` and `io.Closer` interfaces. This would enable more seamless integration with existing Go functions.

### Example

For the following wit type `stream` the types should implement the following:

```go
// StreamReader implements io.ReadCloser
var _ io.ReadCloser = (*witTypes.StreamReader[uint8])(nil)

// io.ReadCloser
type ReadCloser interface {
Read(p []byte) (n int, err error)
Close() error
}

// StreamWriter implements io.WriteCloser
var _ io.WriteCloser = (*witTypes.StreamWriter[uint8])(nil)

// io.WriteCloser
type WriteCloser interface {
Write(p []byte) (n int, err error)
Close() error
}
```

This would allow you to for example, encode json straight onto the stream:
```go
// Create stream
tx, rx := foo.MakeStreamU8()

// Encode json
err := son.NewEncoder(tx).Encode(map[string]string{
"foo": "bar",
})
...
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.