mus-stream-go offers a streaming version of the mus-go
serializer, keeping the same structure but using Writer and Reader
interfaces instead of byte slices.
More information can be found in the mus-go documentation.
Here is just a small example:
package main
import "github.com/mus-format/mus-go/varint"
func main() {
var (
num = 100
size = varint.Int.Size(num)
bs = make([]byte, size)
buf = bytes.NewBuffer(bs) // Create a Writer/Reader.
)
n, err := varint.Int.Marshal(num, buf)
// ...
num, n, err = varint.Int.Unmarshal(buf)
// ...
}When working with real connections (e.g., network or file I/O) rather than
bytes.Buffer, you must use bufio.Writer and bufio.Reader. This is
required because:
- They implement the
muss.Writerandmuss.Readerinterfaces. - They provide the necessary buffering for efficient I/O operations.
dts-stream-go enables typed data serialization using DTM.
The MarshallerMUS interface is defined in the ext-stream-go
module.