首页
随机
最近更改
特殊页面
社群首页
参数设置
关于WHY42
免责声明
WHY42
搜索
用户菜单
登录
欢迎来到Riguz的小站!这是一个私人wiki,用来记录一些我的笔记。
查看“︁Yjs varint encoding”︁的源代码
←
Yjs varint encoding
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
y-protocol defines protocol that is used when exchanging data between yjs clients<ref>https://github.com/yjs/y-protocols/blob/master/PROTOCOL.md</ref>. Yjs uses varint to encode content, which is similar in protobuf. Yjs encodes unsigned integer within range of 0-2^53-1, which is the max number supported by javascript<ref>https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER</ref>. <syntaxhighlight lang="python"> 123456=0b111|1000100|1000000 ->(1)1000000|(1)1000100|(0)____111 -> 0xc0 | 0xc4 | 0x07 </syntaxhighlight> The first bit indicates that whether there's a continuous byte, if it's 0, then the number is finished. In short, the protocol defines the following methods: * <syntaxhighlight lang="java" inline>varUint(number)</syntaxhighlight> * <syntaxhighlight lang="java" inline>varByteArray(buffer) := varUint(length(buffer)) • buffer</syntaxhighlight> * <syntaxhighlight lang="java" inline>utf8(string)</syntaxhighlight> * <syntaxhighlight lang="java" inline>varString(string) := varByteArray(utf8(string))</syntaxhighlight> * <syntaxhighlight lang="java" inline>json(object) := varString(JSON.stringify(object))</syntaxhighlight> Online tool to calculate varUint encoding: https://bluecrewforensics.com/varint-converter/ [[Category:Yjs]] [[Category:CRDT]]
返回
Yjs varint encoding
。