ble_data_converter 1.0.0 ble_data_converter: ^1.0.0 copied to clipboard
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 #
Type | byte length | max | min |
---|---|---|---|
Int8 | 1 | 127 | -128 |
Int16 | 2 | 32767 | -32768 |
Int32 | 4 | 2147483647 | -2147483648 |
Int64 | 8 | 9223372036854775807 | -9223372036854775808 |
UInt8 | 1 | 255 | 0 |
UInt16 | 2 | 65535 | 0 |
UInt32 | 4 | 4294967295 | 0 |
UInt64 | 8 | 18446744073709551615 | 0 |
Type | byte Length |
---|---|
utf8 | reference |