binngo

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: MIT Imports: 2 Imported by: 2

README

BinnGo

Go Reference GitHub go.mod Go version Go Report Card test Code Coverage Scrutinizer Code Quality

Binary serializer. Implements easy to use encoding and decoding of Binn. This package is very similar to the standard go encoder packages like encoding/json. BinnGo uses reflection.

Original C Binn Library: https://github.com/liteserver/binn

Binn Specification: https://github.com/liteserver/binn/blob/master/spec.md

Work In Progress notification

This package in under development. Encoding and decoding complex and nested structures may not work as expected.

Installation

Run the following command to install the package:

go get -u github.com/et-nik/binngo

How To Use

Reading Binn data
package main

import (
	"fmt"
	"github.com/et-nik/binngo"
)

func main() {
	binnBinary := []byte{
		0xE0,                          // [type] list (container)
		23,                            // [size] container total size
		0x02,                          // [count] items
		0xA0,                          // [type] = string
		0x05,                          // [size]
		'h', 'e', 'l', 'l', 'o', 0x00, // [data] (null terminated)
		0xA0,                          // [type] = string
		0x05,                          // [size]
		'w', 'o', 'r', 'l', 'd', 0x00, // [data] (null terminated)
	}
	items := []string{}

	err := binngo.Unmarshal(binnBinary, &items)
	if err != nil {
		fmt.Println("error:", err)
	}

	fmt.Printf("%+v", items)
}
Writing Binn data
package main

import (
	"fmt"
	"io/ioutil"
	"github.com/et-nik/binngo"
)

func main() {
	structure := struct {
		Val1 int64
		Val2 string
	}{
		123,
		"value",
	}

	binnBinary, err := binngo.Marshal(structure)
	if err != nil {
		fmt.Println("error:", err)
	}

	err = ioutil.WriteFile("/path/to/binfile", binnBinary, 0644)
	if err != nil {
		fmt.Println("error:", err)
	}
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Types

This section is empty.

Directories

Path Synopsis
Package binn contains basic BINN format information and structure constants.
Package binn contains basic BINN format information and structure constants.
Package decode implements BINN decoding.
Package decode implements BINN decoding.
Package encoder implements BINN encoding.
Package encoder implements BINN encoding.

Jump to

Keyboard shortcuts

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