utils

package
v0.0.0-...-c9d2d86 Latest Latest
Warning

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

Go to latest
Published: May 25, 2018 License: ISC Imports: 18 Imported by: 0

Documentation

Overview

Copyright (C) 2017, Zipper Team. All rights reserved.

This file is part of zipper

The zipper is free software: you can use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

The zipper is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ISC License for more details.

You should have received a copy of the ISC License along with this program. If not, see <https://opensource.org/licenses/isc>.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNonString = errors.New("cannot unmarshal non-string as hex data")
	ErrOddLength = errors.New("hex string has odd length")
	ErrSyntax    = errors.New("invalid hex")
)

Functions

func AppDataDir

func AppDataDir(appName string, roaming bool) string

AppDataDir returns a default data directory for the databases

func AssertEquals

func AssertEquals(t testing.TB, actual interface{}, expected interface{})

func AssertNotEquals

func AssertNotEquals(t testing.TB, actual interface{}, expected interface{})

func AssertSame

func AssertSame(t testing.TB, actual interface{}, expected interface{})

func ByteToFloat64

func ByteToFloat64(src []byte) float64

func BytesToHex

func BytesToHex(byteSlice []byte) string

func BytesToUint32

func BytesToUint32(src []byte) uint32

func BytesToUint32Arrary

func BytesToUint32Arrary(src []byte) []uint32

func CheckInt64Border

func CheckInt64Border(x, y int64) bool

func Contain

func Contain(obj interface{}, target interface{}) bool

func CurrentTimestamp

func CurrentTimestamp() uint32

func DecodeUint32

func DecodeUint32(bytes []byte, cnt uint32) ([]uint32, error)

func DelStringFromSlice

func DelStringFromSlice(val string, slice *[]string)

func Deserialize

func Deserialize(data []byte, obj interface{}) error

Deserialize deserializes bytes to object

func FileExist

func FileExist(filePath string) bool

FileExist determines whether a file exists

func Float64ToByte

func Float64ToByte(src float64) []byte

func HexToBytes

func HexToBytes(s string) []byte

func IsDirEmpty

func IsDirEmpty(path string) (bool, error)

IsDirEmpty determines whether a directory is empty

func IsDirExist

func IsDirExist(path string) (bool, error)

IsDirExist determines whether a directory exists

func IsDirMissingOrEmpty

func IsDirMissingOrEmpty(path string) (bool, error)

IsDirMissingOrEmpty determines whether a directory is empty or missing

func MinimizeSilce

func MinimizeSilce(src []byte) []byte

func OpenDir

func OpenDir(dir string) (string, error)

OpenDir opens or creates a dir If the dir already exists, open it . If it does not, It will create the file with mode 0700.

func OpenFile

func OpenFile(path string) (*os.File, error)

OpenFile opens or creates a file If the file already exists, open it . If it does not, It will create the file with mode 0644.

func ReadVarInt

func ReadVarInt(r io.Reader) (uint64, error)

ReadVarInt decodes varint and returns real length

func Serialize

func Serialize(obj interface{}) []byte

Serialize serializes an object to bytes

func Uint32ArrayToBytes

func Uint32ArrayToBytes(arrary []uint32) []byte

func Uint32ToBytes

func Uint32ToBytes(src uint32) []byte

func UnmarshalFixedText

func UnmarshalFixedText(input, out []byte) error

UnmarshalFixedText decodes the input as a string with 0x prefix. The length of out determines the required input length. This function is commonly used to implement the UnmarshalText method for fixed-size types.

func VarDecode

func VarDecode(r io.Reader, val interface{}) error

VarDecode decodes the data to val, val mustbe pointer

func VarEncode

func VarEncode(w io.Writer, val interface{})

VarEncode encodes the input data TODO: val support all types

func VarInt

func VarInt(n uint64) []byte

VarInt converts n to varint bytes the raw protocol: https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer

func WriteVarInt

func WriteVarInt(w io.Writer, count uint64)

WriteVarInt writes varint bytes to stream

func ZeroMemory

func ZeroMemory(s interface{})

ZeroMemory erases a slice memory

Types

type Bytes

type Bytes []byte

Bytes marshals/unmarshals as a JSON string .

func (Bytes) MarshalText

func (b Bytes) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (*Bytes) UnmarshalJSON

func (b *Bytes) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Bytes) UnmarshalText

func (b *Bytes) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Times

type Times []uint32

func (Times) Len

func (t Times) Len() int

func (Times) Less

func (t Times) Less(i, j int) bool

func (Times) Swap

func (t Times) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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