byte_bloc 0.1.1 copy "byte_bloc: ^0.1.1" to clipboard
byte_bloc: ^0.1.1 copied to clipboard

outdated

ByteBloc simplify binary array parsing for C/C++ structures.

byte_bloc #

ByteBloc simplify binary array parsing for C/C++ structures.

Usage #

Import #

import 'package:byte_bloc/byte_bloc.dart';

Example of C/C++ structure from embeded device #

struct DeviceStructure
{
    u_int32_t type;
    char longitude[12];
};

Binary array of the structure will look like #

[10, 0, 0, 0, 77, 121, 32, 100, 101, 118, 105, 99, 101, 0, 0, 0]

From dart side we can implement model with factory fromByteBloc and method toByteBloc #

class DeviceStructure {
  static const int NAME_SIZE = 12;
  final int id;
  final String name;

  DeviceStructure({this.id, this.name});

  factory DeviceStructure.fromByteBloc(ByteBloc byteBloc) {
    final id = byteBloc.readUint32();
    final name = byteBloc.readString(NAME_SIZE);
    return DeviceStructure(id: id, name: name);
  }

  ByteBloc toByteBloc() {
    final byteBloc = ByteBloc.empty()
      ..writeUint32(id)
      ..writeString(name, NAME_SIZE);
    return byteBloc;
  }
}

Deserialize model #

  final binaryArray = [10, 0, 0, 0, 77, 121, 32, 100, 101, 118, 105, 99, 101, 0, 0, 0];
  final binaryArrayByteBloc = ByteBloc(Uint8List.fromList(binaryArray));
  final deviceStructure = DeviceStructure.fromByteBloc(binaryArrayByteBloc);

Serialize model #

  final resultByteBloc = deviceStructure.toByteBloc();
  print(resultByteBloc.list);

TODO Write unite tests for ByteBloc write methods #

4
likes
0
pub points
35%
popularity

Publisher

unverified uploader

ByteBloc simplify binary array parsing for C/C++ structures.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

convert, meta

More

Packages that depend on byte_bloc