tencent cloud

Cloud Log Service

Encoding and Decoding Functions

Download
フォーカスモード
フォントサイズ
最終更新日: 2026-05-20 19:58:46

Function decode_url

Function Definition

This function is used to decode an encoded URL.

Syntax Description

decode_url(value)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
url
URL value
String
Yes
-
-

Example

Raw logs:
{"url":"https%3A%2F%2Fcloud.tencent.com%2F"}
Processing rules:
fields_set("result",decode_url(v("url")))
Processing result:
{"result":"https://cloud.tencent.com/","url":"https%3A%2F%2Fcloud.tencent.com%2F"}

Function md5_encoding

Function Definition

This function is used to calculate and return the MD5 checksum.

Syntax Description

md5_encoding(value)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
Value
The data for which to calculate the MD5 checksum
String
Yes
-
-

Example

Raw logs:
{"field": "haha"}
Processing rules:
fields_set("field", md5_encoding(v("field")))
Processing result:
{"field":"4e4d6c332b6fe62a63afe56171fd3725"}

Function uuid

Function Definition

This function is used to generate a universally unique identifier (UUID).

Syntax Description

uuid()

Parameter Description

No input parameters

Example

Raw logs:
{"key":"value"}
Processing rules:
fields_set("field",uuid())
Processing result:
{"field":"8c2db704-45c0-4ea1-9e2c-cf9c966e35cd","key":"value"}

Function str_encode

Function Definition

Encode a string in the specified format.

Syntax Description

str_encode(data, encoding="utf8", errors="ignore")

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
data
Data to be encoded
String
Yes
-
-
encoding
Encoding format. The default is utf8. ASCII, latin1, and unicode-escape are supported.
String
No
utf8
-
errors
Handling method when the encoding format fails to recognize characters.
ignore (default): Ignore and do not encode.
Strict control: Report an error directly and discard this log data.
replace: Use a half-angle question mark (?), and replace the unrecognized part.
xmlcharrefreplace: Use corresponding XML character references to replace unrecognized parts
String
No
ignore
-

Example

Raw logs:
{"field1": "asd encode encode \\\\u1234"}
Processing rules:
fields_set("field2", str_decode(str_encode(v("field1"), "unicode-escape"), "unicode-escape"))
Processing result:
{"field1":"asd encode encode \\\\u1234","field2":"asd code code ሴ"}

Function Str_decode

Function Definition

Decode a string in the specified format.

Syntax Description

str_decode(data, encoding="utf8", errors="ignore")

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
data
Data to be decoded
String
Yes
-
-
encoding
Encoding format. The default is utf8. ASCII, latin1, and unicode-escape are supported.
String
No
utf8
-
errors
Handling method when the encoding format fails to recognize characters.
ignore (default): Ignore and do not decode.
Strict control: Report an error directly and discard this log data.
replace: Replace the undecodable part with a half-width question mark (?).
xmlcharrefreplace: Use corresponding XML characters to replace undecodable parts
String
No
ignore
-

Example

Raw logs:
{"field1": "Test in English and Chinese: qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM special symbols:]] [! @#$%^&*()_++~"}
Processing rules:
fields_set("field2", str_decode(str_encode(v("field1"))))
Processing result:
{"field1":"Test in English and Chinese: qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM Special Symbols:]] [! @#$%^&*()_++~", "field2":"Test in English and Chinese: qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM special symbols:]] [! @#$%^&*()_++~"}

Function Base64 Encode

Function Definition

Encode the string in base64.

Syntax Description

base64_encode(value, format="RFC3548")

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
value
String to be encoded
string
Yes
-
-
format
Encoding format, supports RFC4648 (default), RFC3548
string
No
RFC4648
-

Example

Raw logs:
{"field": "hello world"}
Processing rules:
fields_set("encode", base64_encode(v("field")))
Processing result:
{"encode":"aGVsbG8gd29ybGQ=", "field":"hello world"}

Function Base64 Decode

Function Definition

Decode the string from base64.

Syntax Description

base64_decode(value, format="RFC3548")

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
value
String to be decoded
string
Yes
-
-
format
Decoding format, supports RFC4648 (default), RFC3548.
string
No
RFC4648
-

Example

Raw logs:
{"field": "aGVsbG8gd29ybGQ="}
Processing rules:
fields_set("decode", base64_decode(v("field")))
Processing result:
{"decode":"hello world", "field":"aGVsbG8gd29ybGQ="}

hashids_encode Function

Function Definition

Encode the data using the Hashids library.

Syntax Description

hashids_encoding(value, salt="", min_length=0)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
value
String to be encoded
Number,List,Tuple
Yes
-
When the value is a number, it cannot be less than 0.
salt
Adds a salt value to the data. The default value is an empty string.
String
Yes
""

min_length
Minimum length of the generated hash value. The default value is 0.
Number
Yes
0
-

Example 1

Raw logs:
{"data": "[123, 456]"}
Processing rules:
fields_set("hashid", hashids_encode(v("data"), salt="test", min_length=32))
Processing result:
{"data":"[123, 456]", "hashid":"O6jN0Z7VARqDzbpBHYOakeowE5Xnr41g"}

Example 2

Raw logs:
{"data1": "123", "data2": "456"}
Processing rules:
fields_set("hashid", hashids_encode(v("data1"),v("data2"), salt="test", min_length=32))
Processing result:
{"data1": "123", "data2": "456", "hashid":"O6jN0Z7VARqDzbpBHYOakeowE5Xnr41g"}

hashids_decode Function

Function Definition

Decode the data that has been encoded using the Hashids library.

Syntax Description

hashids_decoding(hash_value, salt="", min_length=0)

Parameter Description

Parameter Name
Parameter Description
Parameter Type
Required
Default Value
Parameter Value Range
hash_value
String to be decoded
String
Yes
-
-
salt
Adds a salt value to the data. The default value is an empty string.
String
Yes
""
-
min_length
Minimum length of the generated hash value. The default value is 0.
Number
Yes
0
-

Example

Raw logs:
{"hashid":"O6jN0Z7VARqDzbpBHYOakeowE5Xnr41g"}
Processing rules:
fields_set("result", hashids_decode(v("hashid"), salt="test", min_length=32))
Processing result:
{"result":"[123, 456]","hashid":"O6jN0Z7VARqDzbpBHYOakeowE5Xnr41g"}

ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック