util

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package util provides utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSerialNumberForAccessoryName

func GetSerialNumberForAccessoryName(name string, storage Storage) string

GetSerialNumberForAccessoryName returns the serial for a specific name stored in storage. When no serial number is stored for this name yet, a new one is created using RandomHexString()

func MAC48Address

func MAC48Address(input string) string

MAC48Address returns a MAC-48-like address from the argument string

func RandomHexString

func RandomHexString() string

RandomHexString returns a random hex string.

func RemoveAccentsFromString

func RemoveAccentsFromString(v string) string

RemoveAccentsFromString removes accent characters from string From https://stackoverflow.com/a/40405242/424814

func XHMURI

func XHMURI(pincode, setupId string, categoryId uint8, flags []SetupFlag) (string, error)

Types

type Container

type Container interface {

	// SetByte sets one byte for a key
	SetByte(key, value byte)

	// SetBytes sets bytes for a key
	SetBytes(key byte, value []byte)

	// SetString sets a string for a key
	SetString(key byte, value string)

	// GetByte returns one byte for a key
	GetByte(key byte) byte

	// GetBytes returns bytes for a key
	GetBytes(key byte) []byte

	// GetString return a string for a key
	GetString(key byte) string

	// BytesBuffer returns the raw bytes
	BytesBuffer() *bytes.Buffer
}

Container is a dictionary using byte keys and values.

func NewTLV8Container

func NewTLV8Container() Container

NewTLV8Container returns a type-length-value container which implements the Container interface. Packets which value exceed a length of 8 bit (255) will be split up in multiple packets.

Learn more https://en.wikipedia.org/wiki/Type-length-value

func NewTLV8ContainerFromReader

func NewTLV8ContainerFromReader(r io.Reader) (Container, error)

NewTLV8ContainerFromReader returns a tlv8 container from a bytes buffer.

type SetupFlag

type SetupFlag uint8
var SetupFlagBTLE SetupFlag = 4
var SetupFlagIP SetupFlag = 2
var SetupFlagIPWAC SetupFlag = 8
var SetupFlagNFC SetupFlag = 1
var SetupFlagNone SetupFlag = 0

type Storage

type Storage interface {
	// Set sets bytes for a key
	Set(key string, value []byte) error

	// Delete removes bytes for a key
	Delete(key string) error

	// Get returns bytes for a key
	Get(key string) ([]byte, error)

	// KeysWithSuffix returns all keys with a specific suffix
	KeysWithSuffix(suffix string) ([]string, error)
}

Storage stores bytes for a key.

func NewFileStorage

func NewFileStorage(dir string) (Storage, error)

NewFileStorage create a file storage for the specified directory. The folder is created if necessary. Every key-value pair is stored in a separate file.

func NewTempFileStorage

func NewTempFileStorage() (Storage, error)

NewTempFileStorage returns a new storage inside temporary folder.

Jump to

Keyboard shortcuts

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