Viewing version 0.0.1+5. Open the latest package page.
standard_message_codec
0.0.1+5An efficient and schemaless binary encoding format for Flutter and Dart.
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');
}
Changelog
0.0.1+5
- Updates metadata for move to https://github.com/flutter/core-packages.
- Updates minimum supported SDK version to Flutter 3.38/Dart 3.10.
0.0.1+4
- Adds pub topics to package metadata.
- Updates minimum supported SDK version to Flutter 3.7/Dart 2.19.
0.0.1+3
- Minor README updates.
0.0.1+2
- Fixes lint warnings.
0.0.1+1
- Fixes minimum version of
testdependency.
0.0.1
- Initial release of standard message codec extracted from the Flutter SDK.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add 'standard_message_codec:0.0.1+5'pubspec.yaml
name: standard_message_codec
description: An efficient and schemaless binary encoding format for Flutter and Dart.
repository: https://github.com/flutter/core-packages/tree/main/packages/standard_message_codec
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Astandard_message_codec
version: 0.0.1+5
environment:
sdk: ^3.10.0
dev_dependencies:
test: ^1.16.0
topics:
- decode
- encode
- interop
Version history
Dependencies
No direct dependencies declared.