使用字节类型
字节类型表示字节值的序列。
类型名称: bytes
字节语法
Flux 不提供字节字面量语法。使用 bytes()
函数 将字符串转换为字节。
bytes(v: "hello")
// Returns [104 101 108 108 111]
只有字符串类型可以转换为字节。
将字符串转换为字节
使用 bytes()
或 hex.bytes()
将字符串转换为字节。
bytes()
: 将字符串转换为字节hex.bytes()
: 解码十六进制值并将其转换为字节。
将十六进制字符串转换为字节
import "contrib/bonitoo-io/hex"
hex.bytes(v: "FF5733")
// Returns [255 87 51] (bytes)
在表中包含字节的字符串表示形式
使用 display()
返回字节的字符串表示形式,并将其作为列值包含在内。display()
将字节类型表示为以 0x
为前缀的小写十六进制字符的字符串。
import "sampledata"
sampledata.string()
|> map(fn: (r) => ({r with _value: display(v: bytes(v: r._value))}))
输出
tag | _time | _value (字符串) |
---|---|---|
t1 | 2021-01-01T00:00:00Z | 0x736d706c5f673971637a73 |
t1 | 2021-01-01T00:00:10Z | 0x736d706c5f306d6776396e |
t1 | 2021-01-01T00:00:20Z | 0x736d706c5f706877363634 |
t1 | 2021-01-01T00:00:30Z | 0x736d706c5f6775767a7934 |
t1 | 2021-01-01T00:00:40Z | 0x736d706c5f357633636365 |
t1 | 2021-01-01T00:00:50Z | 0x736d706c5f7339666d6779 |
tag | _time | _value (字符串) |
---|---|---|
t2 | 2021-01-01T00:00:00Z | 0x736d706c5f623565696461 |
t2 | 2021-01-01T00:00:10Z | 0x736d706c5f6575346f7870 |
t2 | 2021-01-01T00:00:20Z | 0x736d706c5f356737747a34 |
t2 | 2021-01-01T00:00:30Z | 0x736d706c5f736f78317574 |
t2 | 2021-01-01T00:00:40Z | 0x736d706c5f77666d373537 |
t2 | 2021-01-01T00:00:50Z | 0x736d706c5f64746e326276 |
此页是否对您有帮助?
感谢您的反馈!