bytecodealliance / bytecodealliance/go-pkg
Feature: Make streams implement the existing Go io interfaces.
- 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
Assessment
This issue has not been assessed yet.