Copyright © 2020-2026 World Wide Web Consortium. W3C® liability, trademark and permissive document license rules apply.
CBOR 是一种紧凑的二进制数据序列化和消息传递格式。本 规范定义了 CBOR-LD 1.0,一种基于 CBOR 的格式,用于序列化链接数据。 该编码旨在利用现有的 JSON-LD 生态系统,该生态系统如今已 部署在数亿个系统上,为寻求高效编码方案的用户提供一种紧凑的 序列化格式。通过利用语义压缩方案,可实现比 通用压缩方案高出 60% 以上的压缩率。该格式 主要旨在作为一种在存储和带宽受限的编程环境中使用链接数据的方式, 用于构建可互操作的语义线级协议, 并在基于 CBOR 的存储引擎中高效存储链接数据。
本节描述本文档在 发布时的状态。当前 W3C 出版物列表以及本技术报告的最新修订版可在 W3C 标准和草案 索引中找到。
本文档是实验性的。
有一个 参考实现,能够 演示本文档中描述的功能。
本文档由 JSON-LD 工作组 作为 工作草案使用 推荐标准 轨道发布。
作为 工作草案发布并不意味着 W3C 及其成员的认可。
这是一份草案文档,可能会在任何时候被其他 文档更新、替换或废弃。除作为 进行中的工作外,不宜引用本文档。
本文档由一个在 W3C 专利 政策下运作的工作组制作。 W3C 维护一份 任何专利 披露的公开列表, 这些披露与该工作组的交付成果有关; 该页面还包含 披露专利的说明。实际知晓某项专利的个人,如果该个人认为该专利包含 必要权利要求, 必须依照 W3C 专利政策第 6 节 披露该信息。
本文档受 2025 年 8 月 18 日 W3C 流程文档管辖。
本节为非规范性内容。
CBOR 是一种紧凑的二进制数据序列化和消息传递格式。本 规范定义了 CBOR-LD 1.0,一种基于 CBOR 的格式,用于序列化链接数据。 该编码旨在利用现有的 JSON-LD 生态系统,该生态系统如今已 部署在数亿个系统上,为寻求高效编码方案的用户提供一种紧凑的 序列化格式。通过利用语义压缩方案,可实现比 通用压缩方案高出 60% 以上的压缩率。该格式 主要旨在作为一种在存储和带宽受限的编程环境中使用链接数据的方式, 用于构建可互操作的语义线级协议, 并在基于 CBOR 的存储引擎中高效存储链接数据。
本节为非规范性内容。
本文档是关于在 CBOR 中对链接 数据进行序列化的详细规范。本文档主要面向以下读者:
除标记为非规范性的章节外,本规范中的所有编写指南、图示、示例和注释 均为非规范性内容。本规范中的其他所有内容均为规范性内容。
本文档中的关键词 MUST 应按 BCP 14 [RFC2119] [RFC8174] 中所述解释,且仅当它像这里所示那样 全部大写出现时才如此解释。
本节为非规范性内容。
可以通过多种方式参与 本规范的开发:
本节为非规范性内容。
CBOR-LD 满足以下设计目标:
同样,以下内容不是目标。
在制定本规范的过程中,已经识别出以下雷区:
本节为非规范性内容。
在高层次上,CBOR-LD 是 JSON-LD 的一种紧凑二进制序列化格式,允许 使用以下机制进行额外压缩:
编解码器是以通用方式压缩类型值的基本原语。语义压缩 用于压缩 JSON-LD 术语。注册表字典用于以 特定用例方式压缩类型值。其中每一种都是可选的——CBOR-LD 可与这些 压缩策略中的任意一种、全部或完全不使用一起使用。总体而言,为 特定用例使用的这些策略集合称为处理模型。
本节为非规范性内容。
语义压缩是创建紧凑 CBOR-LD 载荷的强大工具。其核心思想是 使用外部 JSON-LD 上下文对象的信息内容来压缩 JSON-LD 术语。 这些外部上下文对象对载荷的创建者和消费者都可用, 因此这以可逆方式完成。
一般的语义压缩过程是取一个 JSON-LD 文档并执行 以下操作:
@context 值;嵌入式上下文值不能被压缩)。
CBOR-LD 载荷需要能在二进制层面被识别为此类载荷。CBOR 通过其“标签” 功能原生支持这一点——即二进制数据中的一个头部值, 通过全局注册表描述其余载荷。
CBOR 标签 0xCB1D(标签值 51997)已在
IANA
CBOR 标签注册表中注册,用于 CBOR-LD。紧随该标签值之后的
数据标识用于创建压缩载荷的注册表条目。
CBOR-LD 载荷MUST被结构化,使得带有标签
0xCB1D 的项
是一个双元素数组,并且第一个元素MUST是一个
主类型 0 整数。
这个整数是 CBOR-LD 注册表条目 ID。其二进制结构为
tag([registryEntryId, payload])。
CBOR-LD 注册表条目 ID 的值随后用于在 CBOR-LD 注册表 中查找一个 CBOR-LD 注册表条目。
为了支持可能用例的无限扩展,这些用例需要不同的 压缩表材料以供消费,同时使用单个 CBOR 标签值,我们定义如下内容。
CBOR-LD 注册表是一个全局列表,为 CBOR-LD 载荷的消费者提供重建解压所需 术语编解码器映射所需要的信息。CBOR-LD 注册表条目包含以下内容:
Registry Entry ID:正整数。
Use Case:此条目要用于的 CBOR-LD 载荷类型。
typeTables:包含要与此
注册表条目一起使用的注册表字典的数组。
processingModel:此注册表条目使用什么处理模型。处理
模型
指定以下内容:
default 处理模型使用语义压缩,并包含
本文档中指定的编解码器。
provisional:一个布尔值,表示该条目是否为临时条目。临时条目
可能会更改或移除。
字符串 "callerProvidedTable" 可出现在 typeTables 中,表示对于此用
例,
需要一个未全局定义的
Type Table。
当前 CBOR-LD 注册表可在此处找到。
要注册条目,请按照 README 中的说明操作。该注册表由 W3C JSON-LD 社区组拥有。
此算法以映射 typeTable、整数 registryEntryId 和
JSON-LD
文档 jsonldDocument 作为输入,并返回十六进制字符串
cborldBytes。
prefix 设为把 registryEntryId 传递给
5.6.1 获取
CBOR 标签结构算法所得的结果。
state 设为空映射。
registryEntryId 关联的注册表条目需要语义
压缩:
state.strategy 设为 "compression"。
state.typeTable 设为 typeTable。
state.registryEntryId 设为 registryEntryId。
state 设为把 state 传递给
5.2.1
初始化转换算法所得的结果。
output 设为把 state 和
jsonldDocument
作为 inputDocument 传递给 5.2.2 转换文档算法所得的结果。
suffix 设为 output 的 CBOR 编码。
suffix 设为 jsonldDocument 的 CBOR 编码。
cborldBytes 设为在 suffix 前添加 prefix 后得到的
十六进制编码。
cborldBytes。
此算法以 CBOR-LD 载荷 cborldBytes 作为输入,并返回 JSON-LD 文档
jsonldDocument。
state 设为空映射。
result 设为把 cborldBytes 传给
5.6.2 获取
注册表条目 ID 算法的结果。
state.registryEntryId 设为
result.registryEntryId,并将 suffix 设为
result.suffix。
state.registryEntryId 关联的注册表条目使用
语义压缩:
state.strategy 设为 "decompression"。
registryEntryId 关联的 CBOR-LD Varint 注册表条目中
typeTables 数组里的每个条目 type: map,
将该条目添加到 state.typeTable,并将
state.reverseTypeTable 中 type 的值设为
inverseMap,其中 inverseMap 是将 map 的映射反转后的结果。
state 设为把 state 传给
5.2.1
初始化转换算法的结果。
input 设为把 suffix 从字节解码为
映射的结果。
jsonldDocument 设为把 state 和
input 作为 inputDocuments
传给 5.2.2
转换文档算法的结果。
jsonldDocument 设为解析 cborldBytes 的结果。
jsonldDocument。
本节中的算法描述了“转换器”的行为,用于在数据形式之间进行抽象 转换。当与“策略”结合使用时, 例如本节后面定义的 "compression" 和 "decompression" 策略, 这些算法可以被实例化以在具体数据形式之间进行转换。"compression" 策略从 JSON-LD 转换为 CBOR-LD,而 "decompression" 策略从 CBOR-LD 转换为 JSON-LD。
此算法接收并返回映射 state。
state 设为把 state 传递给
5.4.1
初始化上下文加载器算法所得的结果。
state.initialActiveContext 设为把空映射
termMap 和
previousActiveContext 传递给 5.3.1 初始化活动上下文算法所得的结果。
state.typesEncodedAsBytes 设为空集合。
state.typesEncodedAsBytes。
state。
此算法以映射 state 和映射或
映射数组 inputDocuments 作为输入,并返回一个包含映射 state 和映射或
映射数组 outputMaps 的映射。
inputDocuments 是数组,则将 inputs 设为
inputDocuments。否则,将 inputs
设为 [inputDocuments]。
outputMaps 设为空数组。
inputs 中的 input:
output 设为空映射。
result 设为把 state、input、
output 和
state.initialActiveContext 作为 activeContext 传递给
5.2.3
通用转换算法所得的结果。
result.output 添加到 outputMaps。
state 设为 result.state。
inputDocuments 是数组,则返回 outputMaps。否则,返回
outputMaps 的
第一个元素。
此算法以映射 input、output、state 和
activeContext
作为输入,并返回一个包含映射 state 和 output 的映射。
state.strategy 被设为 "compression":
contextConversionResult 设为
5.2.5.1 为压缩转换上下文算法的结果,
并传入
state、activeContext、input 和
output。
activeContext 设为 contextConversionResult.activeContext,
output
设为 contextConversionResult.output,并将 state 设为
contextConversionResult.state。
activeContext 设为
result.activeContext,并将 state 设为
result 的 result.state,其中 result 来自
5.2.6.1 为解压缩转换上下文算法,并传入
state、
activeContext、input 和 output。
state.strategy 被设为 "compression",则将 state 设为
result.state,并将
objectTypes 设为 result.objectTypes,其中 result 来自
5.2.5.4
获取用于压缩的对象类型算法,并传入 state、
activeContext、input 和 output。
state 设为 result.state,并将 objectTypes 设为
result.objectTypes,
其中 result 来自 5.2.6.4 获取用于解压缩的对象类型
算法,
并传入 state、activeContext、input 和
output。
activeContext 设为把 activeContext 和
objectTypes 传递给
5.3.4
应用类型作用域上下文算法所得的结果。
state.strategy 被设为 "compression",则将 state 设为
result.state,并将
termEntries 设为 result.termEntries,其中 result 来自
5.2.5.3 获取用于压缩的输入项算法,并传入
state、
input 和 activeContext。
state 设为 result.state,将 output 设为
result.output,
并将 termEntries 设为 result.termEntries,其中 result
来自
5.2.6.3 获取用于解压缩的输入项算法,
并传入 state、input、output 和 activeContext。
termEntries 中的 [termInfo, value]:
term 设为 termInfo.term。
valueActiveContext 设为把 activeContext
和 term 传递给
5.3.3 应用属性作用域上下文算法所得的结果。
plural 设为 termInfo.plural 的值,并将
termType 设为
termInfo.def 中 @type 的值。
plural 被设为 true,则将 values 设为
value 的值。否则,将 values 设为
一个包含 value 的值作为单个元素的数组。
outputs 设为空数组。
values 中的 unconvertedValue:
result 设为 5.2.4 转换值算法的结果,
并传入 state、termType、作为 value 的
unconvertedValue
以及作为 activeContext
的 valueActiveContext。
state 设为 result.state,并将
result.output 添加到 outputs。
plural 被设为 true,则将 outputValues 设为
outputs。否则,将 outputValues
设为 outputs 的第一个元素。
state.strategy 被设为 "compression",则在 output 中将
termInfo.termId 的值映射到
outputValues。否则,在 output 中将
termInfo.term 的值映射到 outputValues。
result 设为空映射。
result.state 设为 state,并将 result.output 设为
output。
result。
此算法以映射 state、activeContext、termInfo 以及
值 value 和 termType 作为输入。
它返回一个包含映射 state 和 output 的 result 对象。
value 是 null,则返回 null。
state.strategy 被设为 "compression",则将 output 设为
把 state、termType、
termInfo 和 value 传递给 5.2.5.2
为压缩转换值算法所得的结果。
output 设为把 state、
termType、
termInfo 和 value 传递给 5.2.6.2
为解压缩转换值算法所得的结果。
output 已定义,则返回 result,即一个包含
state 和 output 的映射。
value 是数组:
outputs 设为空数组。
value 中的 element:
result 为 5.2.4 转换值算法的结果,
并传入 activeContext、state、
termInfo、termType 以及作为
value 的 element。将 state 设为
result.state,并将
result.output
添加到 outputs。
result 设为空映射。将 result.state
设为 state,并将 result.output 设为
outputs。
result。
output 设为空映射。
result 设为 5.2.3 通用转换算法的结果,并传入
state、
activeContext、作为 input 的 value,以及 output。
result。
本节中的算法定义了 "compression" 策略, 该策略将与前面定义的“转换”算法一起使用, 以将 JSON-LD 转换为 CBOR-LD。
此算法以映射 state、activeContext、input
和 output
作为输入,并返回一个包含映射 output、state
和 activeContext 的映射 result。
applyEmbeddedResult 设为 5.3.2
应用嵌入式上下文算法的结果,
并传入 state、activeContext 和 input。
activeContext 设为 applyEmbeddedResult.activeContext,并将
state 设为
applyEmbeddedResult.state。
input 中没有条目:
result 设为空映射。
result.state 设为 state,并将
result.activeContext 设为 activeContext。
result。
context 设为 input 中 "@context" 的值。
encodedContexts 设为空数组。
context 是数组,则将 isArray 设为 true,
并将
contexts 设为 context。
否则,将 isArray 设为 false,并将 contexts 设为
[context]。
contexts 中的 contextValue:
encoderData 设为 5.5.1.1 创建上下文编码器的结果,
并传入
state.typeTable 和 contextValue。
encoderData 是空映射,则将 contextValue 添加到
encodedContexts。
encoderData 的值添加到
encodedContexts。
isArray 为 true,则将 id 设为
state.keywordsMap 中 "@context" 的值加 1,
并在 output 中将 id 的值设为 encodedContexts。
id 设为 state.keywordsMap 中 "@context" 的值,
并在
output 中将 id 的值设为 encodedContexts 的第一个元素。
result.output 设为 output,将 result.state 设为
state,并将 result.activeContext
设为 activeContext。
result。
此算法以映射 state 和 termInfo,以及值
valueToEncode 和 termType
作为输入,并返回映射 encoderData。
valueToEncode 是对象,则返回。
result 设为 5.5.2.1 创建值编码器的结果,并传入
state、termInfo、valueToToEncode 和
termType。
result。
此算法以映射 state、activeContext 和
input 作为输入,并返回一个映射 state 和一个数组 entries。
entries 初始化为空数组。
keys 设为 input 的键,并按字典序排序。
keys 中的 key:
key 是 "@context",则继续。
value 设为 input 中 key 的值。
value 是数组,则将 plural 设为 true。
否则,将 plural 设为 false。
key 在
state.termToId 中没有条目,则将 termId 设为
key。
plural 为 true,则将 termId 设为
state.termToId 中 key 的值加 1。
termId 设为
state.termToId 中 key 的值。
activeContext.termMap 有
key 的条目,则将 definition 设为
activeContext.termMap 中 key 的值。否则,将
definition 设为空映射。
entryTerm 设为一个新映射。
entryTerm 中 "term" 的值设为
key 的值。将 termId、plural 和
definition
添加到 entryTerm。
entry,即 entryTerm 和
value。
entry 添加到 entries。
entries 和 state 的映射 result。
此算法以映射 activeContext 和 input 作为输入,并返回集合
objectTypes。
objectTypes 设为空集合。
activeContext.typeTerms 中的 term:
term 在 input 中有条目:
types 设为
input 中 term 的值。
types 中的每个值添加到 objectTypes。
objectTypes。
本节中的算法定义了 "decompression" 策略, 该策略将与前面定义的“转换”算法一起使用, 以将 CBOR-LD 转换为 JSON-LD。
此算法以映射 state、activeContext、input
和 output 作为输入,并返回一个
包含映射 output、state 和
activeContext 的映射 result。
decoderData 设为 5.5.1.3 创建上下文解码器的结果,并传入
state.reverseTypeTable。
contextTermId 设为
state.keywordsMap 中 "@context" 的值。
contextTermId 在 input 中有条目,则将
output 中 "@context" 的值设为 5.5.1.4 解码上下文的结果,并传入
decoderData 以及
input 中 contextTermId 的值作为 value。
contextTermIdPlural 设为 contextTermId 的值加 1。
contextTermIdPlural 在 input 中有条目:
contextTermId 在前一次检查期间也已经在 input
中有条目,则抛出
ERR_INVALID_ENCODED_CONTEXT 错误。
encodedContexts 设为 input 中
contextTermIdPlural
的值。如果 encodedContexts
不是数组,则抛出 ERR_INVALID_ENCODED_CONTEXT 错误。
contexts 设为空数组。
encodedContexts 中的每个 valueToDecode,
将把 decoderData 和作为 value 的 valueToDecode
传递给 5.5.1.4
解码上下文所得的结果添加到 contexts。
output 中 "@context" 的值设为 contexts。
embeddedContextResult 设为 5.3.2
应用嵌入式上下文算法的结果,并传入
activeContext、作为 input 的 output,以及
state。
result 设为空映射。
result.state 设为
embeddedContextResult.state,并将 result.activeContext
设为
embeddedContextResult.activeContext。
result。
此算法以映射 state 和 termInfo,以及值
termType 和 valueToDecode 作为输入,并返回值
decodedValue。
value 是映射,则返回。
decoderData 设为 5.5.2.3 创建值解码器的结果,并传入
valueToDecode、
state、termInfo 和 termType。
decodedValue 设为 5.5.2.4 解码值的结果,并传入 decoderData。
decodedValue。
此算法以映射 state、activeContext 和
input 作为输入,并返回一个映射 state 和一个数组
entries。
entries 初始化为空数组。
input 中的键值对 key 和 value:
key 是
state.keywordsMap 中 "@context" 的值,或该值加 1,则继续。
key 是字符串,则将 plural 设为 false,并将
term 设为 key。
key 是奇数,则将 plural 设为 true。否则,将
plural 设为 false。
plural 为 true,则将 term 设为
state.idToTerm 中 id 减 1 的值。
如果该值没有条目,则抛出错误
ERR_UNKNOWN_CBORLD_TERM_ID。
term 设为
state.idToTerm 中 id 的值。如果该值没有
条目,则抛出错误 ERR_UNKNOWN_CBORLD_TERM_ID。
definition 设为
activeContext.termMap 中 term 的值。
entryTerm 设为一个新映射。
entryTerm 中 "termId" 的值设为
key 的值。将 term、plural 和
definition
添加到 entryTerm。
entry,即 entryTerm 和
value。
entry 添加到 entries。
entries 中每个元素里的 term 值对
entries 排序。
entries 和 state 的映射 result。
此算法以映射 state、activeContext、input
作为输入,并
返回一个映射 state 和一个集合 objectTypes。
objectTypes 设为空集合。
activeContext.typeTerms 中的 term:
term 在
state.termToId 中没有条目,则将 termId 设为
term。
termId 设为
state.termToId 中 term 的值。
termId 和 termId 加 1 都不存在于
input 中,则继续。
termId 存在于 input 中,则将
value 设为 input 中 termId 的值。
value 设为 input 中 termId 加 1 的值。
key 是字符串,则将 plural 设为 false,并将
term 设为 key。
key 是奇数,则将 plural 设为 true。否则,将
plural 设为 false。
plural 为 true,则将 term 设为
state.idToTerm 中 id 减 1 的值。
如果该值没有条目,则抛出错误
ERR_UNKNOWN_CBORLD_TERM_ID。
term 设为
state.idToTerm 中 id 的值。如果该值没有
条目,则抛出错误 ERR_UNKNOWN_CBORLD_TERM_ID。
definition 设为
activeContext.termMap 中 term 的值。
termInfo 设为一个新映射。
term、termId、plural 和
definition 添加到 termInfo。
value 不是数组,则将 values 设为一个
包含 value 作为单个元素的数组。
否则,将 values 设为 value 的值。
values 中的每个 value:
decoderData 设为 5.5.2.3
创建值解码器的结果,并传入 value、
termInfo、state 以及作为
termType 的 "@vocab"。
decoderData 存在,则将把
5.5.2.4
解码值的结果添加到
`objectTypes,其中传入 decoderData。
value 添加到 objectTypes。
objectTypes。
本节中的算法描述如何确定 与 JSON-LD 文档关联的上下文文档中的哪些组件 在压缩或解压缩期间的任意时刻正在被使用。 这些算法包括如何在 CBOR-LD 中应用嵌入式、类型作用域和 属性作用域上下文。这与本规范稍后定义的上下文 加载算法形成对比,后者描述如何 构造从术语到整数的映射,这些映射是 CBOR-LD 压缩技术的核心。活动上下文处理和上下文 加载算法共同规定了在与 CBOR-LD 之间转换时应如何处理 JSON-LD 上下文文档。
此算法以映射 previousActiveContext 和 termMap
作为输入,并返回映射 activeContext。它会更新正在使用的
活动上下文,并查找 '@type' 的所有别名。
activeContext 设为一个新映射。
activeContext.previousActiveContext 设为 previousActiveContext。
activeContext.termMap 设为 termMap。
activeContext.typeTerms 设为数组 ['@type']。
termMap 中的 [term, def]:
def 中 "@id" 的值是 "@type",则将 term 添加到
activeContext.typeTerms。
activeContext。
此算法以映射 state、activeContext 和 input
作为输入,并
返回一个包含映射 state 和 activeContext 的映射 result。
termMapUpdateResult 设为把 state、
作为
activeTermMap 的 activeContext.termMap,以及 input 中
'@context' 的值作为
contexts 传递给
5.3.5 更新术语
映射算法所得的结果。
state 设为 termMapUpdateResult.state。
termMap 设为 termMapUpdateResult.activeTermMap。
newActiveContext 设为 5.3.1
初始化活动上下文算法的结果,
并传入 termMap 以及作为
previousActiveContext 的 activeContext。
result 设为一个新映射,并将 result.activeContext 设为
newActiveContext,并将
result.state 设为 state。
result。
此算法以映射 state、activeContext 和字符串
term 作为输入,并
返回一个包含映射 state 和 activeContext 的映射 result。
revertedTermMap 设为 5.3.6 还原术语映射算法的结果,
并传入 activeContext。
termDef 设为
activeContext.termMap 中 term 的值。将 contexts 设为
termDef 中 "@context" 的值。
termMapUpdateResult 设为把 state、
作为
activeTermMap 的 revertedTermMap,作为 propertyScope 的
true,以及
contexts 传递给
5.3.5 更新术语
映射算法所得的结果。
state 设为 termMapUpdateResult.state。
termMap 设为 termMapUpdateResult.activeTermMap。
newActiveContext 设为 5.3.1
初始化活动上下文算法的结果,
并传入 termMap 以及作为
previousActiveContext 的 activeContext。
result 设为一个新映射,并将 result.activeContext 设为
newActiveContext,并将
result.state 设为 state。
result。
此算法以映射 state、activeContext 和集合
objectTypes 作为输入,并
返回一个包含映射 state 和 activeContext 的映射 result。
objectTypesSorted 设为空数组。
objectTypes 的元素,并按顺序将这些元素添加到
objectTypesSorted。
newTermMap 设为 activeContext.termMap。
objectTypesSorted 中的 type:
typeDef 设为 newTermMap 中 type 的值。
将 contexts 设为
typeDef 中 "@context" 的值。
termMapUpdateResult 设为把 state、
作为
activeTermMap 的 newTermMap、contexts 以及作为
typeScope 的 true 传递给
5.3.5
更新术语映射算法所得的结果。
state 设为 termMapUpdateResult.state,并将
newTermMap 设为
termMapUpdateResult.activeTermMap。
newActiveContext 设为 5.3.1
初始化活动上下文算法的结果,
并传入作为 termMap 的 newTermMap 以及作为
previousActiveContext 的 activeContext。
result 设为一个新映射,并将 result.activeContext 设为
newActiveContext,并将
result.state 设为 state。
result。
此算法以映射 state、activeTermMap 和映射或数组
contexts,以及布尔值 typeScope
和 propertyScope 作为输入;若未提供,这两个布尔值都默认为
false。它返回映射 state
和 activeTermMap。
contexts 不是数组,则将 contexts 设为一个数组,其唯一元素为
contexts
之前的值。
allowProtectedOverride 设为 propertyScope 的值。
propagateDefault 设为 typeScope 的值的否定。
contexts 中的 contextIdentifier:
loadResult 设为 5.4.2 加载上下文算法的结果,并传入
state 和
contextIdentifier。
entry 设为 loadResult.entry,
将 context 设为 entry.context,并将 state
设为 loadResult.state。
@propagate 出现在 context 中,则将 propagate
设为 context 中 @propagate 的值。
否则,将 propagate 设为 propagateDefault 的值。
newTermMap 设为空映射。对于 entry.termMap
中的 [key,
value]:
value 的内容浅拷贝到一个新映射
newValue 中,并将 propagate
添加到 newValue。
newTermMap 中 key 的值设为
newValue。
activeTermMap 中的 [term, activeDef]:
def 为
newTermMap 中 term 的值。
def 已定义:
activeDef 中 protected 的值为
true:
allowProtectedOverride 被设为
false,并且 def 与
activeDef 不完全相同,
则抛出错误 ERR_PROTECTED_TERM_REDEFINITION。
newTermMap 中 term 的值设为一个映射,该映射包含来自
activeDef
的值,并将 propagate 设为
def.propagate 的值。
term 出现在 context 中,则将
newTermMap 中 term 的值设为
一个包含来自 activeDef 的所有值的映射。
activeTermMap 的值设为 newTermMap 的值。
result 设为空映射。
result.state 设为 state,并将
result.activeTermMap 设为 activeTermMap。
result。
此算法以映射 activeContext 作为输入,并返回映射
newTermMap。
newTermMap 设为空映射。
nonPropagatingTerms 设为空数组。
activeContext 中的 [term, def]:
def.propagate 被设为 false,则将 term 添加到
nonPropagatingTerms,
并进入此循环的下一次迭代。
newTermMap 中 term 的值设为
def。
nonPropagatingTerms 中的 term:
currentContext 设为 activeContext.previousActiveContext。
def 设为
currentContext.termMap 中 term 的值。
def 未定义且 def.propagate 被设为
false 时:
currentContext 设为
activeContext.previousActiveContext。
def 设为
currentContext.termMap 中 term 的值。
def 未定义,则将 newTermMap 中
term 的值设为 def。
newTermMap。
本节中的算法定义如何构造 术语与整数之间的映射,这些映射被用作 CBOR-LD 压缩技术的核心。
此算法接收并返回映射 state。
state.contextMap 设为一个新映射。
state.nextTermId 设为 100。
state.keywordsMap 设为以下 JSON-LD 关键词到其关联
整数值的映射:
{
'@context' => 0,
'@type' => 2,
'@id' => 4,
'@value' => 6,
'@direction' => 8,
'@graph' => 10,
'@included' => 12,
'@index' => 14,
'@json' => 16,
'@language' => 18,
'@list' => 20,
'@nest' => 22,
'@reverse' => 24,
'@base' => 26,
'@container' => 28,
'@default' => 30,
'@embed' => 32,
'@explicit' => 34,
'@none' => 36,
'@omitDefault' => 38,
'@prefix' => 40,
'@preserve' => 42,
'@protected' => 44,
'@requireAll' => 46,
'@set' => 48,
'@version' => 50,
'@vocab' => 52,
'@propagate' => 54
}
state.keywordsMap 中的每个条目添加到 state.termToId。
state.strategy 被设为 "decompression",则将 state.idToTerm 设为
state.termToId 的反向映射
(即从整数到 JSON-LD 关键词的映射)。
state。
此算法以映射 state 和上下文映射或 URL
contextIdentifier 作为输入,并返回
result,即一个包含映射 state 和 entry 的映射。
state.contextMap 有 contextIdentifier 的条目:
result 初始化为空映射。
result.state 设为 state。
result.entry 设为
state.contextMap 中 contextIdentifier 的值。
result。
context 是字符串:
context 设为
该对象中 "@context" 的值。
contextUrl 设为 contextIdentifier 的值。
context 设为 contextIdentifier。
result 设为 5.4.3 添加上下文算法的结果,并传入
state、context,以及如果已设置则传入 contextUrl。
result。
此算法以映射 state、上下文对象 context 和上下文
URL contextUrl
作为输入,并返回 result,即一个包含映射 state 和 entry 的映射。
context 有条目 "@import":
importUrl 设为 `context 中 "@import" 的值。
state.contextMap 没有 importUrl 的条目:
importUrl 关联的上下文对象,并将
importContext 设为该对象中
"@context" 的值。
importedContextAdditionResult 设为 5.4.3
添加上下文算法的结果,
并传入 state、作为 context 的 importContext,
以及作为 contextUrl 的 importUrl。
state 设为 importedContextAdditionResult.state,并将
importEntry 设为
importedContextAdditionResult.entry。
importEntry 设为
state.contextMap 中 importUrl 的值。
context 设为一个包含来自 context 的所有条目以及
importEntry.context 的映射。
termMap 设为空映射。
entry 设为一个包含 context 和 termMap 的对象。
sortedTerms 设为按字典序排序 context 中键所得的结果。
context 中有条目,则将 isProtected 设为
true,否则设为 false。
sortedTerms 中的 term:
term 在 state.keywordsMap 中有条目,则进入此循环的下一次
迭代。
definition 设为 context 中 term 的值。
definition 是 null,则进入此循环的下一次
迭代。
definition 是字符串:
newDefinition 设为空映射。
newDefinition 中 "@id" 的值设为 definition。
definition 的值设为 newDefinition。
definition 中 protected 的值设为
isProtected。
termMap 中 term 的值设为 definition。
term 在 state.termToId 中没有条目:
termId 设为 state.nextTermId。
state.nextTermId 增加 2。
state.termToId 中 term 的值设为
termId。
state.idToTerm 中 termId 的值设为
term。
contextUrl 已定义,则将
state.contextMap 中 contextUrl 的值设为 entry。
state.contextMap 中 context 的值
设为 entry。
result 设为空映射。
result.state 设为 state,并将 result.entry 设为
entry。
result。
本节中的编解码器明确规定了 JSON-LD 中各个值应如何转换为 CBOR, 以及如何反向转换。它们被前一节中的算法使用,并使 CBOR-LD 能够 高效地 将原始类型和非原始类型编码为 CBOR。
此算法以映射 typeTable 和值 contextValue 作为输入,并
返回映射 encoderData。
encoderData 初始化为空映射。
contextValue 不是字符串,则返回。
contextTable 设为
typeTable 中 "context" 的值。
encoderData.context 设为 contextValue,并将
encoderData.contextTable 设为
contextTable。
encoderData。
此算法以映射 encoderData 作为输入,并返回 CBOR 二进制数据。
encoderData.context 在
encoderData.contextTable 中有条目,则返回
encoderData 中 encoderData.context 的值作为
主类型 0(无符号整数)对象的 CBOR 编码。
encoderData.context 的值作为主类型 3
(文本字符串)对象的 CBOR 编码。
此算法以映射 reverseTypeTable 作为输入,并
返回映射 encoderData。
reverseContextTable 设为
reverseTypeTable 中 "context" 的值。
decoderData 初始化为空映射。
decoderData.reverseContextTable 设为
reverseContextTable 的值,并
返回 decoderData。
此算法以映射 decoderData 和值 value 作为输入,并返回
一个值。
value 不是数字,则返回 value。
decoderData.reverseContextTable 有
value 的条目,则返回
该条目的值。
此算法以映射 state 和 termInfo,以及值
termType 和 valueToEncode 作为输入,并返回映射 encoderData
或 valueToEncode。
isUrl 设为 false。
termInfo.term 是 "@id" 或 "@type",则将 isUrl 设为
true。
termInfo.def 中 "@id" 的值是 "@id" 或 "@type",则将
isUrl 设为 true。
termType 是 "@id" 或 "@vocab",则将 isUrl 设为 true。
isUrl 为 true,则将 tableType 设为 "url"。
termType 已定义,则将 tableType 设为
termType。
tableType 设为 "none"。
state.typeTable 有 tableType 的条目:
subTable 设为
state.typeTable 中 tableType 的值。
subTable 有 valueToEncode 的条目:
intValue 设为 subTable 中
valueToEncode 的值。
将 includeSign 设为 false。
state.typesEncodedAsBytes 有
tableType 的条目,则将 convertToBytes 设为
true。
否则,将 convertToBytes 设为 false。
tableType 不是 "none" 且 valueToEncode 是
整数:
intValue 设为 valueToEncode 的值。
convertToBytes 和 includeSign 设为
true。
intValue 已定义:
encoderData 初始化为空映射。
encoderData.intValue 设为
intValue 的值,将
encoderData.convertToBytes
设为
convertToBytes 的值,并将
encoderData.includeSign 设为
includeSign 的值。
encoderData。
tableType 在 state.processingModeTypeEncoders 中有条目,则将
encoderData 设为
调用与该条目的编解码器关联的 Create Encoder 算法所得的结果。
encoderData 已定义,则返回 encoderData。
valueToEncode。
此算法以映射 encoderData 作为输入,并返回 CBOR 二进制数据。
encoderData.convertToBytes 为 true:
bytes 设为把 intValue 转换为字节所得的结果,
使用 includeSign 的值来
确定该整数的二进制表示应为有符号还是
无符号。
bytes 作为主类型 2(字节字符串)对象的 CBOR 编码。
intValue 作为主类型 0(无符号
整数)对象的 CBOR 编码。
此算法以映射 state 和 termInfo,以及值
termType 和 valueToDecode 作为输入,并返回映射
decoderData。
isUrl 设为 false。
termInfo.term 是 "@id" 或 "@type",则将 isUrl 设为
true。
termInfo.def 中 "@id" 的值是 "@id" 或 "@type",则将
isUrl 设为 true。
termType 是 "@id" 或 "@vocab",则将 isUrl 设为 true。
isUrl 为 true,则将 tableType 设为 "url"。
termType 已定义,则将 tableType 设为
termType。
tableType 设为 "none"。
state.reverseTypeTable 有 tableType 的条目:
subTable 设为
state.reverseTypeTable 中 tableType 的值。
useTable 设为 false。
valueToDecode 是字节数组,并且
state.typesEncodedAsBytes 有
tableType 的条目:
useTable 设为 true。
intValue 设为
valueToDecode 字节的无符号整数转换结果。
valueToDecode 是整数,并且
state.typesEncodedAsBytes 没有
tableType 的条目:
useTable 设为 true。
intValue 设为 valueToDecode。
useTable 为 true:
intValue 不在 subTable 中,则抛出错误
ERR_UNKNOWN_COMPRESSED_VALUE。
decoded 设为
subTable 中 intValue 的值。
valueToDecode 是字节数组且 tableType
不是 "none",则将
decoded 设为 valueToDecode 的整数转换结果。
decoded 已定义,则将 decoderData 初始化为空
映射,将 decoderData.decoded 设为
decoded 的值,并返回 decoderData。
tableType 在 state.processingModeTypeDecoders 中有条目,则将
DecoderData 设为
调用与该条目的编解码器关联的 Create Decoder 算法所得的结果。
decoderData 已定义,则返回 decoderData。
valueToDecode 不是数组,则初始化
decoderData 为空映射,将
decoderData.decoded 设为 valueToDecode,并返回
decoderData。
此算法以映射 decoderData 作为输入,并返回一个值。
decoderData.decoded。
registryEntryId 作为输入,并返回字节字符串
prefix。
registryEntryBytes 设为 registryEntryID 的 CBOR 编码
prefix 设为把 registryEntryBytes 追加到
字节字符串 0xD9CB1D82 末尾所得的结果。
prefix。
此算法以已编码的 CBOR-LD 载荷 cborldBytes 作为输入,并返回
suffix(要解码的主要数据)以及
应用于解压缩 suffix 的 registryEntryId 值。
cborldbytes 上的 CBOR 标签不是 0xCB1D(标签值 51997),
则抛出 ERR_NON_CBOR_LD_TAG 错误。
ERR_INVALID_PAYLOAD_STRUCTURE 错误。
registryEntryId 的值设为被标记
数组索引 0 处整数的值。
suffix 的值设为该数组第二个元素的值。
result 设为空映射。
result.suffix 设为 suffix 的值,并将
result.registryEntryId 设为
registryEntryId 的值。
result。
本节为非规范性内容。
本节为非规范性内容。
本节为非规范性内容。
本规范注册了一个 CBOR 标签,以允许消费者识别 CBOR-LD 载荷。 以下内容是临时性的,尚未得到 IANA 批准。
标签:51997
注册表: https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml
数据项:数组
语义:标签值 51997 表示该载荷是 CBOR-LD。
语义描述: https://w3c.github.io/cbor-ld/#cbor-tags-for-cbor-ld
联系人:Wesley Smith (wsmith@digitalbazaar.com)