converter

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0 Imports: 17 Imported by: 3

Documentation

Index

Constants

View Source
const (
	BlackHoleAddr = "BlackHole"
	WhiteHoleAddr = "WhiteHole"
)

Variables

View Source
var ErrSliceSize = errors.New("Slice size larger than buffer size")
View Source
var FirstEcosystemTables = map[string]bool{
	`keys`:               true,
	`menu`:               true,
	`pages`:              true,
	`snippets`:           true,
	`languages`:          true,
	`contracts`:          true,
	`tables`:             true,
	`parameters`:         true,
	`history`:            true,
	`sections`:           true,
	`members`:            true,
	`roles`:              true,
	`roles_participants`: true,
	`notifications`:      true,
	`applications`:       true,
	`binaries`:           true,
	`buffer_data`:        true,
	`app_params`:         true,
	`views`:              true,
}
View Source
var (
	HoleAddrMap = map[string]Hole{
		BlackHoleAddr: {K: 0, S: "0000-0000-0000-0000-0000"},
		WhiteHoleAddr: {K: 5555, S: "0000-0000-0000-0000-5555"},
	}
)

Functions

func AddressToID

func AddressToID(input string) (addr int64)

AddressToID converts the string representation of the wallet number to a numeric

func AddressToString

func AddressToString(int int64) (str string)

AddressToString converts int64 address to chain address as xxxx-xxxx-xxxx-xxxx-xxxx.

func AddressToStringUint64

func AddressToStringUint64(uint uint64) (str string)

func BinMarshal

func BinMarshal(out *[]byte, v any) (*[]byte, error)

BinMarshal converts v parameter to []byte slice.

func BinToDec

func BinToDec(bin []byte) int64

BinToDec converts input binary []byte to int64

func BinToDecBytesShift

func BinToDecBytesShift(bin *[]byte, num int64) int64

BinToDecBytesShift converts the input binary []byte to int64 and shifts the input bin

func BinToHex

func BinToHex(v any) []byte

BinToHex converts interface to hex []byte

func BinUnmarshal

func BinUnmarshal(out *[]byte, v any) error

BinUnmarshal converts []byte slice which has been made with BinMarshal to v

func BinUnmarshalBuff

func BinUnmarshalBuff(buf *bytes.Buffer, v any) error

func BytesShift

func BytesShift(str *[]byte, index int64) (ret []byte)

BytesShift returns the index bytes of the input []byte and shift str pointer

func BytesShiftReverse

func BytesShiftReverse(str *[]byte, v any) []byte

BytesShiftReverse gets []byte from the end of the input and cut the input pointer to []byte

func BytesToFloat64

func BytesToFloat64(s []byte) float64

BytesToFloat64 converts []byte to float64

func BytesToInt

func BytesToInt(s []byte) int

BytesToInt converts []byte to integer

func BytesToInt64

func BytesToInt64(s []byte) int64

BytesToInt64 converts []bytes to int64

func CheckSum

func CheckSum(val []byte) int

CheckSum calculates the 0-9 check sum of []byte

func DecToBin

func DecToBin(v any, sizeBytes int64) []byte

DecToBin converts interface to []byte

func DecodeBytesBuf

func DecodeBytesBuf(buf *bytes.Buffer) ([]byte, error)

func DecodeLenInt64

func DecodeLenInt64(data *[]byte) (int64, error)

DecodeLenInt64 gets int64 from []byte and shift the slice. The []byte should be encoded with EncodeLengthPlusInt64.

func DecodeLenInt64Buf

func DecodeLenInt64Buf(buf *bytes.Buffer) (int64, error)

func DecodeLength

func DecodeLength(buf *[]byte) (ret int64, err error)

DecodeLength decodes []byte to int64 and shifts buf. Bytes must be encoded with EncodeLength function.

0x43 => 67
0x820400 => 1024
0x830f4240 => 1000000

func DecodeLengthBuf

func DecodeLengthBuf(buf *bytes.Buffer) (int, error)

func EncodeLenByte

func EncodeLenByte(out *[]byte, buf []byte) *[]byte

func EncodeLenInt64

func EncodeLenInt64(data *[]byte, x int64) *[]byte

func EncodeLenInt64InPlace

func EncodeLenInt64InPlace(x int64) []byte

func EncodeLength

func EncodeLength(length int64) []byte

EncodeLength encodes int64 number to []byte. If it is less than 128 then it returns []byte{length}. Otherwise, it returns (0x80 | len of int64) + int64 as BigEndian []byte

67 => 0x43
1024 => 0x820400
1000000 => 0x830f4240

func EncodeLengthPlusData

func EncodeLengthPlusData(idata any) []byte

EncodeLengthPlusData encoding interface into []byte

func Escape

func Escape(data string) string

Escape deletes unaccessable characters

func EscapeForJSON

func EscapeForJSON(data string) string

EscapeForJSON replaces quote to slash and quote

func EscapeName

func EscapeName(name string) string

EscapeName deletes unaccessable characters for input name(s)

func EscapeSQL

func EscapeSQL(name string) string

func FieldToBytes

func FieldToBytes(v any, num int) []byte

FieldToBytes returns the value of n-th field of v as []byte

func Float64ToStr

func Float64ToStr(f float64) string

Float64ToStr converts float64 to string

func FormatMoney

func FormatMoney(exp string, digit int32) (string, error)

FormatMoney converts minimal unit to legibility unit. For example, value * 10 ^ -digit

func HexToBin

func HexToBin(ihexdata any) []byte

HexToBin converts hex interface to binary []byte

func IDToAddress

func IDToAddress(id int64) (out string)

IDToAddress converts the identifier of account to a string of the form xxxx-xxxx-xxxx-xxxx-xxxx.

func InSliceString

func InSliceString(search string, slice []string) bool

InSliceString searches the string in the slice of strings

func Int64ToByte

func Int64ToByte(num int64) []byte

Int64ToByte converts int64 to []byte

func Int64ToDateStr

func Int64ToDateStr(date int64, format string) string

func Int64ToStr

func Int64ToStr(num int64) string

Int64ToStr converts int64 to string

func Int64Toint

func Int64Toint(dat int64) (int, error)

func IntToStr

func IntToStr(num int) string

IntToStr converts integer to string

func InterfaceSliceToStr

func InterfaceSliceToStr(i []any) (strs []string, err error)

InterfaceSliceToStr converts the slice of interfaces to the slice of strings

func InterfaceToFloat64

func InterfaceToFloat64(i any) float64

InterfaceToFloat64 converts the interfaces to the float64

func InterfaceToStr

func InterfaceToStr(v any) (string, error)

InterfaceToStr converts the interfaces to the string

func IsLatin

func IsLatin(name string) bool

IsLatin checks if the specified string contains only latin character, digits and '-', '_'.

func IsValidAddress

func IsValidAddress(address string) bool

IsValidAddress checks if the specified address is chain address.

func MarshalJson

func MarshalJson(v any) string

func NumString

func NumString(in string) string

NumString insert spaces between each three digits. 7123456 => 7 123 456

func ParseName

func ParseName(in string) (id int64, name string)

ParseName gets a state identifier and the name of the contract or table from the full name like @[id]name

func ParseTable

func ParseTable(tblname string, defaultEcosystem int64) string

ParseTable return format 1:@[id]tblname -> parse id_tblname format 2:[defaultEcosystem]_tblname

func RSortMap

func RSortMap(m map[int64]string) []map[int64]string

RSortMap sorts map to the reversed slice of maps

func Round

func Round(num float64) int64

func RoundWithPrecision

func RoundWithPrecision(num float64, precision int) float64

RoundWithPrecision rounds float64 value

func RoundWithoutPrecision

func RoundWithoutPrecision(num float64) int64

RoundWithoutPrecision is round float64 without precision

func Sanitize

func Sanitize(name string, available string) string

Sanitize deletes unaccessable characters from input string

func SanitizeName

func SanitizeName(input string) string

SanitizeName deletes unaccessable characters from name string

func SanitizeNumber

func SanitizeNumber(input string) string

SanitizeNumber deletes unaccessable characters from number or name string

func SanitizeScript

func SanitizeScript(input string) string

SanitizeScript deletes unaccessable characters from input string

func SliceReverse

func SliceReverse(s []int64) []int64

SliceReverse reverses the slice of int64

func SortMap

func SortMap(m map[int64]string) []map[int64]string

SortMap sorts map to the slice of maps

func StrToFloat64

func StrToFloat64(s string) float64

StrToFloat64 converts string to float64

func StrToInt

func StrToInt(s string) int

StrToInt converts string to integer

func StrToInt64

func StrToInt64(s string) int64

StrToInt64 converts string to int64

func StrToMoney

func StrToMoney(str string) float64

StrToMoney rounds money string to float64

func StrToUint64

func StrToUint64(s string) uint64

StrToUint64 converts string to the unsinged int64

func StringToAddress

func StringToAddress(str string) (result int64)

StringToAddress converts string chain address to int64 address. The input address can be a positive or negative number, or chain address in xxxx-xxxx-xxxx-xxxx-xxxx format. Returns 0 when error occurs.

func StripTags

func StripTags(value string) string

StripTags replaces < and > to &lt; and &gt;

func SubNodeParseTable

func SubNodeParseTable(tblname string, defaultEcosystem int64) string

func UInt32ToStr

func UInt32ToStr(num uint32) string

UInt32ToStr converts uint32 to string

func ValidateEmail

func ValidateEmail(email string) bool

ValidateEmail validates email

func ValueToDecimal

func ValueToDecimal(v any) (ret decimal.Decimal, err error)

func ValueToInt

func ValueToInt(v any) (ret int64, err error)

ValueToInt converts interface (string or int64) to int64

Types

type Hole

type Hole struct {
	K int64
	S string
}

Jump to

Keyboard shortcuts

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