효율적인 데이터 직렬화 및 역직렬화를 위한 휴대용 Dart 패키지로, 바이너리 데이터의 저수준 읽기 및 쓰기를 위한 동적 BytesBuffer를 제공합니다. 객체와 직렬화된 형식 간의 변환을 간소화하도록 설계되었으며, 안드로이드, iOS, 웹, macOS, Windows, 리눅스 등 다양한 플랫폼에서 크로스플랫폼 사용을 지원합니다. 최소한의 오버헤드로 고성능 데이터 처리가 필요한 애플리케이션에 이상적입니다. 네트워크 통신, 파일 저장, 실시간 데이터 교환과 같은 시나리오에서는 속도와 신뢰성이 중요한 경우에 특히 유용합니다.
사용 사례
이진 데이터 전송
파일 형식 파싱
실시간 데이터 처리
다중 플랫폼 간 데이터 공유
네트워크 프로토콜 구현
주요 기능
동적 BytesBuffer
효율적인 직렬화
크로스 플랫폼 지원
저수준 데이터 조작
고성능
적합한 대상
고성능 앱
네트워크 집약형 애플리케이션
임베디드 시스템
데이터 집약적인 워크플로우
사용자 지정 이진 형식
고려 사항
이진 데이터에 대한 이해가 필요합니다
사용자 정의 로직 없이 기본 유형에 제한됨
복잡한 JSON 구조에 적합하지 않습니다
수동 유형 관리 필요
저수준 작업의 학습 곡선
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
data_serializer
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';
voidmain() {
// 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');
}
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
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.