binary_codec 1.0.0 copy "binary_codec: ^1.0.0" to clipboard
binary_codec: ^1.0.0 copied to clipboard

outdated

Converts null, bools, ints, doubles, Uint8Lists, Strings, Maps and Lists into a binary format and back

Binary Codec #

Package designed for simple conversion of some standard data types to Uint8List and back.

It's my first package and I'm a student with no time, be patient please.

Example #

See installation tab for how to add this library to your project.

Use folowing line to import the library in a file.

import 'package:binary_codec/binary_codec.dart';

Example usecase:

import 'dart:convert';
import 'dart:typed_data';

import 'package:binary_codec/binary_codec.dart';

void main() {
    Map info = {
        'allowedTypes': [
            null,
            true,
            false,
            'Any strings',
            utf8.encode('Any Uint8Lists'),
            12385.12385734,
            -1293573.1324543,
            "'any' ints",
            {
                'sets': 'are also allowed',
            },
            [
                'lists',
                'are also allowed',
            ]
        ],
        'note about ints': 'Care about the floating-int-mess in javascript (for dart2js only integers in the safe range are handled correctly)',
        'note about keys': {
            'description': 'You can use any of the allowedTypes for keys',
            'example': {
                123: 'asdf',
                124.235: 'qwer',
                true: 'x',
                null: 'y',
                Uint8List.fromList([255, 0, 218, 17]): 'z',
            },
        },
        'note about root type': 'Note that you can pass any of the allowed types into the decoder, not just maps',
    };
    Uint8List encoded = binaryCodec.encode(info);

    var decoded = binaryCodec.decode(encoded);
  
    assert(info.toString() == decoded.toString());

    print(decoded.toString());
}
7
likes
0
pub points
67%
popularity

Publisher

unverified uploader

Converts null, bools, ints, doubles, Uint8Lists, Strings, Maps and Lists into a binary format and back

Homepage

License

unknown (license)

More

Packages that depend on binary_codec