pro_mpack 3.0.0
pro_mpack: ^3.0.0 copied to clipboard
A Dart library for serializing and deserializing data in the MessagePack format.
Examples Structure #
This directory contains examples demonstrating how to use pro_mpack effectively in various scenarios.
1. Basic Usage #
A simple overview showing how to use the core API:
- Simple Serialization: How to encode and decode standard types.
- Collections: Working with Lists and Maps.
- Reusable Instance: High-performance caching with a
MessagePackinstance. - One-off Extensions: Using
encodeExtanddecodeExtfor quick custom types without a registry.
2. Extensions in Depth #
A focused example on how to build and register custom extensions for complex, nested data types and external classes:
- Polymorphic Extensions: How to register external types like
BigIntwhich have internal implementations (_BigIntImpl). - Nested Groups: Organizing relational structures (
User,Address,Product) usingregisterGroupandsubIdto bypass the 256-ID limit. - Type-Safe Collections: Decoding nested arrays of specific models efficiently using
unpackArrayOf<T>()andunpackAs<T>(). - High Performance: Using the
MessagePackinstance for optimizedO(1)extension lookups.
3. Advanced Network Streaming #
A multi-file architectural example simulating a real-world IoT/Telemetry protocol:
- Custom Models: Encoding/decoding complex nested structures (
TelemetryPacket,SensorData) using custom MessagePack extensions. - Fragmentation Resilience: Proving that the
streamDecodercan reconstruct nested packets from tiny network chunks (e.g. 5 bytes at a time) without extra allocations. - Zero-Allocation: Uses
streamDecoderto avoid GC overhead for incomplete packets.
4. File Streaming (Big Data) #
A high-performance example demonstrating how to process large binary files:
- Real-world File Structure: Demonstrates how to write and parse files with custom headers (Magic Bytes, Version) and MessagePack metadata blocks.
- Incremental Processing: Using
File.openRead()andstreamDecoderto process data without loading the entire file into RAM. - Market Data Simulation: Packing and parsing 500,000 trade records (Market Ticks) on-the-fly using
Packerbatching (takeBytes(dispose: false)). - Memory Efficiency: Maintaining a constant memory footprint regardless of file size.
How to Run #
You can run any example directly using the Dart CLI:
# Run the basic overview
dart example/basic/main.dart
# Run the extensions example
dart example/extensions/main.dart
# Run the advanced telemetry simulation
dart example/network_streaming/main.dart
# Run the big data file streaming example
dart example/file_streaming/main.dart