bytestruct

package module
v0.0.0-...-64d4f3c Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: MIT Imports: 5 Imported by: 0

README

ByteStructGO: A Go library for reading and writing binary data using go structures

🚧 This is not production ready 🚧

ByteStructGO is a Go library that simplifies the reading and writing of binary data. It allows you to define the structure of your data using tags, and then automatically handles the encoding and decoding of bytes. ByteStructGO supports both little-endian and big-endian byte orders.

Features

  • Easy to use: just define your data structure using tags, and let ByteStructGO do the rest.
  • Nested Structure: ByteStructGO can decode nessted and array structs

Missing

  • cant handle array of strings

Install

go get github.com/cowboymacke/ByteStructGO

Usage

To use ByteStructGO, you need to import the package and define your data structure using tags.

package main

import (
	"bytes"
	"encoding/binary"
	"fmt"

	structGo "github.com/cowboymacke/ByteStructGO"
)

// Define the message structure
type Message struct {
	Length  uint16 
	Payload string `byteSize:"Length"`
}

func main() {

	reader := bytes.NewBuffer([]byte{0, 11, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100})

	var message Message
	err := structGo.Unmarshal(reader, binary.BigEndian, &message)
	if err != nil {
		fmt.Printf("Failed to Unmarshal: %s", err.Error())
		return
	}

	fmt.Printf("Payload: %s", message.Payload) // -> Payload: Hello World

}

Examples

You can find more examples of using ByteStructGO in the examples folder.

Feedback

If you have any questions, suggestions, or issues, please feel free to open an issue or submit a pull request.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(order binary.ByteOrder, v interface{}) ([]byte, error)

func Unmarshal

func Unmarshal(reader io.Reader, order binary.ByteOrder, v interface{}) error

Types

This section is empty.

Directories

Path Synopsis
examples
Marshal command
Unmarshal command

Jump to

Keyboard shortcuts

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