util

package
v0.15.6 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: ISC Imports: 12 Imported by: 5

Documentation

Overview

Package util - miscellaneous small routines

Index

Constants

View Source
const Varint64MaximumBytes = 9

Varint64MaximumBytes - maximum possible number of bytes in Varint64

Variables

This section is empty.

Functions

func ClippedVarint64 added in v0.8.0

func ClippedVarint64(buffer []byte, minimum int, maximum int) (int, int)

ClippedVarint64 - return a positive clipped value as an int any value outside the range minimum..maximum is an error

func CopyVarint64

func CopyVarint64(buffer []byte) []byte

CopyVarint64 - make a copy of a Varint64 from the beginning of a buffer

func EnsureAbsolute added in v0.2.0

func EnsureAbsolute(directory string, filePath string) string

EnsureAbsolute - ensure the path is absolute if not, prepend the directory to make absolute path

func EnsureFileExists added in v0.2.0

func EnsureFileExists(name string) bool

EnsureFileExists - check if file exists

func FetchJSON added in v0.4.12

func FetchJSON(client *http.Client, url string, reply interface{}) error

FetchJSON - fetch a JSON response from an HTTP request and decode it

func FormatBytes added in v0.2.0

func FormatBytes(name string, data []byte) string

FormatBytes - for dumping the expected hex used by some test routines

func FromBase58

func FromBase58(b string) []byte

FromBase58 decodes a modified base58 string to a byte slice.

func FromVarint64

func FromVarint64(buffer []byte) (uint64, int)

FromVarint64 - convert an array of up to Varint64MaximumBytes to a uint64

also return the number of bytes used as second value returns 0, 0 if varint64 buffer is truncated

func ToBase58

func ToBase58(b []byte) string

ToBase58 encodes a byte slice to a modified base58 string.

func ToVarint64

func ToVarint64(value uint64) []byte

ToVarint64 - convert a 64 bit unsigned integer to Varint64

Structure of the result byte 1: ext | B06 | B05 | B04 | B03 | B02 | B01 | B00 byte 2: ext | B13 | B12 | B11 | B10 | B09 | B08 | B07 byte 3: ext | B20 | B19 | B18 | B17 | B16 | B15 | B14 byte 4: ext | B27 | B26 | B25 | B24 | B23 | B22 | B21 byte 5: ext | B34 | B33 | B32 | B31 | B30 | B29 | B28 byte 6: ext | B41 | B40 | B39 | B38 | B37 | B36 | B35 byte 7: ext | B48 | B47 | B46 | B45 | B44 | B43 | B42 byte 8: ext | B55 | B54 | B53 | B52 | B51 | B50 | B49 byte 9: B63 | B62 | B61 | B60 | B59 | B58 | B57 | B56

Types

type Connection added in v0.2.0

type Connection struct {
	// contains filtered or unexported fields
}

Connection - type to hold an IP and Port

func ConnectionFromIPandPort added in v0.2.0

func ConnectionFromIPandPort(ip net.IP, port uint16) *Connection

ConnectionFromIPandPort - convert an IP and port to a connection

func NewConnection added in v0.2.0

func NewConnection(hostPort string) (*Connection, error)

NewConnection - create a connection from an Host:Port string

func NewConnections added in v0.2.0

func NewConnections(hostPort []string) ([]*Connection, error)

NewConnections - convert an array of connections

func (*Connection) CanonicalIPandPort added in v0.2.0

func (conn *Connection) CanonicalIPandPort(prefix string) (string, bool)

CanonicalIPandPort - make the IP:Port into canonical string

examples:

IPv4:  127.0.0.1:1234
IPv6:  [::1]:1234

prefix is optional and can be empty ("") returns prefixed string and IPv6 flag

func (Connection) MarshalText added in v0.2.0

func (conn Connection) MarshalText() ([]byte, error)

MarshalText - convert to text for JSON

func (*Connection) Pack added in v0.2.0

func (conn *Connection) Pack() PackedConnection

Pack - pack an IP and Port into a byte buffer

func (Connection) String added in v0.2.0

func (conn Connection) String() string

basic string conversion

type PackedConnection added in v0.2.0

type PackedConnection []byte

PackedConnection - type for packed byte buffer IP and Port

func (PackedConnection) Unpack added in v0.2.0

func (packed PackedConnection) Unpack() (*Connection, int)

Unpack - unpack a byte buffer into an IP and Port returns nil if unpack fails if successful returns connection and number of bytes used so an array can be unpacked more easily

func (PackedConnection) Unpack46 added in v0.8.1

func (packed PackedConnection) Unpack46() (*Connection, *Connection)

Unpack46 - unpack first IPv4 and first IPv6 plus Port

Jump to

Keyboard shortcuts

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