当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
19 Star 122 Fork 136

OpenHarmony-SIG/flutter_packages
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

An efficient and schemaless binary format used by the Flutter SDK.

Features

Efficiency

The standard message codec is a binary format, as opposed to text based formats like JSON. Consider the following snippet of JSON:

{
    "data": [1, 2, 3, 4],
}

In order for this message to be decoded into a Dart map, a utf8 binary file must first be parsed and validated into a Dart string. Then a second pass is performed which looks for specific characters that indicate JSON structures - for example "{" and "}". No sizes or lengths are known ahead of time while, parsing, so the resulting Dart list created for the "data" key is append to as decoding happens.

In contrast, decoding the standard message codec version of this message avoids utf8 decoding, instead operating on the bytes themselves. The only string constructed will be for the "data" key. The length of the list in the data field is encoded in the structure, meaning the correct length object can be allocated and filled in as decoding happens.

Schemaless

Using standard message codec does not require a schema (like protobuf) or any generated code. This makes it easy to use for dynamic messages and simplifies the integration into existing codebases.

The tradeoff for this ease of use is that it becomes the application's responsibility to verify the structure of messages sent/received. There is also no automatic backwards compatibility like protobuf.

Getting started

standard_message_codec can be used to encode and decode messages in either Flutter or pure Dart applications.

void main() {
  final ByteData? data =
      const StandardMessageCodec().encodeMessage(<Object, Object>{
    'foo': true,
    3: 'fizz',
  });
  print('The encoded message is $data');
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openharmony-sig/flutter_packages.git
git@gitee.com:openharmony-sig/flutter_packages.git
openharmony-sig
flutter_packages
flutter_packages
master

搜索帮助