Thanks to visit codestin.com
Credit goes to github.com

Skip to content

introduce 'byte' tag into struct for mapping up struct for the ability to unmarshal arrays

License

Notifications You must be signed in to change notification settings

cowboymacke/ByteStructGO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

introduce 'byte' tag into struct for mapping up struct for the ability to unmarshal arrays

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages