Skip to content

This is a very simple binary library written in Go.

License

Notifications You must be signed in to change notification settings

beito123/binary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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())
}