muss

package module
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2025 License: MIT Imports: 1 Imported by: 21

README

mus-stream-go

Go Reference GoReportCard codecov

mus-stream-go offers a streaming version of mus-go, keeping the same structure but using Writer and Reader interfaces instead of byte slices.

How To

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:

  1. They implement the muss.Writer and muss.Reader interfaces.
  2. They provide the necessary buffering for efficient I/O operations.

DTS (Data Type metadata Support)

mus-stream-dts-go enables typed data serialization using DTM.

MarshallerMUS Interface

The MarshallerMUS interface is defined in the ext-mus-stream-go module.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader interface {
	io.ByteReader
	io.Reader
}

Reader is the interface that groups the basic ReadByte and Read methods.

type Serializer added in v0.5.0

type Serializer[T any] interface {
	Marshal(t T, w Writer) (n int, err error)
	Unmarshal(r Reader) (t T, n int, err error)
	Size(t T) (size int)
	Skip(r Reader) (n int, err error)
}

Serializer is the interface that groups the Marshal, Unmarshal, Size and Skip methods.

Marshal writes an encoded value, returning the number of bytes written and any error encountered.

Unmarshal reads an encoded value, returning the value, the number of bytes read and any error encountered.

Size returns the number of bytes needed to encode the value.

Skip skips an encoded value, returning the number of skipped bytes and any error encountered.

type Writer

type Writer interface {
	io.ByteWriter
	io.Writer
	io.StringWriter
}

Writer is the interface that groups the WriteByte, Write and WriteString methods.

Directories

Path Synopsis
options
map

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL