Skip to content

Feature: Make streams implement the existing Go io interfaces. #9

Description

@jamesstocktonj1

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<u8> the types should implement the following:

// 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:

// Create stream
tx, rx := foo.MakeStreamU8()

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions