codec.base64EncodeThis function encodes a string into Base64 format, which is used to represent binary data in text form, making it safe for transmission over text protocols.
Signature: codec.base64Encode(str string) string
Arguments: str — an arbitrary string to be encoded in base64.
Result: A string encoded in base64 format.
Example of use:
$encoded = codec.base64Encode(“Hello!”) // $encoded will contain the string “0J/RgNC40LLQtdGCIQ==”
codec.base64DecodeDecodes the string specified in Base64.
Signature: ccodec.base64Decode(str string) ?string
Arguments: str — a string encoded in Base64.
Result: The original string if decoding was successful, or nil if the string contains invalid characters.
Example of use:
$decoded = codec.base64Decode(“0J/RgNC40LLQtdGCIQ==”) // $decoded will contain the string “Hello!”
$failed = codec.base64Decode(“Hello!”) // $failed will be equal to nil
odec.jsonEncode(value any) stringEncodes the specified value in JSON.
Signature: codec.jsonEncode(value any) string
Arguments: value — arbitrary value for encoding.
Return value: Returns the value in json format.
Example of use:
$encoded = codec.jsonEncode((1, true, “a”, {‘a’: 1, “b”: 2})) // $encoded will contain the string ‘[1, true, “a”, {‘a’: 1, “b”: 2}]’
codec.jsonDecodeDecodes the value specified in JSON.
Signature: codec.jsonDecode(value string) any
Arguments: value — the value encoded in json.
Return value: returns the decoded value or nil if it cannot be decoded.
Example of use:
$decoded = codec.jsonDecode(‘[1, true, “a”, {“a”: 1, “b”: 2}]’) // $decoded will contain the list [1, true, “a”, {‘a’: 1, “b”: 2}]
codec.urlEncodeThis function encodes a string according to the RFC3986 standard, converting special characters into a format that is safe for transmission in a URL.
Signature: codec.urlEncode(str string) string
Arguments: str — the string to be encoded for use in a URL.
Result: A string encoded in URL format.
Example of use:
$encoded = codec.urlEncode(“Hello!”)
// $encoded will contain the string “%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%21”
codec.urlDecodeThis function decodes a string encoded in URL format according to the RFC3986 standard, restoring the original text.
Signature: codec.urlDecode(str string) string
Arguments: str — a string encoded in URL format.
Result: Decoded string.
Examples of use:
$decoded = codec.urlDecode(“%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%21”)
// $decoded will contain the string “Hello!”
$decoded = codec.urlDecode(“%%”)
// $decoded will contain the string “%%”