Donation
If this package helps you, consider supporting its development:
tlv_decoder
TLV stands for "Type-Length-Value," a data structure used to encapsulate multiple pieces of information into a single byte sequence.
Features
- Encode a list of
TLVentries into bytes. - Decode bytes into a list of
TLVentries. - BER/DER length fields, both short and long form:
0x00–0x7Ffor lengths0–127.0x81 LLfor lengths128–255.0x82 LL LLfor lengths256–65535.0x83/0x84 …for larger lengths.
- Input validation with clear
FormatExceptionmessages for truncated or unsupported input.
Getting started
dependencies:
tlv_decoder: ^0.0.5
Usage
import 'dart:typed_data';
import 'package:tlv_decoder/tlv_decoder.dart';
void main() {
// Decoding
final data = Uint8List.fromList(
[0x01, 0x03, 0x41, 0x42, 0x43, 0x02, 0x02, 0x44, 0x45],
);
final List<TLV> tlvList = TlvUtils.decode(data);
// Encoding
final encoded = TlvUtils.encode([
TLV(type: 1, length: 3, value: Uint8List.fromList([0x41, 0x42, 0x43])),
TLV(type: 2, length: 2, value: Uint8List.fromList([0x44, 0x45])),
]);
}
TLV.length is informational; TlvUtils.encode always derives the length field from the value bytes.
Features and bugs
Please file feature requests and bugs at the issue tracker.
License
Project under MIT license.
