gostruct

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

README

 ____            ____    __                           __      
/\  _`\         /\  _`\ /\ \__                       /\ \__   
\ \ \L\_\    ___\ \,\L\_\ \ ,_\  _ __   __  __    ___\ \ ,_\  
 \ \ \L_L   / __`\/_\__ \\ \ \/ /\`'__\/\ \/\ \  /'___\ \ \/  
  \ \ \/, \/\ \L\ \/\ \L\ \ \ \_\ \ \/ \ \ \_\ \/\ \__/\ \ \_ 
   \ \____/\ \____/\ `\____\ \__\\ \_\  \ \____/\ \____\\ \__\
    \/___/  \/___/  \/_____/\/__/ \/_/   \/___/  \/____/ \/__/

A go implementation of Python's Struct module
GitHub License GitHub tag (with filter) CodeFactor GitHub code size in bytes

Installation

go get github.com/ItzAfroBoy/gostruct@latest

Example

package main

import (
    "fmt"
    "github.com/ItzAfroBoy/gostruct"
)

type Data struct {
    A int32
    B int32
    C float32
    D float32
    E uint8
    F uint32
}

func main() {
    byteStream := receive() // Data to unpack
    packet := Data{}
    gostruct.UnpackToStruct("<iiffBI", byteStream, &packet)
    fmt.Println(packet)
}

Documentation

Overview

A go implementation of Python's Struct module

Example
package main

import (
	"fmt"
	"github.com/ItzAfroBoy/gostruct"
)

type Data struct {
	A int32
	B int32
	C float32
	D float32
	E uint8
	F uint32
}

func main() {
	byteStream := receive() // Data to unpack
	packet := Data{}
	gostruct.UnpackToStruct("<iiffBI", byteStream, &packet)
	fmt.Println(packet)
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unpack

func Unpack(format string, buffer []byte) []any

Unpack buffer using format string. Returns array containing parsed data

func UnpackToStruct

func UnpackToStruct(format string, buffer []byte, v any)

Unpack buffer using format string. Populates v using reflect. Buffer contents must match amount of struct fields

Types

This section is empty.

Jump to

Keyboard shortcuts

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