util

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2017 License: ISC Imports: 8 Imported by: 8

Documentation

Index

Constants

View Source
const Varint64MaximumBytes = 9

maximum possible number of bytes in Varint64

Variables

This section is empty.

Functions

func CopyVarint64

func CopyVarint64(buffer []byte) []byte

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

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

check if file exists

func FormatBytes added in v0.2.0

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

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)

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

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
}

type to hold an IP and Port

func ConnectionFromIPandPort added in v0.2.0

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

convert an IP and port to a connection

func NewConnection added in v0.2.0

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

decode a connection string into an IP and Port

func NewConnections added in v0.2.0

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

convert an array of connections

func (*Connection) CanonicalIPandPort added in v0.2.0

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

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)

convert to text for JSON

func (*Connection) Pack added in v0.2.0

func (conn *Connection) Pack() PackedConnection

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

type for packed byte buffer IP and Port

func (PackedConnection) Unpack added in v0.2.0

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

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

Jump to

Keyboard shortcuts

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