Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/ndef.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ List<NDEFRecord> decodeRawNdefMessage(
while (!stream.isEnd()) {
var record = NDEFRecord.decodeStream(stream, typeFactory);
if (records.isEmpty) {
if (record.flags.MB != true) {
if (!record.flags.MB) {
throw FormatException("MB flag is not set in first record");
}
} else {
if (record.flags.MB != false) {
if (record.flags.MB) {
throw FormatException("MB flag is set in middle record");
}
}
records.add(record);
}
if (records.last.flags.ME != true) {
if (!records.last.flags.ME) {
throw FormatException("ME flag is not set in last record");
}
if (records.last.flags.CF != false) {
if (records.last.flags.CF) {
throw FormatException("CF flag is set in last record");
Comment on lines +52 to 56
}
return records;
Expand Down
6 changes: 3 additions & 3 deletions lib/record.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class NDEFRecord {

/// Sets the decoded type string, encoding it to UTF-8 bytes.
set decodedType(String? decodedType) {
encodedType = utf8.encode(decodedType!) as Uint8List?;
encodedType = utf8.encode(decodedType!);
}

/// Gets the type as a decoded UTF-8 string.
Expand Down Expand Up @@ -176,8 +176,8 @@ class NDEFRecord {
}

/// Sets the ID from a string value.
set idString(String? value) {
id = latin1.encode(value!);
set idString(String value) {
id = latin1.encode(value);
}

/// The minimum payload length for this record type.
Expand Down
7 changes: 1 addition & 6 deletions lib/records/absolute_uri.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,14 @@ class AbsoluteUriRecord extends NDEFRecord {

/// Gets the URI from the record type field.
String? get uri {
return decodedType;
return super.decodedType;
}

/// Sets the URI in the record type field.
set uri(String? uri) {
decodedType = uri;
}

@override
String? get decodedType {
return uri;
}

@override
String toString() {
var str = "AbsoluteUriRecord: ";
Expand Down
67 changes: 29 additions & 38 deletions lib/records/media/bluetooth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ class _Address {
}
}

_Address.fromBytes(Uint8List? bytes) {
if (bytes != null) {
if (bytes.length != 6) {
throw ArgumentError.value(
bytes.length,
"bytes.length",
"Bluetooth address must be 6 bytes",
);
}
addr = bytes;
_Address.fromBytes(Uint8List bytes) {
if (bytes.length != 6) {
throw ArgumentError.value(
bytes.length,
"bytes.length",
"Bluetooth address must be 6 bytes",
);
}
addr = bytes;
}

String get address {
Expand Down Expand Up @@ -67,7 +65,7 @@ class EPAddress extends _Address {
EPAddress({super.address});

/// Constructs an [EPAddress] from raw bytes.
EPAddress.fromBytes(Uint8List super.bytes) : super.fromBytes();
EPAddress.fromBytes(super.bytes) : super.fromBytes();

/// Gets the address as raw bytes.
Uint8List get bytes {
Expand Down Expand Up @@ -108,19 +106,12 @@ class LEAddress extends _Address {
late LEAddressType type;

/// Constructs an [LEAddress] with the specified [type] and [address].
LEAddress({LEAddressType? type, super.address}) {
this.type = type!;
}
LEAddress({required this.type, super.address});

LEAddress.fromTypeBytes(LEAddressType? type, Uint8List bytes)
: super.fromBytes(bytes) {
this.type = type!;
}
LEAddress.fromTypeBytes(this.type, Uint8List bytes) : super.fromBytes(bytes);

LEAddress.fromBytes(Uint8List? bytes) {
if (bytes != null) {
this.bytes = bytes;
}
LEAddress.fromBytes(Uint8List bytes) {
this.bytes = bytes;
}

@override
Expand Down Expand Up @@ -714,7 +705,7 @@ class EIR {
}

Uint8List get bytes {
return ([typeNum] + data) as Uint8List; // Strong cast, MAYBE have problems.
return Uint8List.fromList([typeNum!, ...data]);
}

set bytes(Uint8List bytes) {
Expand Down Expand Up @@ -774,13 +765,13 @@ class BluetoothRecord extends MimeRecord {
}

/// Sets the attribute [value] for the specified EIR [type].
void setAttribute(EIRType? type, Uint8List value) {
void setAttribute(EIRType type, Uint8List value) {
if (!EIR.typeNumMap.containsKey(type)) {
throw ArgumentError(
"EIR type $type is not supported, please select one from ${EIRType.values}",
);
}
attributes[type!] = value;
attributes[type] = value;
}

/// Gets the Bluetooth device name.
Expand Down Expand Up @@ -958,19 +949,19 @@ class BluetoothEasyPairingRecord extends BluetoothRecord {

@override
Uint8List get payload {
List<int?> data = <int?>[];
var data = <int>[];
for (var e in attributes.entries) {
data.add(e.value.length + 1);
data.add(EIR.typeNumMap[e.key]);
data.add(EIR.typeNumMap[e.key]!);
data.addAll(e.value);
Comment on lines 953 to 956
}
List<int>? payload = ByteUtils.intToBytes(
var payload = ByteUtils.intToBytes(
data.length + address!.bytes.length + 2,
2,
endianness: Endianness.Little,
) +
address!.bytes +
data.cast();
data;
return Uint8List.fromList(payload);
}

Expand Down Expand Up @@ -1014,7 +1005,7 @@ class BluetoothLowEnergyRecord extends BluetoothRecord {
/// Gets the Bluetooth LE device address.
LEAddress? get address {
if (attributes.containsKey(EIRType.LEBluetoothDeviceAddress)) {
return LEAddress.fromBytes(attributes[EIRType.LEBluetoothDeviceAddress]);
return LEAddress.fromBytes(attributes[EIRType.LEBluetoothDeviceAddress]!);
} else {
return null;
}
Expand Down Expand Up @@ -1121,8 +1112,8 @@ class BluetoothLowEnergyRecord extends BluetoothRecord {
"got ${attributes[EIRType.Appearance]!.length}",
);
}
int? value = ByteUtils.bytesToInt(
attributes[EIRType.Appearance],
int value = ByteUtils.bytesToInt(
attributes[EIRType.Appearance]!,
endianness: Endianness.Little,
);
if (appearanceMap.containsKey(value)) {
Expand Down Expand Up @@ -1212,14 +1203,14 @@ class BluetoothLowEnergyRecord extends BluetoothRecord {
}

@override
Uint8List? get payload {
Uint8List? payload = <int?>[] as Uint8List;
Uint8List get payload {
var data = <int>[];
for (var e in attributes.entries) {
payload.add(e.value.length + 1);
payload.add(EIR.typeNumMap[e.key!]!);
payload.addAll(e.value);
data.add(e.value.length + 1);
data.add(EIR.typeNumMap[e.key]!);
data.addAll(e.value);
Comment on lines 1208 to +1211
}
return Uint8List.fromList(payload);
return Uint8List.fromList(data);
}

@override
Expand Down
4 changes: 2 additions & 2 deletions lib/records/well_known/device_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class DeviceInformationRecord extends WellKnownRecord {
uuidData = Uint8List.fromList(Uuid.parse(uuid));
}

void _addEncodedData(String? value, int type, List<int?> payload) {
void _addEncodedData(String? value, int type, List<int> payload) {
if (value != null) {
payload.add(type);
Uint8List valueBytes = utf8.encode(value);
Expand All @@ -125,7 +125,7 @@ class DeviceInformationRecord extends WellKnownRecord {
"Decoding requires the manufacturer and model name TLVs",
);
}
List<int>? payload = [];
var payload = <int>[];

// known data
_addEncodedData(vendorName, 0, payload);
Expand Down
26 changes: 11 additions & 15 deletions lib/records/well_known/handover.dart
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,9 @@ class HandoverRecord extends WellKnownRecord {
}

@override
Uint8List? get payload {
Uint8List get payload {
var data = encodeNdefMessage(allRecordList);
// cast() 's use
List<int>? payload = ([version.value] + data).cast();
return Uint8List.fromList(payload);
return Uint8List.fromList([version.value] + data);
}

@override
Expand Down Expand Up @@ -553,7 +551,7 @@ class HandoverRequestRecord extends HandoverRecord {
}

@override
Uint8List? get payload {
Uint8List get payload {
if (version.value > 0x11) {
if (collisionResolutionNumber == null) {
throw ArgumentError(
Expand Down Expand Up @@ -673,7 +671,7 @@ class HandoverSelectRecord extends HandoverRecord {
}

@override
Uint8List? get payload {
Uint8List get payload {
if (version.value < 0x12 && errorRecordList.isNotEmpty) {
throw ArgumentError(
"Encoding error record version ${version.value} is not supported",
Expand Down Expand Up @@ -770,30 +768,28 @@ class HandoverCarrierRecord extends WellKnownRecord {
this.id = id;
}

int? _carrierTnf;
late int _carrierTnf;
String? carrierType;
late Uint8List carrierData;

TypeNameFormat get carrierTnf {
return TypeNameFormat.values[_carrierTnf!];
return TypeNameFormat.values[_carrierTnf];
Comment on lines 775 to +776
}

set carrierTnf(TypeNameFormat carrierTnf) {
_carrierTnf = TypeNameFormat.values.indexOf(carrierTnf);
}

String get carrierFullType {
return NDEFRecord.tnfString[_carrierTnf!] + carrierType!;
return NDEFRecord.tnfString[_carrierTnf] + carrierType!;
}

@override
Uint8List? get payload {
Uint8List get payload {
var carrierTypeBytes = utf8.encode(carrierType!);
List<int>? payload = ([_carrierTnf, carrierTypeBytes.length] +
carrierTypeBytes +
carrierData)
.cast();
return Uint8List.fromList(payload);
return Uint8List.fromList(
[_carrierTnf, carrierTypeBytes.length] + carrierTypeBytes + carrierData,
);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/records/well_known/signature.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class SignatureRecord extends WellKnownRecord {

for (int i = 0; i < certificateNumberOfCertificates; i++) {
int len = stream.readInt(2);
certificateStore.add(stream.readBytes(len));
_certificateStore.add(stream.readBytes(len));
}

if (certificateURIPresent == 1) {
Expand Down
4 changes: 2 additions & 2 deletions lib/records/well_known/smart_poster.dart
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,11 @@ class SmartPosterRecord extends WellKnownRecord {
///
/// The map should contain a MIME type as key and image/video data as value.
set icon(Map<String?, Uint8List?>? icon) {
String? decodedType = icon!.keys.toList()[0];
String? decodedType = icon!.keys.first;
_checkValidIconType(decodedType!);
iconRecord = MimeRecord(
decodedType: decodedType,
payload: icon.values.toList()[0],
payload: icon.values.first,
);
Comment on lines 578 to 584
}

Expand Down
6 changes: 3 additions & 3 deletions lib/records/well_known/uri.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ class UriRecord extends WellKnownRecord {
}

/// Constructs a [UriRecord] from a URI or IRI string.
UriRecord.fromString(String? string) {
iriString = string!;
UriRecord.fromString(String string) {
iriString = string;
}

/// Constructs a [UriRecord] from a [Uri] instance.
UriRecord.fromUri(Uri? uri) {
UriRecord.fromUri(Uri uri) {
uriString = uri.toString();
}

Expand Down
14 changes: 5 additions & 9 deletions lib/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class ByteUtils {

/// Converts [bytes] to an integer with the specified [endianness].
static int bytesToInt(
Uint8List? bytes, {
Uint8List bytes, {
Endianness endianness = Endianness.Big,
}) {
var stream = ByteStream(bytes!);
var stream = ByteStream(bytes);
return stream.readInt(stream.length, endianness: endianness);
}

Expand Down Expand Up @@ -73,12 +73,12 @@ class ByteUtils {

/// Converts a BigInt [value] to bytes with specified [length] and [endianness].
static Uint8List bigIntToBytes(
BigInt? value,
BigInt value,
int length, {
Endianness endianness = Endianness.Big,
}) {
var list = <int>[];
BigInt v = value!;
BigInt v = value;
for (int i = 0; i < length; i++) {
list.add((v % BigInt.from(256)).toInt());
v ~/= BigInt.from(256);
Expand Down Expand Up @@ -351,11 +351,7 @@ class Version {

/// Constructs a [Version] with an optional raw [value].
Version({int? value}) {
if (value != null) {
this.value = value;
} else {
value = 0;
}
this.value = value ?? 0;
}

/// Constructs a [Version] from [major] and [minor] version numbers.
Expand Down
Loading