# 开始
top ::= value
# 8-bit二进制数据,拆分成最大64k的chunks
# 每个chunk最多表示4093个字符
binary ::= x41 b1 b0 <binary-data> binary # 非末尾chunk,x41 b1 b0 是固定值,数据末尾加上binary作为结束
::= ‘B‘ b1 b0 <binary-data> # 末尾chunk,‘B‘ b1 b0 是固定值
::= [x20-x2f] <binary-data> # 长度为0-15的二进制binary数据
::= [x34-x37] <binary-data> # 长度为0-1023的二进制binary数据
# boolean true/false
boolean ::= ‘T‘
::= ‘F‘
# 对象的定义(紧凑地映射)
class-def ::= ‘C‘ string int string*
# 自epoch(1970-01-01 00:00:00 UTC)以来的64bit毫秒编码的UTC时间
date ::= x4a b7 b6 b5 b4 b3 b2 b1 b0
::= x4b b3 b2 b1 b0 # 自epoch(1970-01-01 00:00:00 UTC)开始的秒数
# 64-bit IEEE double双精度类型
double ::= ‘D‘ b7 b6 b5 b4 b3 b2 b1 b0
::= x5b # 0.0
::= x5c # 1.0
::= x5d b0 # byte转化的double (-128.0 to 127.0)
::= x5e b1 b0 # short转化的double
::= x5f b3 b2 b1 b0 # 32-bit float转化的double
# 32-bit 有符号整数
int ::= ‘I‘ b3 b2 b1 b0
::= [x80-xbf] # -x10 to x3f
::= [xc0-xcf] b0 # -x800 to x7ff
::= [xd0-xd7] b1 b0 # -x40000 to x3ffff
# list/vector
list ::= x55 type value* ‘Z‘ # 可变长度的list
::= ‘V‘ type int value* # 固定长度的ist
::= x57 value* ‘Z‘ # 可变长度的无类型list
::= x58 int value* # 固定长度的无类型list
::= [x70-77] type value* # 固定长度的有类型list
::= [x78-7f] value* # 固定长度的无类型 list
# 64-bit 有符号长整型
long ::= ‘L‘ b7 b6 b5 b4 b3 b2 b1 b0
::= [xd8-xef] # -x08 到 x0f
::= [xf0-xff] b0 # -x800 到 x7ff
::= [x38-x3f] b1 b0 # -x40000 到 x3ffff
::= x59 b3 b2 b1 b0 # 32-bit 整型转化成长整型
# map/object map或对象
map ::= ‘M‘ type (value value)* ‘Z‘ # key, value 映射键值对
::= ‘H‘ (value value)* ‘Z‘ # 无类型key, value键值对
# null值
null ::= ‘N‘
# Object实例
object ::= ‘O‘ int value*
::= [x60-x6f] value*
# 值引用value reference (例如循环树和图表circular trees and graphs)
ref ::= x51 int # 引用第N个map/list/object
# UTF-8 encoded character string split into 64k chunks
# 被编码为utf-8的字符串,拆分到最大64k的chunks中
string ::= x52 b1 b0 <utf8-data> string # 非末尾 chunk
::= ‘S‘ b1 b0 <utf8-data> # 长度为0-65535的字符串
::= [x00-x1f] <utf8-data> # 长度为0-31的字符串
::= [x30-x34] <utf8-data> # 长度为0-1023的字符串
# 用于面向对象语言的map/list类型
type ::= string # type name
::= int # type reference
# 值类型
value ::= null
::= binary
::= boolean
::= class-def value
::= date
::= double
::= int
::= list
::= long
::= map
::= object
::= ref
::= string