ble_data_converter 1.0.0

SDKdartflutter
Platformandroidios

This package is for easy conversion to rawdata(List<int>) to be sent to BLE devices, etc.

Purpose

This package is for easy conversion to rawdata(List<int>) to be sent to BLE devices, etc.
The types supported by this package are utf8, int8/16/32/64, uint8/16/32/64.
also supported Endian Types (Big-endian / Little-endian)
it is based on Swift(iOS) int type.

How to Use

  • String to utf-8(Big-endian)
  // encode(Big-endian)
  const String sampleStr = "sample";
  final List<int> strData = BLEDataConverter.str.stringToUtf8(randomStr);

  print(strData) // [115, 97, 109, 112, 108, 101]
  
  // decode(Big-endian)
  final String decodeStr = BLEDataConverter.str.stringFromUtf8(strData)

  print(decodeStr) // "sample"
  • int to int64 byte data(Big-endian)
  // encode(Big-endian)
  final int i64Max = 9223372036854775807;
  final List<int> value = BLEDataConverter.i64.intToBytes(i64Max);

  print(value); // [127, 255, 255, 255, 255, 255, 255, 255]

  // decode(Big-endian)
  final int decode = BLEDataConverter.i64.bytesToInt(value);

  print(decode); // 9223372036854775807
  • also Support Little-endian
  // encode(Little-endian)
  final int i64Max = 9223372036854775807;
  final List<int> value =
      BLEDataConverter.i64.intToBytes(i64Max, endian: Endian.little);

  print(value); //[127, 255, 255, 255, 255, 255, 255, 255]

  // decode(Little-endian)
  final int decode =
      BLEDataConverter.i64.bytesToInt(value, endian: Endian.little);

  print(decode); // 9223372036854775807

Compatible Type

Typebyte lengthmaxmin
Int81127-128
Int16232767-32768
Int3242147483647-2147483648
Int6489223372036854775807-9223372036854775808
UInt812550
UInt162655350
UInt32442949672950
UInt648184467440737095516150
Typebyte Length
utf8reference