byteorder

package module
v0.0.0-...-49066a1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: MIT Imports: 3 Imported by: 0

README

byteorder GoDoc

byteorder is a Go module for working with arbitrarily-ordered byte slices. It is useful e.g. when dealing with Modbus wire formats.

Installation:

go get github.com/andig/byteorder

Usage:

import "github.com/andig/byteorder"

// reverse byte order, i.e. little endian
bo := New("BA")
fmt.Printf("0x%04x", bo.Uint16([]byte{1, 2}))
// Output: 0x0201

NOTE: byteorder is not optimized for performance. The conversion functions will allocate which may not be desirable in high-frequency code paths.

In addition to the Go binary.ByteOrder implementation, this modules provides convenience functions for the ioBroker.modbus data types.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Doublebe

func Doublebe(b []byte) float64

Double (Big Endian): ABCDEFGH

func Doublele

func Doublele(b []byte) float64

Double (Little Endian): HGFEDCBA

func Floatbe

func Floatbe(b []byte) float32

Float (Big Endian): ABCD

func Floatle

func Floatle(b []byte) float32

Float (Little Endian): DCBA

func Floatsb

func Floatsb(b []byte) float32

Float (Big Endian Swap Byte): DCBA

func Floatsw

func Floatsw(b []byte) float32

Float (Big Endian Swap Word): CDAB

func New

func New(order string) binary.ByteOrder

New creates a new binary.ByteOrder with the order of bytes given as a string ("ABCD")

Example
// reverse byte order, i.e. little endian
bo := New("BA")
fmt.Printf("0x%04x", bo.Uint16([]byte{1, 2}))
Output:

0x0201

func Uint16be

func Uint16be(b []byte) uint16

Unsigned 16 bit (Big Endian): AB

func Uint16le

func Uint16le(b []byte) uint16

Unsigned 16 bit (Little Endian): BA

func Uint32be

func Uint32be(b []byte) uint32

Unsigned 32 bit (Big Endian): ABCD

func Uint32le

func Uint32le(b []byte) uint32

Unsigned 32 bit (Little Endian): DCBA

func Uint32sb

func Uint32sb(b []byte) uint32

Unsigned 32 bit (Big Endian Swap Byte): DCBA

func Uint32sw

func Uint32sw(b []byte) uint32

Unsigned 32 bit (Big Endian Swap Word): CDAB

func Uint64be

func Uint64be(b []byte) uint64

Unsigned 64 bit (Big Endian): ABCDEFGH

func Uint64le

func Uint64le(b []byte) uint64

Unsigned 64 bit (Little Endian): HGFEDCBA

func Uint64sb

func Uint64sb(b []byte) uint64

Unsigned 64 bit (Big Endian Swap Byte): HGFEDCBA

func Uint64sw

func Uint64sw(b []byte) uint64

Unsigned 64 bit (Big Endian Swap Word): GHEFCDAB

Types

This section is empty.

Jump to

Keyboard shortcuts

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