encoding

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package encoding provides utilities to marshal and unmarshal some values to and from a binary stream suitable for the pesit protocol.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidConversion = errors.New("invalid conversion")

ErrInvalidConversion is the error returned when the slice to marshal has an invalid length.

Functions

func MarshalUint16

func MarshalUint16(number uint16) ([]byte, error)

MarshalUint16 serializes a unint16 number to a byte slice. The most significant byte is the first byte. If the first byte value is 0, it is removed (i.e. the byte slice have length 1).

The return value error is always nil.

func MarshalUint24

func MarshalUint24(number uint32) ([]byte, error)

MarshalUint24 serializes a unint number to a byte slice. The most significant byte is the first byte. If the first byte value is 0, it is removed (i.e. the byte slice have length 1).

The return value error is always nil.

func MarshalUint32

func MarshalUint32(number uint32) ([]byte, error)

MarshalUint32 serializes a unint number to a byte slice. The most significant byte is the first byte. If the first byte value is 0, it is removed (i.e. the byte slice have length 1).

The return value error is always nil.

func MarshalUint64

func MarshalUint64(number uint64) ([]byte, error)

MarshalUint64 serializes a unint number to a byte slice. The most significant byte is the first byte. If the first byte value is 0, it is removed (i.e. the byte slice have length 1).

The return value error is always nil.

func UnmarshalUint16

func UnmarshalUint16(bytes []byte) (uint16, error)

UnmarshalUint16 reads a byte slice in a uint16 number. The slice must contain 1 or 2 bytes, the most significant byte being the first byte. It returns an error if the slice has the wrong length.

func UnmarshalUint24

func UnmarshalUint24(bytes []byte) (uint32, error)

UnmarshalUint24 reads a byte slice in a uint number. The slice must contain 1, 2 or 3 bytes, the most significant byte being the first byte. It returns an error if the slice has the wrong length.

func UnmarshalUint32

func UnmarshalUint32(bytes []byte) (uint32, error)

UnmarshalUint32 reads a byte slice in a uint number. The slice must contain 1, 2, 3 or 4 bytes, the most significant byte being the first byte. It returns an error if the slice has the wrong length.

func UnmarshalUint64

func UnmarshalUint64(bytes []byte) (uint64, error)

UnmarshalUint64 reads a byte slice in a uint number. The slice must contain up to 8 bytes, the most significant byte being the first byte. It returns an error if the slice has the wrong length.

Types

This section is empty.

Source Files

  • doc.go
  • uint.go
  • uint16.go
  • uint24.go
  • uint32.go
  • uint64.go

Jump to

Keyboard shortcuts

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