Documentation ¶
Overview ¶
Package std provides interface to StdLib native contract. It implements various useful conversion functions.
Index ¶
- Constants
- func Atoi(s string, base int) int
- func Atoi10(s string) int
- func Base58CheckDecode(b []byte) []byte
- func Base58CheckEncode(b []byte) string
- func Base58Decode(b []byte) []byte
- func Base58Encode(b []byte) string
- func Base64Decode(b []byte) []byte
- func Base64Encode(b []byte) string
- func Deserialize(b []byte) interface{}
- func Itoa(num int, base int) string
- func Itoa10(num int) string
- func JSONDeserialize(data []byte) interface{}
- func JSONSerialize(item interface{}) []byte
- func MemoryCompare(s1, s2 []byte) int
- func MemorySearch(mem, pattern []byte) int
- func MemorySearchIndex(mem, pattern []byte, start int) int
- func MemorySearchLastIndex(mem, pattern []byte, start int) int
- func Serialize(item interface{}) []byte
- func StringSplit(s, sep string) []string
- func StringSplitNonEmpty(s, sep string) []string
Constants ¶
const Hash = "\xc0\xef\x39\xce\xe0\xe4\xe9\x25\xc6\xc2\xa0\x6a\x79\xe1\x44\x0d\xd8\x6f\xce\xac"
Hash represents StdLib contract hash.
Variables ¶
This section is empty.
Functions ¶
func Atoi ¶
Atoi converts string to a number in a given base. Base should be either 10 or 16. It uses `atoi` method of StdLib native contract.
func Atoi10 ¶ added in v0.95.0
Atoi10 converts string to a number in a base 10. It uses `atoi` method of StdLib native contract.
func Base58CheckDecode ¶ added in v0.95.1
Base58CheckDecode calls `base58CheckDecode` method of StdLib native contract and decodes given base58 string with a checksum represented as a byte slice into a new byte slice.
func Base58CheckEncode ¶ added in v0.95.1
Base58CheckEncode calls `base58CheckEncode` method of StdLib native contract and encodes given byte slice into a base58 string with checksum and returns byte representation of this string.
func Base58Decode ¶
Base58Decode calls `base58Decode` method of StdLib native contract and decodes given base58 string represented as a byte slice into a new byte slice.
func Base58Encode ¶
Base58Encode calls `base58Encode` method of StdLib native contract and encodes given byte slice into a base58 string and returns byte representation of this string.
func Base64Decode ¶
Base64Decode calls `base64Decode` method of StdLib native contract and decodes given base64 string represented as a byte slice into byte slice.
func Base64Encode ¶
Base64Encode calls `base64Encode` method of StdLib native contract and encodes given byte slice into a base64 string and returns byte representation of this string.
func Deserialize ¶
func Deserialize(b []byte) interface{}
Deserialize calls `deserialize` method of StdLib native contract and unpacks previously serialized value from a byte slice, it's the opposite of Serialize.
func Itoa ¶
Itoa converts num in a given base to string. Base should be either 10 or 16. It uses `itoa` method of StdLib native contract.
func Itoa10 ¶ added in v0.95.0
Itoa10 converts num in a base 10 to string. It uses `itoa` method of StdLib native contract.
func JSONDeserialize ¶
func JSONDeserialize(data []byte) interface{}
JSONDeserialize deserializes value from json. It uses `jsonDeserialize` method of StdLib native contract. It performs deserialization as follows:
strings -> []byte (string) from base64 integers -> (u)int* types null -> interface{}(nil) arrays -> []interface{} maps -> map[string]interface{}
func JSONSerialize ¶
func JSONSerialize(item interface{}) []byte
JSONSerialize serializes value to json. It uses `jsonSerialize` method of StdLib native contract. Serialization format is the following: []byte -> base64 string bool -> json boolean nil -> Null string -> base64 encoded sequence of underlying bytes (u)int* -> integer, only value in -2^53..2^53 are allowed []interface{} -> json array map[type1]type2 -> json object with string keys marshaled as strings (not base64).
func MemoryCompare ¶ added in v0.95.0
MemoryCompare is similar to bytes.Compare: The result will be 0 if a==b, -1 if a < b, and +1 if a > b. It uses `memoryCompare` method of StdLib native contract.
func MemorySearch ¶ added in v0.95.0
MemorySearch returns index of the first occurrence of val in mem. If not found, -1 is returned. It uses `memorySearch` method of StdLib native contract.
func MemorySearchIndex ¶ added in v0.95.0
MemorySearchIndex returns index of the first occurrence of val in mem starting from start. If not found, -1 is returned. It uses `memorySearch` method of StdLib native contract.
func MemorySearchLastIndex ¶ added in v0.95.0
MemorySearchLastIndex returns index of the last occurrence of val in mem ending before start. If not found, -1 is returned. It uses `memorySearch` method of StdLib native contract.
func Serialize ¶
func Serialize(item interface{}) []byte
Serialize calls `serialize` method of StdLib native contract and serializes any given item into a byte slice. It works for all regular VM types (not ones from interop package) and allows to save them in storage or pass into Notify and then Deserialize them on the next run or in the external event receiver.
func StringSplit ¶ added in v0.95.0
StringSplit splits s by occurrences of sep. It uses `stringSplit` method of StdLib native contract.
func StringSplitNonEmpty ¶ added in v0.95.0
StringSplitNonEmpty splits s by occurrences of sep and returns a list of non-empty items. It uses `stringSplit` method of StdLib native contract.
Types ¶
This section is empty.