beito123 / binary

This is a very simple binary library written in Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Binary

GoDoc

This is a simple binary library written in Go.

Installation

You can get the package with go get command.

go get -u github.com/beito123/binary

-u is a option updating the package

License

These codes are under the MIT License.

Examples

Read

func main() {
	data := []byte{0xff, 0xff, 0xff, 0xff} // = -1 (int32)

	stream := binary.NewStreamBytes(data) // stream with bytes
	
	value, err := stream.Int() // int32
	if err != nil {
		panic(err)
	}

	fmt.Printf("Int32 value: %d", value) // Int value: -1
}

Write

func main() {
	stream := binary.NewStream() // empty bytes

	var value int32 = -1
	
	err := stream.WriteInt(value)
	if err != nil {
		panic(err)
	}

	// Bytes: []byte{0xff, 0xff, 0xff, 0xff}
	fmt.Printf("Bytes: %#v", stream.Bytes())
}

About

This is a very simple binary library written in Go.

License:MIT License


Languages

Language:Go 100.0%