搜索插件、代码仓与 APP 分类

插件详情v1.2.3

data_serializer

便携式 Dart 包,用于高效处理数据序列化/反序列化,包括一个动态的 BytesBuffer 以读写数据。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1.3万
喜欢数
3
Pub 分数
150

安装插件

flutter pub add data_serializer

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个便携式 Dart 包,用于高效的数据序列化和反序列化,具有动态 BytesBuffer,可低级别读写二进制数据。旨在简化对象与序列化格式之间的转换,支持跨平台使用,涵盖 Android、iOS、Web、macOS、Windows 和 Linux。适用于需要高性能数据处理且开销极小的应用场景。在涉及网络通信、文件存储或实时数据交换的场合尤其有用,此时速度和可靠性至关重要。

适合场景

  • 二进制数据传输
  • 文件格式解析
  • 实时数据处理
  • 跨平台数据共享
  • 网络协议实现

主要特点

  • 动态 BytesBuffer
  • 高效序列化
  • 跨平台支持
  • 底层数据操作
  • 高性能

适合对象

  • 高性能应用
  • 网络密集型应用
  • 嵌入式系统
  • 数据密集型工作流
  • 自定义二进制格式

使用建议

  • 需要理解二进制数据
  • 仅限基本类型,不包含自定义逻辑
  • 不适合复杂的JSON结构
  • 需要手动类型管理
  • 低级别操作的学习曲线

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

data_serializer

pub package Null Safety Codecov Dart CI GitHub Tag New Commits Last Commits Pull Requests Code size License

Portable Dart package to handle data serialization/deserialization efficiently, including a dynamic BytesBuffer to read/write data.

API Documentation

See the API Documentation for a full list of functions, classes and extension.

Usage

import 'package:data_serializer/data_serializer.dart';

void main() {
  // Dynamic bytes buffer with initial capacity of 16 bytes.
  var buffer = BytesBuffer(16);

  // Write a unsigned int of 32 bits:
  buffer.writeInt32(0x10203040);

  // Write a `String` encoded using UTF-8:
  buffer.writeString('Hello!');

  // Write a unsigned int of 64 bits:
  buffer.writeUint64(9223372036854775807);

  // Write a data block (prefixed by 4 bytes for he data length).
  var dataBlock = [110, 120, 130, 140, 150, 160].toUint8List();
  buffer.writeBlock32(dataBlock);

  // Write all bytes:
  buffer.writeAll([210, 220]);

  // The current length of the buffer, expanded automatically:
  print('length: ${buffer.length}');

  // Change the current position cursor to `0`:
  buffer.seek(0);

  // Read a 32 bits int:
  var n32 = buffer.readUint32();
  print('n32: 0x${n32.toHex32()}');

  // Reads a `String` decoding from UTF-8:
  var s = buffer.readString();
  print('s: $s');

  // Read a 64 bits int:
  var n64 = buffer.readUint64();
  print('n64: $n64');

  // The current buffer position:
  print('position: ${buffer.position}');

  // Read a data block:
  var dataBlock2 = buffer.readBlock32();
  print('dataBlock2: $dataBlock2');

  // The position after read the data block:
  print('position: ${buffer.position}');

  // The remaining bytes in the buffer:
  var tailBytes = buffer.readRemainingBytes();
  print('tailBytes: $tailBytes');
}

OUTPUT:

length: 34
n32: 0x10203040
s: Hello!
n64: 9223372036854775807
position: 22
dataBlock2: [110, 120, 130, 140, 150, 160]
position: 32
tailBytes: [210, 220]

Browser/JavaScript compatibility

All the operations are tested to be compatible with JavaScript.

Note that JS only supports 53-bits integers. To avoid any issue serializing 64-bits integers, try to use BigInt serialization, or ensure that you are bellow the 53-bits range.

See the class DataSerializerPlatform if you need runtime information about integers support.

Test Coverage

Codecov

This package aims to always have a high test coverage percentage, over 95%. With that the package can be a reliable tool to support your important projects.

Source

The official source code is hosted @ GitHub:

  • https://github.com/gmpassos/data_serializer

Features and bugs

Please file feature requests and bugs at the issue tracker.

Contribution

Any help from the open-source community is always welcome and needed:

  • Found an issue?
    • Please fill a bug report with details.
  • Wish a feature?
    • Open a feature request with use cases.
  • Are you using and liking the project?
    • Promote the project: create an article, do a post or make a donation.
  • Are you a developer?
    • Fix a bug and send a pull request.
    • Implement a new feature.
    • Improve the Unit Tests.
  • Have you already helped in any way?
    • Many thanks from me, the contributors and everybody that uses this project!

If you donate 1 hour of your time, you can contribute a lot, because others will do the same, just be part and start with your 1 hour.

Author

Graciliano M. Passos: gmpassos@GitHub.

License

Apache License - Version 2.0

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目