mirror of
https://github.com/esiur/esiur-dart.git
synced 2025-06-27 14:53:11 +00:00
null-safety
This commit is contained in:
@ -2,14 +2,14 @@ import '../Core/IDestructible.dart';
|
||||
import 'Codec.dart';
|
||||
import 'dart:collection';
|
||||
|
||||
class AutoList<T, ST> extends IDestructible with IterableMixin {
|
||||
class AutoList<T, ST> extends IDestructible with IterableMixin<T> {
|
||||
List<T> _list = <T>[];
|
||||
|
||||
ST _state;
|
||||
bool _removableList;
|
||||
ST? _state;
|
||||
late bool _removableList;
|
||||
|
||||
sort(Function comparer) {
|
||||
_list.sort(comparer);
|
||||
sort(int Function(T, T)? compare) {
|
||||
_list.sort(compare);
|
||||
}
|
||||
|
||||
Iterator<T> get iterator => _list.iterator;
|
||||
@ -26,7 +26,7 @@ class AutoList<T, ST> extends IDestructible with IterableMixin {
|
||||
|
||||
/// Create a new instance of AutoList
|
||||
/// <param name="state">State object to be included when an event is raised.</param>
|
||||
AutoList([ST state, List<T> values]) {
|
||||
AutoList([ST? state, List<T>? values]) {
|
||||
this._state = state;
|
||||
this._removableList = Codec.implementsInterface<T, IDestructible>();
|
||||
|
||||
@ -105,8 +105,7 @@ class AutoList<T, ST> extends IDestructible with IterableMixin {
|
||||
/// </summary>
|
||||
clear() {
|
||||
if (_removableList)
|
||||
_list
|
||||
.forEach((x) => (x as IDestructible)?.off("destroy", _itemDestroyed));
|
||||
_list.forEach((x) => (x as IDestructible).off("destroy", _itemDestroyed));
|
||||
|
||||
// lock (syncRoot)
|
||||
_list.clear();
|
||||
|
@ -30,82 +30,56 @@ import 'DC.dart';
|
||||
import 'DataType.dart';
|
||||
import 'Guid.dart';
|
||||
|
||||
class BinaryList
|
||||
{
|
||||
var _list = <int>[];
|
||||
class BinaryList {
|
||||
var _list = <int>[];
|
||||
|
||||
int get length => _list.length;
|
||||
int get length => _list.length;
|
||||
|
||||
BinaryList addDateTime(DateTime value)
|
||||
{
|
||||
_list.addAll(DC.dateTimeToBytes(value));
|
||||
return this;
|
||||
}
|
||||
void addDateTime(DateTime value) {
|
||||
_list.addAll(DC.dateTimeToBytes(value));
|
||||
}
|
||||
|
||||
BinaryList insertDateTime(int position, DateTime value)
|
||||
{
|
||||
_list.insertAll(position, DC.dateTimeToBytes(value));
|
||||
return this;
|
||||
}
|
||||
void insertDateTime(int position, DateTime value) {
|
||||
_list.insertAll(position, DC.dateTimeToBytes(value));
|
||||
}
|
||||
|
||||
void addDateTimeArray(List<DateTime> value) {
|
||||
_list.addAll(DC.dateTimeArrayToBytes(value));
|
||||
}
|
||||
|
||||
BinaryList addDateTimeArray(List<DateTime> value)
|
||||
{
|
||||
_list.addAll(DC.dateTimeArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
void insertDateTimeArray(int position, List<DateTime> value) {
|
||||
_list.insertAll(position, DC.dateTimeArrayToBytes(value));
|
||||
}
|
||||
|
||||
BinaryList insertDateTimeArray(int position, List<DateTime> value)
|
||||
{
|
||||
_list.insertAll(position, DC.dateTimeArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
void addGuid(Guid value) {
|
||||
_list.addAll(DC.guidToBytes(value));
|
||||
}
|
||||
|
||||
BinaryList addGuid(Guid value)
|
||||
{
|
||||
_list.addAll(DC.guidToBytes(value));
|
||||
return this;
|
||||
}
|
||||
void insertGuid(int position, Guid value) {
|
||||
_list.insertAll(position, DC.guidToBytes(value));
|
||||
}
|
||||
|
||||
BinaryList insertGuid(int position, Guid value)
|
||||
{
|
||||
_list.insertAll(position, DC.guidToBytes(value));
|
||||
return this;
|
||||
}
|
||||
void addGuidArray(List<Guid> value) {
|
||||
_list.addAll(DC.guidArrayToBytes(value));
|
||||
}
|
||||
|
||||
BinaryList addGuidArray(List<Guid> value)
|
||||
{
|
||||
_list.addAll(DC.guidArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
void insertGuidArray(int position, List<Guid> value) {
|
||||
_list.insertAll(position, DC.guidArrayToBytes(value));
|
||||
}
|
||||
|
||||
BinaryList insertGuidArray(int position, List<Guid> value)
|
||||
{
|
||||
_list.insertAll(position, DC.guidArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
void addUint8Array(Uint8List value) {
|
||||
_list.addAll(value);
|
||||
}
|
||||
|
||||
void addDC(DC value) {
|
||||
_list.addAll(value.toArray());
|
||||
}
|
||||
|
||||
BinaryList addUint8Array(Uint8List value)
|
||||
{
|
||||
_list.addAll(value);
|
||||
return this;
|
||||
}
|
||||
void insertUint8Array(int position, Uint8List value) {
|
||||
_list.insertAll(position, value);
|
||||
}
|
||||
|
||||
BinaryList addDC(DC value)
|
||||
{
|
||||
_list.addAll(value.toArray());
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertUint8Array(int position, Uint8List value)
|
||||
{
|
||||
_list.insertAll(position, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
BinaryList addHex(String value)
|
||||
{
|
||||
return this.addUint8Array(DC.fromHex(value, null));
|
||||
@ -117,434 +91,316 @@ class BinaryList
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
BinaryList addString(String value)
|
||||
{
|
||||
_list.addAll(DC.stringToBytes(value));
|
||||
return this;
|
||||
void addString(String value) {
|
||||
_list.addAll(DC.stringToBytes(value));
|
||||
}
|
||||
|
||||
void insertString(int position, String value) {
|
||||
_list.insertAll(position, DC.stringToBytes(value));
|
||||
}
|
||||
|
||||
void addStringArray(List<String> value) {
|
||||
_list.addAll(DC.stringArrayToBytes(value));
|
||||
}
|
||||
|
||||
void insertStringArray(int position, List<String> value) {
|
||||
_list.insertAll(position, DC.stringArrayToBytes(value));
|
||||
}
|
||||
|
||||
void insertUint8(int position, int value) {
|
||||
_list.insert(position, value);
|
||||
}
|
||||
|
||||
void addUint8(int value) {
|
||||
_list.add(value);
|
||||
}
|
||||
|
||||
void addInt8(int value) {
|
||||
_list.add(value);
|
||||
}
|
||||
|
||||
void insertInt8(int position, int value) {
|
||||
_list.insert(position, value);
|
||||
}
|
||||
|
||||
void addInt8Array(Int8List value) {
|
||||
_list.addAll(DC.int8ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void insertInt8Array(int position, Int8List value) {
|
||||
_list.insertAll(position, DC.int8ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void addChar(int value) {
|
||||
_list.addAll(DC.charToBytes(value));
|
||||
}
|
||||
|
||||
void InsertChar(int position, int value) {
|
||||
_list.insertAll(position, DC.charToBytes(value));
|
||||
}
|
||||
|
||||
void addCharArray(Uint16List value) {
|
||||
_list.addAll(DC.charArrayToBytes(value));
|
||||
}
|
||||
|
||||
void InsertCharArray(int position, Uint16List value) {
|
||||
_list.insertAll(position, DC.charArrayToBytes(value));
|
||||
}
|
||||
|
||||
void addBoolean(bool value) {
|
||||
_list.addAll(DC.boolToBytes(value));
|
||||
}
|
||||
|
||||
void insertBoolean(int position, bool value) {
|
||||
_list.insertAll(position, DC.boolToBytes(value));
|
||||
}
|
||||
|
||||
void addBooleanArray(List<bool> value) {
|
||||
_list.addAll(DC.boolToBytes(value));
|
||||
}
|
||||
|
||||
void insertBooleanArray(int position, List<bool> value) {
|
||||
_list.insertAll(position, DC.boolToBytes(value));
|
||||
}
|
||||
|
||||
void addUint16(int value) {
|
||||
_list.addAll(DC.uint16ToBytes(value));
|
||||
}
|
||||
|
||||
void insertUint16(int position, int value) {
|
||||
_list.insertAll(position, DC.uint16ToBytes(value));
|
||||
}
|
||||
|
||||
void addUint16Array(Uint16List value) {
|
||||
_list.addAll(DC.uint16ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void insertUint16Array(int position, Uint16List value) {
|
||||
_list.insertAll(position, DC.uint16ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void addInt16(int value) {
|
||||
_list.addAll(DC.int16ToBytes(value));
|
||||
}
|
||||
|
||||
void insertInt16(int position, int value) {
|
||||
_list.insertAll(position, DC.int16ToBytes(value));
|
||||
}
|
||||
|
||||
void addInt16Array(Int16List value) {
|
||||
_list.addAll(DC.int16ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void insertInt16Array(int position, Int16List value) {
|
||||
_list.insertAll(position, DC.int16ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void addUint32(int value) {
|
||||
_list.addAll(DC.uint32ToBytes(value));
|
||||
}
|
||||
|
||||
void insertUint32(int position, int value) {
|
||||
_list.insertAll(position, DC.uint32ToBytes(value));
|
||||
}
|
||||
|
||||
void addUint32Array(Uint32List value) {
|
||||
_list.addAll(DC.uint32ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void InsertUint32Array(int position, Uint32List value) {
|
||||
_list.insertAll(position, DC.uint32ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void addInt32(int value) {
|
||||
_list.addAll(DC.int32ToBytes(value));
|
||||
}
|
||||
|
||||
void insertInt32(int position, int value) {
|
||||
_list.insertAll(position, DC.int32ToBytes(value));
|
||||
}
|
||||
|
||||
void addInt32Array(Int32List value) {
|
||||
_list.addAll(DC.int32ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void insertInt32Array(int position, Int32List value) {
|
||||
_list.insertAll(position, DC.int32ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void addUint64(int value) {
|
||||
_list.addAll(DC.uint64ToBytes(value));
|
||||
}
|
||||
|
||||
void insertUint64(int position, int value) {
|
||||
_list.insertAll(position, DC.uint64ToBytes(value));
|
||||
}
|
||||
|
||||
void addUint64Array(Uint64List value) {
|
||||
_list.addAll(DC.uint64ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void InsertUint64Array(int position, Uint64List value) {
|
||||
_list.insertAll(position, DC.uint64ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void addInt64(int value) {
|
||||
_list.addAll(DC.int64ToBytes(value));
|
||||
}
|
||||
|
||||
void insertInt64(int position, int value) {
|
||||
_list.insertAll(position, DC.int64ToBytes(value));
|
||||
}
|
||||
|
||||
void addInt64Array(Int64List value) {
|
||||
_list.addAll(DC.int64ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void insertInt64Array(int position, Int64List value) {
|
||||
_list.insertAll(position, DC.int64ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void addFloat32(double value) {
|
||||
_list.addAll(DC.float32ToBytes(value));
|
||||
}
|
||||
|
||||
void insertFloat32(int position, double value) {
|
||||
_list.insertAll(position, DC.float32ToBytes(value));
|
||||
}
|
||||
|
||||
void addFloat32Array(Float32List value) {
|
||||
_list.addAll(DC.float32ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void insertFloat32Array(int position, Float32List value) {
|
||||
_list.insertAll(position, DC.float32ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void addFloat64(double value) {
|
||||
_list.addAll(DC.float64ToBytes(value));
|
||||
}
|
||||
|
||||
void insertFloat64(int position, double value) {
|
||||
_list.insertAll(position, DC.float64ToBytes(value));
|
||||
}
|
||||
|
||||
void addFloat64Array(Float64List value) {
|
||||
_list.addAll(DC.float64ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void insertFloat64Array(int position, Float64List value) {
|
||||
_list.insertAll(position, DC.float64ArrayToBytes(value));
|
||||
}
|
||||
|
||||
void add(type, value) {
|
||||
switch (type) {
|
||||
case DataType.Bool:
|
||||
addBoolean(value);
|
||||
return;
|
||||
case DataType.BoolArray:
|
||||
addBooleanArray(value);
|
||||
return;
|
||||
case DataType.UInt8:
|
||||
addUint8(value);
|
||||
return;
|
||||
case DataType.UInt8Array:
|
||||
addUint8Array(value);
|
||||
return;
|
||||
case DataType.Int8:
|
||||
addInt8(value);
|
||||
return;
|
||||
case DataType.Int8Array:
|
||||
addInt8Array(value);
|
||||
return;
|
||||
case DataType.Char:
|
||||
addChar(value);
|
||||
return;
|
||||
case DataType.CharArray:
|
||||
addCharArray(value);
|
||||
return;
|
||||
case DataType.UInt16:
|
||||
addUint16(value);
|
||||
return;
|
||||
case DataType.UInt16Array:
|
||||
addUint16Array(value);
|
||||
return;
|
||||
case DataType.Int16:
|
||||
addInt16(value);
|
||||
return;
|
||||
case DataType.Int16Array:
|
||||
addInt16Array(value);
|
||||
return;
|
||||
case DataType.UInt32:
|
||||
addUint32(value);
|
||||
return;
|
||||
case DataType.UInt32Array:
|
||||
addUint32Array(value);
|
||||
return;
|
||||
case DataType.Int32:
|
||||
addInt32(value);
|
||||
return;
|
||||
case DataType.Int32Array:
|
||||
addInt32Array(value);
|
||||
return;
|
||||
case DataType.UInt64:
|
||||
addUint64(value);
|
||||
return;
|
||||
case DataType.UInt64Array:
|
||||
addUint64Array(value);
|
||||
return;
|
||||
case DataType.Int64:
|
||||
addInt64(value);
|
||||
return;
|
||||
case DataType.Int64Array:
|
||||
addInt64Array(value);
|
||||
return;
|
||||
|
||||
case DataType.Float32:
|
||||
addFloat32(value);
|
||||
return;
|
||||
case DataType.Float32Array:
|
||||
addFloat32Array(value);
|
||||
return;
|
||||
|
||||
case DataType.Float64:
|
||||
addFloat64(value);
|
||||
return;
|
||||
case DataType.Float64Array:
|
||||
addFloat64Array(value);
|
||||
return;
|
||||
|
||||
case DataType.String:
|
||||
addString(value);
|
||||
return;
|
||||
case DataType.StringArray:
|
||||
addStringArray(value);
|
||||
return;
|
||||
|
||||
case DataType.DateTime:
|
||||
addDateTime(value);
|
||||
return;
|
||||
case DataType.DateTimeArray:
|
||||
addDateTimeArray(value);
|
||||
return;
|
||||
|
||||
default:
|
||||
throw new Exception("Not Implemented " + type.ToString());
|
||||
//return this;
|
||||
}
|
||||
}
|
||||
|
||||
BinaryList insertString(int position, String value)
|
||||
{
|
||||
_list.insertAll(position, DC.stringToBytes(value));
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// Convert the _list to an array of bytes
|
||||
/// </summary>
|
||||
/// <returns>Bytes array</returns>
|
||||
Uint8List toArray() {
|
||||
return Uint8List.fromList(_list);
|
||||
}
|
||||
|
||||
BinaryList addStringArray(List<String> value)
|
||||
{
|
||||
_list.addAll(DC.stringArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
DC toDC() {
|
||||
return new DC.fromUint8Array(toArray());
|
||||
}
|
||||
|
||||
BinaryList insertStringArray(int position, List<String> value)
|
||||
{
|
||||
_list.insertAll(position, DC.stringArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertUint8(int position, int value)
|
||||
{
|
||||
_list.insert(position, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addUint8(int value)
|
||||
{
|
||||
_list.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addInt8(int value)
|
||||
{
|
||||
_list.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt8(int position, int value)
|
||||
{
|
||||
_list.insert(position, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addInt8Array(Int8List value)
|
||||
{
|
||||
_list.addAll(DC.int8ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt8Array(int position, Int8List value)
|
||||
{
|
||||
_list.insertAll(position, DC.int8ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addChar(int value)
|
||||
{
|
||||
_list.addAll(DC.charToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList InsertChar(int position, int value)
|
||||
{
|
||||
_list.insertAll(position, DC.charToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addCharArray(Uint16List value)
|
||||
{
|
||||
_list.addAll(DC.charArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList InsertCharArray(int position, Uint16List value)
|
||||
{
|
||||
_list.insertAll(position, DC.charArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addBoolean(bool value)
|
||||
{
|
||||
_list.addAll(DC.boolToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertBoolean(int position, bool value)
|
||||
{
|
||||
_list.insertAll(position, DC.boolToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addBooleanArray(List<bool> value)
|
||||
{
|
||||
_list.addAll(DC.boolToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertBooleanArray(int position, List<bool> value)
|
||||
{
|
||||
_list.insertAll(position, DC.boolToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addUint16(int value)
|
||||
{
|
||||
_list.addAll(DC.uint16ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertUint16(int position, int value)
|
||||
{
|
||||
_list.insertAll(position, DC.uint16ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addUint16Array(Uint16List value)
|
||||
{
|
||||
_list.addAll(DC.uint16ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertUint16Array(int position, Uint16List value)
|
||||
{
|
||||
_list.insertAll(position, DC.uint16ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addInt16(int value)
|
||||
{
|
||||
_list.addAll(DC.int16ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt16(int position, int value)
|
||||
{
|
||||
_list.insertAll(position, DC.int16ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addInt16Array(Int16List value)
|
||||
{
|
||||
_list.addAll(DC.int16ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt16Array(int position, Int16List value)
|
||||
{
|
||||
_list.insertAll(position, DC.int16ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addUint32(int value)
|
||||
{
|
||||
_list.addAll(DC.uint32ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertUint32(int position, int value)
|
||||
{
|
||||
_list.insertAll(position, DC.uint32ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addUint32Array(Uint32List value)
|
||||
{
|
||||
_list.addAll(DC.uint32ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
BinaryList InsertUint32Array(int position, Uint32List value)
|
||||
{
|
||||
_list.insertAll(position, DC.uint32ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addInt32(int value)
|
||||
{
|
||||
_list.addAll(DC.int32ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt32(int position, int value)
|
||||
{
|
||||
_list.insertAll(position, DC.int32ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addInt32Array(Int32List value)
|
||||
{
|
||||
_list.addAll(DC.int32ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt32Array(int position, Int32List value)
|
||||
{
|
||||
_list.insertAll(position, DC.int32ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addUint64(int value)
|
||||
{
|
||||
_list.addAll(DC.uint64ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertUint64(int position, int value)
|
||||
{
|
||||
_list.insertAll(position, DC.uint64ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addUint64Array(Uint64List value)
|
||||
{
|
||||
_list.addAll(DC.uint64ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList InsertUint64Array(int position, Uint64List value)
|
||||
{
|
||||
_list.insertAll(position, DC.uint64ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addInt64(int value)
|
||||
{
|
||||
_list.addAll(DC.int64ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt64(int position, int value)
|
||||
{
|
||||
_list.insertAll(position, DC.int64ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addInt64Array(Int64List value)
|
||||
{
|
||||
_list.addAll(DC.int64ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertInt64Array(int position, Int64List value)
|
||||
{
|
||||
_list.insertAll(position, DC.int64ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addFloat32(double value)
|
||||
{
|
||||
_list.addAll(DC.float32ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertFloat32(int position, double value)
|
||||
{
|
||||
_list.insertAll(position, DC.float32ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addFloat32Array(Float32List value)
|
||||
{
|
||||
_list.addAll(DC.float32ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertFloat32Array(int position, Float32List value)
|
||||
{
|
||||
_list.insertAll(position, DC.float32ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
BinaryList addFloat64(double value)
|
||||
{
|
||||
_list.addAll(DC.float64ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertFloat64(int position, double value)
|
||||
{
|
||||
_list.insertAll(position, DC.float64ToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList addFloat64Array(Float64List value)
|
||||
{
|
||||
_list.addAll(DC.float64ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
BinaryList insertFloat64Array(int position, Float64List value)
|
||||
{
|
||||
_list.insertAll(position, DC.float64ArrayToBytes(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
BinaryList add(type, value)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case DataType.Bool:
|
||||
addBoolean(value);
|
||||
return this;
|
||||
case DataType.BoolArray:
|
||||
addBooleanArray(value);
|
||||
return this;
|
||||
case DataType.UInt8:
|
||||
addUint8(value);
|
||||
return this;
|
||||
case DataType.UInt8Array:
|
||||
addUint8Array(value);
|
||||
return this;
|
||||
case DataType.Int8:
|
||||
addInt8(value);
|
||||
return this;
|
||||
case DataType.Int8Array:
|
||||
addInt8Array(value);
|
||||
return this;
|
||||
case DataType.Char:
|
||||
addChar(value);
|
||||
return this;
|
||||
case DataType.CharArray:
|
||||
addCharArray(value);
|
||||
return this;
|
||||
case DataType.UInt16:
|
||||
addUint16(value);
|
||||
return this;
|
||||
case DataType.UInt16Array:
|
||||
addUint16Array(value);
|
||||
return this;
|
||||
case DataType.Int16:
|
||||
addInt16(value);
|
||||
return this;
|
||||
case DataType.Int16Array:
|
||||
addInt16Array(value);
|
||||
return this;
|
||||
case DataType.UInt32:
|
||||
addUint32(value);
|
||||
return this;
|
||||
case DataType.UInt32Array:
|
||||
addUint32Array(value);
|
||||
return this;
|
||||
case DataType.Int32:
|
||||
addInt32(value);
|
||||
return this;
|
||||
case DataType.Int32Array:
|
||||
addInt32Array(value);
|
||||
return this;
|
||||
case DataType.UInt64:
|
||||
addUint64(value);
|
||||
return this;
|
||||
case DataType.UInt64Array:
|
||||
addUint64Array(value);
|
||||
return this;
|
||||
case DataType.Int64:
|
||||
addInt64(value);
|
||||
return this;
|
||||
case DataType.Int64Array:
|
||||
addInt64Array(value);
|
||||
return this;
|
||||
|
||||
case DataType.Float32:
|
||||
addFloat32(value);
|
||||
return this;
|
||||
case DataType.Float32Array:
|
||||
addFloat32Array(value);
|
||||
return this;
|
||||
|
||||
case DataType.Float64:
|
||||
addFloat64(value);
|
||||
return this;
|
||||
case DataType.Float64Array:
|
||||
addFloat64Array(value);
|
||||
return this;
|
||||
|
||||
case DataType.String:
|
||||
addString(value);
|
||||
return this;
|
||||
case DataType.StringArray:
|
||||
addStringArray(value);
|
||||
return this;
|
||||
|
||||
case DataType.DateTime:
|
||||
addDateTime(value);
|
||||
return this;
|
||||
case DataType.DateTimeArray:
|
||||
addDateTimeArray(value);
|
||||
return this;
|
||||
|
||||
default:
|
||||
throw new Exception("Not Implemented " + type.ToString());
|
||||
//return this;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Convert the _list to an array of bytes
|
||||
/// </summary>
|
||||
/// <returns>Bytes array</returns>
|
||||
Uint8List toArray()
|
||||
{
|
||||
return Uint8List.fromList(_list);
|
||||
}
|
||||
|
||||
|
||||
DC toDC()
|
||||
{
|
||||
return new DC.fromUint8Array(toArray());
|
||||
}
|
||||
|
||||
|
||||
AsyncReply<dynamic> done()
|
||||
{
|
||||
return null;
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
AsyncReply<dynamic> done() {
|
||||
return AsyncReply.ready(null);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
import '../Core/AsyncException.dart';
|
||||
import '../Core/ErrorType.dart';
|
||||
import '../Core/ExceptionCode.dart';
|
||||
|
||||
import '../Resource/Template/TemplateType.dart';
|
||||
|
||||
import 'DataType.dart';
|
||||
@ -93,7 +98,7 @@ class Codec {
|
||||
/// <param name="next">Next structure to compare with the initial</param>
|
||||
/// <param name="connection">DistributedConnection is required in case a structure holds items at the other end</param>
|
||||
static int compareStructures(
|
||||
Structure initial, Structure next, DistributedConnection connection) {
|
||||
Structure? initial, Structure? next, DistributedConnection connection) {
|
||||
if (next == null) return StructureComparisonResult.Null;
|
||||
|
||||
if (initial == null) return StructureComparisonResult.Structure;
|
||||
@ -126,7 +131,7 @@ class Codec {
|
||||
/// <param name="initial">Initial record to compare with</param>
|
||||
/// <param name="next">Next record to compare with the initial</param>
|
||||
/// <param name="connection">DistributedConnection is required in case a structure holds items at the other end</param>
|
||||
static int compareRecords(IRecord initial, IRecord next) {
|
||||
static int compareRecords(IRecord? initial, IRecord? next) {
|
||||
if (next == null) return RecordComparisonResult.Null;
|
||||
|
||||
if (initial == null) return RecordComparisonResult.Record;
|
||||
@ -139,9 +144,9 @@ class Codec {
|
||||
return RecordComparisonResult.Record;
|
||||
}
|
||||
|
||||
static AsyncBag parseRecordArray(
|
||||
static AsyncBag<IRecord?> parseRecordArray(
|
||||
DC data, int offset, int length, DistributedConnection connection) {
|
||||
var reply = new AsyncBag();
|
||||
var reply = new AsyncBag<IRecord?>();
|
||||
|
||||
if (length == 0) {
|
||||
reply.seal();
|
||||
@ -161,12 +166,12 @@ class Codec {
|
||||
var template =
|
||||
Warehouse.getTemplateByClassId(classId, TemplateType.Record);
|
||||
|
||||
reply.arrayType = template.definedType;
|
||||
reply.arrayType = template?.definedType;
|
||||
|
||||
AsyncReply<IRecord> previous = null;
|
||||
AsyncReply<IRecord?>? previous = null;
|
||||
|
||||
if (result == RecordComparisonResult.Null)
|
||||
previous = new AsyncReply<IRecord>.ready(null);
|
||||
previous = AsyncReply<IRecord?>.ready(null);
|
||||
else if (result == RecordComparisonResult.Record ||
|
||||
result == RecordComparisonResult.RecordSameType) {
|
||||
var cs = data.getUint32(offset);
|
||||
@ -176,13 +181,13 @@ class Codec {
|
||||
offset += recordLength;
|
||||
}
|
||||
|
||||
reply.add(previous);
|
||||
reply.add(previous as AsyncReply<IRecord?>);
|
||||
|
||||
while (offset < end) {
|
||||
result = data[offset++];
|
||||
|
||||
if (result == RecordComparisonResult.Null)
|
||||
previous = new AsyncReply<IRecord>.ready(null);
|
||||
previous = new AsyncReply<IRecord?>.ready(null);
|
||||
else if (result == RecordComparisonResult.Record ||
|
||||
result == RecordComparisonResult.RecordSameType) {
|
||||
var cs = data.getUint32(offset);
|
||||
@ -193,14 +198,14 @@ class Codec {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
reply.add(previous);
|
||||
reply.add(previous as AsyncReply<IRecord?>);
|
||||
}
|
||||
} else {
|
||||
AsyncReply<IRecord> previous = null;
|
||||
Guid classId = null;
|
||||
AsyncReply<IRecord?>? previous = null;
|
||||
Guid? classId = null;
|
||||
|
||||
if (result == RecordComparisonResult.Null)
|
||||
previous = new AsyncReply<IRecord>.ready(null);
|
||||
previous = new AsyncReply<IRecord?>.ready(null);
|
||||
else if (result == RecordComparisonResult.Record) {
|
||||
var cs = data.getUint32(offset);
|
||||
var recordLength = cs - 16;
|
||||
@ -211,13 +216,13 @@ class Codec {
|
||||
offset += recordLength;
|
||||
}
|
||||
|
||||
reply.add(previous);
|
||||
reply.add(previous as AsyncReply<IRecord?>);
|
||||
|
||||
while (offset < end) {
|
||||
result = data[offset++];
|
||||
|
||||
if (result == RecordComparisonResult.Null)
|
||||
previous = new AsyncReply<IRecord>.ready(null);
|
||||
previous = new AsyncReply<IRecord?>.ready(null);
|
||||
else if (result == RecordComparisonResult.Record) {
|
||||
var cs = data.getUint32(offset);
|
||||
var recordLength = cs - 16;
|
||||
@ -236,7 +241,7 @@ class Codec {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
reply.add(previous);
|
||||
reply.add(previous as AsyncReply<IRecord?>);
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,7 +306,7 @@ class Codec {
|
||||
|
||||
static AsyncReply<IRecord> parseRecord(
|
||||
DC data, int offset, int length, DistributedConnection connection,
|
||||
[Guid classId = null]) {
|
||||
[Guid? classId = null]) {
|
||||
var reply = new AsyncReply<IRecord>();
|
||||
|
||||
if (classId == null) {
|
||||
@ -317,7 +322,7 @@ class Codec {
|
||||
parseVarArray(data, offset, length, connection).then((ar) {
|
||||
if (template.definedType != null) {
|
||||
var record =
|
||||
Warehouse.createInstance(template.definedType) as IRecord;
|
||||
Warehouse.createInstance(template.definedType as Type) as IRecord;
|
||||
|
||||
Map<String, dynamic> value = {};
|
||||
|
||||
@ -337,16 +342,24 @@ class Codec {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
connection.getTemplate(classId).then<dynamic>((tmp) {
|
||||
parseVarArray(data, offset, length, connection).then<dynamic>((ar) {
|
||||
var record = new Record();
|
||||
connection.getTemplate(classId)
|
||||
..then((tmp) {
|
||||
if (tmp != null) {
|
||||
parseVarArray(data, offset, length, connection)
|
||||
..then((ar) {
|
||||
var record = new Record();
|
||||
|
||||
for (var i = 0; i < tmp.properties.length; i++)
|
||||
record.add(tmp.properties[i].name, ar[i]);
|
||||
for (var i = 0; i < tmp.properties.length; i++)
|
||||
record.add(tmp.properties[i].name, ar[i]);
|
||||
|
||||
reply.trigger(record);
|
||||
});
|
||||
}).error((x) => reply.triggerError(x));
|
||||
reply.trigger(record);
|
||||
});
|
||||
} else {
|
||||
reply.triggerError(AsyncException(ErrorType.Management,
|
||||
ExceptionCode.TemplateNotFound.index, null));
|
||||
}
|
||||
})
|
||||
..error((x) => reply.triggerError(x));
|
||||
}
|
||||
|
||||
return reply;
|
||||
@ -377,9 +390,9 @@ class Codec {
|
||||
}
|
||||
|
||||
static DC composeRecordArray<T extends IRecord>(
|
||||
List<T> records, DistributedConnection connection,
|
||||
List<T>? records, DistributedConnection connection,
|
||||
[bool prependLength = false]) {
|
||||
if (records == null || records?.length == 0)
|
||||
if (records == null || records.length == 0)
|
||||
return prependLength ? new DC(4) : new DC(0);
|
||||
|
||||
var rt = new BinaryList();
|
||||
@ -391,14 +404,14 @@ class Codec {
|
||||
if (isTyped) {
|
||||
var template = Warehouse.getTemplateByType(T);
|
||||
|
||||
if (template != null) {
|
||||
// typed array ... no need to add class id , it will be included at the first entry
|
||||
rt.addUint8(0x10 | comparsion);
|
||||
rt.addGuid(template.classId);
|
||||
} else // something wrong
|
||||
{
|
||||
throw new Exception("Template for type `${T}` not found.");
|
||||
}
|
||||
//if (template != null) {
|
||||
// typed array ... no need to add class id , it will be included at the first entry
|
||||
rt.addUint8(0x10 | comparsion);
|
||||
rt.addGuid(template.classId);
|
||||
//} else // something wrong
|
||||
//{
|
||||
// throw new Exception("Template for type `${T}` not found.");
|
||||
//}
|
||||
|
||||
if (comparsion == RecordComparisonResult.Record)
|
||||
rt.addDC(composeRecord(records[0], connection, false, true));
|
||||
@ -468,17 +481,17 @@ class Codec {
|
||||
/// <param name="prependLength">If true, prepend the length as UInt32 at the beginning of the returned bytes array</param>
|
||||
/// <returns>Array of bytes in the network byte order</returns>
|
||||
static DC composeStructureArray(
|
||||
List<Structure> structures, DistributedConnection connection,
|
||||
List<Structure>? structures, DistributedConnection connection,
|
||||
[bool prependLength = false]) {
|
||||
if (structures == null || structures?.length == 0)
|
||||
if (structures == null || structures.length == 0)
|
||||
return prependLength ? new DC(4) : new DC(0);
|
||||
|
||||
var rt = new BinaryList();
|
||||
var comparsion = StructureComparisonResult.Structure;
|
||||
|
||||
rt
|
||||
.addUint8(comparsion)
|
||||
.addDC(composeStructure(structures[0], connection, true, true, true));
|
||||
..addUint8(comparsion)
|
||||
..addDC(composeStructure(structures[0], connection, true, true, true));
|
||||
|
||||
for (var i = 1; i < structures.length; i++) {
|
||||
comparsion =
|
||||
@ -508,9 +521,9 @@ class Codec {
|
||||
/// <param name="length">Number of bytes to parse</param>
|
||||
/// <param name="connection">DistributedConnection is required in case a structure in the array holds items at the other end</param>
|
||||
/// <returns>Array of structures</returns>
|
||||
static AsyncBag<Structure> parseStructureArray(
|
||||
static AsyncBag<Structure?> parseStructureArray(
|
||||
DC data, int offset, int length, DistributedConnection connection) {
|
||||
var reply = new AsyncBag<Structure>();
|
||||
var reply = new AsyncBag<Structure?>();
|
||||
if (length == 0) {
|
||||
reply.seal();
|
||||
return reply;
|
||||
@ -520,14 +533,14 @@ class Codec {
|
||||
|
||||
var result = data[offset++];
|
||||
|
||||
AsyncReply<Structure> previous = null;
|
||||
AsyncReply<Structure?>? previous = null;
|
||||
// string[] previousKeys = null;
|
||||
// DataType[] previousTypes = null;
|
||||
|
||||
StructureMetadata metadata = new StructureMetadata();
|
||||
|
||||
if (result == StructureComparisonResult.Null)
|
||||
previous = new AsyncReply<Structure>.ready(null);
|
||||
previous = new AsyncReply<Structure?>.ready(null);
|
||||
else if (result == StructureComparisonResult.Structure) {
|
||||
int cs = data.getUint32(offset);
|
||||
offset += 4;
|
||||
@ -535,13 +548,13 @@ class Codec {
|
||||
offset += cs;
|
||||
}
|
||||
|
||||
reply.add(previous);
|
||||
reply.add(previous as AsyncReply<Structure?>);
|
||||
|
||||
while (offset < end) {
|
||||
result = data[offset++];
|
||||
|
||||
if (result == StructureComparisonResult.Null)
|
||||
previous = new AsyncReply<Structure>.ready(null);
|
||||
previous = new AsyncReply<Structure?>.ready(null);
|
||||
else if (result == StructureComparisonResult.Structure) {
|
||||
int cs = data.getUint32(offset);
|
||||
offset += 4;
|
||||
@ -562,7 +575,7 @@ class Codec {
|
||||
offset += cs;
|
||||
}
|
||||
|
||||
reply.add(previous);
|
||||
reply.add(previous as AsyncReply<Structure?>);
|
||||
}
|
||||
|
||||
reply.seal();
|
||||
@ -587,7 +600,10 @@ class Codec {
|
||||
if (includeKeys) {
|
||||
for (var k in value.keys) {
|
||||
var key = DC.stringToBytes(k);
|
||||
rt.addUint8(key.length).addDC(key).addDC(compose(value[k], connection));
|
||||
rt
|
||||
..addUint8(key.length)
|
||||
..addDC(key)
|
||||
..addDC(compose(value[k], connection));
|
||||
}
|
||||
} else {
|
||||
for (var k in value.keys)
|
||||
@ -613,9 +629,9 @@ class Codec {
|
||||
/// <returns>Structure</returns>
|
||||
static AsyncReply<Structure> parseStructure(
|
||||
DC data, int offset, int length, DistributedConnection connection,
|
||||
[StructureMetadata metadata = null,
|
||||
List<String> keys = null,
|
||||
List<int> types =
|
||||
[StructureMetadata? metadata = null,
|
||||
List<String>? keys = null,
|
||||
List<int>? types =
|
||||
null]) // out string[] parsedKeys, out DataType[] parsedTypes, string[] keys = null, DataType[] types = null)
|
||||
{
|
||||
var reply = new AsyncReply<Structure>();
|
||||
@ -685,9 +701,8 @@ class Codec {
|
||||
/// <param name="connection">DistributedConnection is required in case a structure in the array holds items at the other end.</param>
|
||||
/// <param name="dataType">DataType, in case the data is not prepended with DataType</param>
|
||||
/// <returns>Value</returns>
|
||||
static AsyncReply<dynamic> parse(
|
||||
DC data, int offset, DistributedConnection connection,
|
||||
[SizeObject sizeObject, int dataType = DataType.Unspecified]) {
|
||||
static AsyncReply parse(DC data, int offset, DistributedConnection connection,
|
||||
[SizeObject? sizeObject, int dataType = DataType.Unspecified]) {
|
||||
bool isArray;
|
||||
int t;
|
||||
|
||||
@ -850,7 +865,8 @@ class Codec {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
// @TODO: Throw exception
|
||||
return AsyncReply.ready(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -859,8 +875,8 @@ class Codec {
|
||||
/// <param name="data">Bytes array</param>
|
||||
/// <param name="offset">Zero-indexed offset.</param>
|
||||
/// <returns>Resource</returns>
|
||||
static AsyncReply<IResource> parseResource(DC data, int offset) {
|
||||
return Warehouse.get(data.getUint32(offset));
|
||||
static AsyncReply<IResource?> parseResource(DC data, int offset) {
|
||||
return Warehouse.getById(data.getUint32(offset));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -904,7 +920,7 @@ class Codec {
|
||||
/// <returns>Null, same, local, distributed or same class distributed.</returns>
|
||||
|
||||
static int compareResources(
|
||||
IResource initial, IResource next, DistributedConnection connection) {
|
||||
IResource? initial, IResource? next, DistributedConnection connection) {
|
||||
if (next == null)
|
||||
return ResourceComparisonResult.Null;
|
||||
else if (next == initial)
|
||||
@ -924,13 +940,12 @@ class Codec {
|
||||
static DC composeResource(
|
||||
IResource resource, DistributedConnection connection) {
|
||||
if (isLocalResource(resource, connection))
|
||||
return DC.uint32ToBytes((resource as DistributedResource).id);
|
||||
return DC.uint32ToBytes((resource as DistributedResource).id as int);
|
||||
else {
|
||||
return new BinaryList()
|
||||
.addGuid(resource.instance.template.classId)
|
||||
.addUint32(resource.instance.id)
|
||||
return (BinaryList()
|
||||
..addGuid(resource.instance?.template.classId as Guid)
|
||||
..addUint32(resource.instance?.id as int))
|
||||
.toDC();
|
||||
//return BinaryList.ToBytes(resource.Instance.Template.ClassId, resource.Instance.Id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -943,9 +958,9 @@ class Codec {
|
||||
/// <returns>Array of bytes in the network byte order.</returns>
|
||||
|
||||
static DC composeResourceArray<T extends IResource>(
|
||||
List<T> resources, DistributedConnection connection,
|
||||
List<T>? resources, DistributedConnection connection,
|
||||
[bool prependLength = false]) {
|
||||
if (resources == null || resources?.length == 0)
|
||||
if (resources == null || resources.length == 0)
|
||||
return prependLength ? new DC(4) : new DC(0);
|
||||
|
||||
var rt = new BinaryList();
|
||||
@ -971,17 +986,17 @@ class Codec {
|
||||
}
|
||||
|
||||
if (comparsion == ResourceComparisonResult.Local)
|
||||
rt.addUint32((resources[0] as DistributedResource).id);
|
||||
rt.addUint32((resources[0] as DistributedResource).id as int);
|
||||
else if (comparsion == ResourceComparisonResult.Distributed)
|
||||
rt.addUint32(resources[0].instance.id);
|
||||
rt.addUint32(resources[0].instance?.id as int);
|
||||
|
||||
for (var i = 1; i < resources.length; i++) {
|
||||
comparsion = compareResources(resources[i - 1], resources[i], connection);
|
||||
rt.addUint8(comparsion);
|
||||
if (comparsion == ResourceComparisonResult.Local)
|
||||
rt.addUint32((resources[i] as DistributedResource).id);
|
||||
rt.addUint32((resources[i] as DistributedResource).id as int);
|
||||
else if (comparsion == ResourceComparisonResult.Distributed)
|
||||
rt.addUint32(resources[i].instance.id);
|
||||
rt.addUint32(resources[i].instance?.id as int);
|
||||
}
|
||||
|
||||
if (prependLength) rt.insertInt32(0, rt.length);
|
||||
@ -997,11 +1012,11 @@ class Codec {
|
||||
/// <param name="offset">Zero-indexed offset.</param>
|
||||
/// <param name="connection">DistributedConnection is required to fetch resources.</param>
|
||||
/// <returns>Array of resources.</returns>
|
||||
static AsyncBag<IResource> parseResourceArray(
|
||||
static AsyncBag<IResource?> parseResourceArray(
|
||||
DC data, int offset, int length, DistributedConnection connection) {
|
||||
//print("parseResourceArray ${offset} ${length}");
|
||||
|
||||
var reply = new AsyncBag<IResource>();
|
||||
var reply = new AsyncBag<IResource?>();
|
||||
if (length == 0) {
|
||||
reply.seal();
|
||||
return reply;
|
||||
@ -1031,27 +1046,27 @@ class Codec {
|
||||
reply.arrayType = tmp?.definedType;
|
||||
}
|
||||
|
||||
AsyncReply<IResource> previous = null;
|
||||
AsyncReply<IResource?>? previous = null;
|
||||
|
||||
if (result == ResourceComparisonResult.Null)
|
||||
previous = new AsyncReply<IResource>.ready(null);
|
||||
previous = new AsyncReply<IResource?>.ready(null);
|
||||
else if (result == ResourceComparisonResult.Local) {
|
||||
previous = Warehouse.get(data.getUint32(offset));
|
||||
previous = Warehouse.getById(data.getUint32(offset));
|
||||
offset += 4;
|
||||
} else if (result == ResourceComparisonResult.Distributed) {
|
||||
previous = connection.fetch(data.getUint32(offset));
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
reply.add(previous);
|
||||
reply.add(previous as AsyncReply<IResource?>);
|
||||
|
||||
while (offset < end) {
|
||||
result = data[offset++];
|
||||
|
||||
AsyncReply<IResource> current = null;
|
||||
AsyncReply<IResource?>? current = null;
|
||||
|
||||
if (result == ResourceComparisonResult.Null) {
|
||||
current = new AsyncReply<IResource>.ready(null);
|
||||
current = new AsyncReply<IResource?>.ready(null);
|
||||
} else if (result == ResourceComparisonResult.Same) {
|
||||
current = previous;
|
||||
} else if (result == ResourceComparisonResult.Local) {
|
||||
@ -1062,7 +1077,7 @@ class Codec {
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
reply.add(current);
|
||||
reply.add(current as AsyncReply<IResource?>);
|
||||
|
||||
previous = current;
|
||||
}
|
||||
@ -1146,10 +1161,10 @@ class Codec {
|
||||
static DC composePropertyValue(PropertyValue propertyValue,
|
||||
DistributedConnection connection) //, bool includeAge = true)
|
||||
{
|
||||
return new BinaryList()
|
||||
.addUint64(propertyValue.age)
|
||||
.addDateTime(propertyValue.date)
|
||||
.addDC(compose(propertyValue.value, connection))
|
||||
return (BinaryList()
|
||||
..addUint64(propertyValue.age)
|
||||
..addDateTime(propertyValue.date)
|
||||
..addDC(compose(propertyValue.value, connection)))
|
||||
.toDC();
|
||||
}
|
||||
|
||||
@ -1194,7 +1209,8 @@ class Codec {
|
||||
static AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>>
|
||||
parseHistory(DC data, int offset, int length, IResource resource,
|
||||
DistributedConnection connection) {
|
||||
var list = new KeyList<PropertyTemplate, List<PropertyValue>>();
|
||||
var list = <
|
||||
PropertyTemplate>[]; //new KeyList<PropertyTemplate, List<PropertyValue>?>();
|
||||
|
||||
var reply =
|
||||
new AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>>();
|
||||
@ -1207,20 +1223,26 @@ class Codec {
|
||||
|
||||
while (offset < ends) {
|
||||
var index = data[offset++];
|
||||
var pt = resource.instance.template.getPropertyTemplateByIndex(index);
|
||||
list.add(pt, null);
|
||||
var cs = data.getUint32(offset);
|
||||
offset += 4;
|
||||
bagOfBags.add(parsePropertyValueArray(data, offset, cs, connection));
|
||||
offset += cs;
|
||||
var pt = resource.instance?.template.getPropertyTemplateByIndex(index);
|
||||
if (pt != null) {
|
||||
list.add(pt); //, null);
|
||||
var cs = data.getUint32(offset);
|
||||
offset += 4;
|
||||
bagOfBags.add(parsePropertyValueArray(data, offset, cs, connection));
|
||||
offset += cs;
|
||||
}
|
||||
}
|
||||
|
||||
bagOfBags.seal();
|
||||
|
||||
bagOfBags.then((x) {
|
||||
for (var i = 0; i < list.length; i++) list[list.keys.elementAt(i)] = x[i];
|
||||
var keyList = KeyList<PropertyTemplate, List<PropertyValue>>();
|
||||
|
||||
reply.trigger(list);
|
||||
for (var i = 0; i < list.length; i++) keyList.add(list[i], x[i]);
|
||||
|
||||
//list[list.keys.elementAt(i)] = x[i];
|
||||
|
||||
reply.trigger(keyList);
|
||||
});
|
||||
|
||||
return reply;
|
||||
@ -1239,9 +1261,10 @@ class Codec {
|
||||
var rt = new BinaryList();
|
||||
|
||||
for (var i = 0; i < history.length; i++)
|
||||
rt.addUint8(history.keys.elementAt(i).index).addDC(
|
||||
composePropertyValueArray(
|
||||
history.values.elementAt(i), connection, true));
|
||||
rt
|
||||
..addUint8(history.keys.elementAt(i).index)
|
||||
..addDC(composePropertyValueArray(
|
||||
history.values.elementAt(i), connection, true));
|
||||
|
||||
if (prependLength) rt.insertInt32(0, rt.length);
|
||||
|
||||
@ -1292,7 +1315,7 @@ class Codec {
|
||||
if (value is Function(DistributedConnection))
|
||||
value = Function.apply(value, [connection]);
|
||||
else if (value is DistributedPropertyContext)
|
||||
value = (value as DistributedPropertyContext).method(connection);
|
||||
value = value.method?.call(connection);
|
||||
|
||||
var type = getDataType(value, connection);
|
||||
var rt = new BinaryList();
|
||||
@ -1304,15 +1327,17 @@ class Codec {
|
||||
|
||||
case DataType.String:
|
||||
var st = DC.stringToBytes(value);
|
||||
rt.addInt32(st.length).addDC(st);
|
||||
rt
|
||||
..addInt32(st.length)
|
||||
..addDC(st);
|
||||
break;
|
||||
|
||||
case DataType.Resource:
|
||||
rt.addUint32((value as DistributedResource).id);
|
||||
rt.addUint32((value as DistributedResource).id as int);
|
||||
break;
|
||||
|
||||
case DataType.DistributedResource:
|
||||
rt.addUint32((value as IResource).instance.id);
|
||||
rt.addUint32((value as IResource).instance?.id as int);
|
||||
break;
|
||||
|
||||
case DataType.Structure:
|
||||
|
@ -34,8 +34,8 @@ const UNIX_EPOCH = 621355968000000000;
|
||||
const TWO_PWR_32 = (1 << 16) * (1 << 16);
|
||||
|
||||
class DC with IterableMixin<int> {
|
||||
Uint8List _data;
|
||||
ByteData _dv;
|
||||
late Uint8List _data;
|
||||
late ByteData _dv;
|
||||
|
||||
DC(int length) {
|
||||
_data = new Uint8List(length);
|
||||
@ -245,7 +245,8 @@ class DC with IterableMixin<int> {
|
||||
var list = new BinaryList();
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
var s = DC.stringToBytes(value[i]);
|
||||
list.addUint32(s.length).addUint8Array(s.toArray());
|
||||
list..addUint32(s.length)
|
||||
..addUint8Array(s.toArray());
|
||||
}
|
||||
|
||||
return list.toDC();
|
||||
@ -289,67 +290,67 @@ class DC with IterableMixin<int> {
|
||||
Uint8List.fromList(_data.getRange(offset, offset + length).toList()));
|
||||
}
|
||||
|
||||
getInt8(int offset) {
|
||||
int getInt8(int offset) {
|
||||
return _dv.getInt8(offset);
|
||||
}
|
||||
|
||||
getUint8(int offset) {
|
||||
int getUint8(int offset) {
|
||||
return _data[offset]; // this.dv.getUint8(offset);
|
||||
}
|
||||
|
||||
getInt16(int offset) {
|
||||
int getInt16(int offset) {
|
||||
return _dv.getInt16(offset);
|
||||
}
|
||||
|
||||
getUint16(int offset) {
|
||||
int getUint16(int offset) {
|
||||
return _dv.getUint16(offset);
|
||||
}
|
||||
|
||||
getInt32(int offset) {
|
||||
int getInt32(int offset) {
|
||||
return _dv.getInt32(offset);
|
||||
}
|
||||
|
||||
getUint32(int offset) {
|
||||
int getUint32(int offset) {
|
||||
return _dv.getUint32(offset);
|
||||
}
|
||||
|
||||
getFloat32(int offset) {
|
||||
double getFloat32(int offset) {
|
||||
return _dv.getFloat32(offset);
|
||||
}
|
||||
|
||||
getFloat64(int offset) {
|
||||
double getFloat64(int offset) {
|
||||
return _dv.getFloat64(offset);
|
||||
}
|
||||
|
||||
setInt8(int offset, int value) {
|
||||
void setInt8(int offset, int value) {
|
||||
return _dv.setInt8(offset, value);
|
||||
}
|
||||
|
||||
setUint8(int offset, int value) {
|
||||
void setUint8(int offset, int value) {
|
||||
return _dv.setUint8(offset, value);
|
||||
}
|
||||
|
||||
setInt16(int offset, int value) {
|
||||
void setInt16(int offset, int value) {
|
||||
return _dv.setInt16(offset, value);
|
||||
}
|
||||
|
||||
setUint16(int offset, int value) {
|
||||
void setUint16(int offset, int value) {
|
||||
return _dv.setUint16(offset, value);
|
||||
}
|
||||
|
||||
setInt32(int offset, int value) {
|
||||
void setInt32(int offset, int value) {
|
||||
return _dv.setInt32(offset, value);
|
||||
}
|
||||
|
||||
setUint32(int offset, int value) {
|
||||
void setUint32(int offset, int value) {
|
||||
return _dv.setUint32(offset, value);
|
||||
}
|
||||
|
||||
setFloat32(int offset, double value) {
|
||||
void setFloat32(int offset, double value) {
|
||||
return _dv.setFloat32(offset, value);
|
||||
}
|
||||
|
||||
setFloat64(int offset, double value) {
|
||||
void setFloat64(int offset, double value) {
|
||||
return _dv.setFloat64(offset, value);
|
||||
}
|
||||
|
||||
@ -397,7 +398,7 @@ class DC with IterableMixin<int> {
|
||||
return this.getUint8(offset) > 0;
|
||||
}
|
||||
|
||||
setBoolean(int offset, bool value) {
|
||||
void setBoolean(int offset, bool value) {
|
||||
this.setUint8(offset, value ? 1 : 0);
|
||||
}
|
||||
|
||||
@ -411,7 +412,7 @@ class DC with IterableMixin<int> {
|
||||
return String.fromCharCode(this.getUint16(offset));
|
||||
}
|
||||
|
||||
setChar(int offset, int value) {
|
||||
void setChar(int offset, int value) {
|
||||
this.setUint16(offset, value); //value.codeUnitAt(0));
|
||||
}
|
||||
|
||||
@ -462,11 +463,11 @@ class DC with IterableMixin<int> {
|
||||
return rt;
|
||||
}
|
||||
|
||||
getInt64(offset) {
|
||||
int getInt64(offset) {
|
||||
return _dv.getUint64(offset);
|
||||
}
|
||||
|
||||
getUint64(offset) {
|
||||
int getUint64(offset) {
|
||||
return _dv.getInt64(offset);
|
||||
}
|
||||
|
||||
@ -478,7 +479,7 @@ class DC with IterableMixin<int> {
|
||||
_dv.setUint64(offset, value);
|
||||
}
|
||||
|
||||
setDateTime(offset, DateTime value) {
|
||||
void setDateTime(offset, DateTime value) {
|
||||
// Unix Epoch
|
||||
var ticks = UNIX_EPOCH + (value.millisecondsSinceEpoch * 10000);
|
||||
this.setUint64(offset, ticks);
|
||||
@ -500,7 +501,7 @@ class DC with IterableMixin<int> {
|
||||
return new Guid(this.clip(offset, 16));
|
||||
}
|
||||
|
||||
setGuid(int offset, Guid guid) {
|
||||
void setGuid(int offset, Guid guid) {
|
||||
set(guid.value, offset);
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,8 @@ import 'DC.dart';
|
||||
class Guid {
|
||||
DC _data;
|
||||
|
||||
Guid(DC data) {
|
||||
_data = data;
|
||||
Guid(this._data) {
|
||||
|
||||
}
|
||||
|
||||
DC get value => _data;
|
||||
|
@ -43,9 +43,9 @@ class KeyList<KT, T> extends IEventHandler with MapMixin<KT, T> {
|
||||
|
||||
at(int index) => _map.values.elementAt(index);
|
||||
|
||||
bool _removableList;
|
||||
late bool _removableList;
|
||||
|
||||
T take(KT key) {
|
||||
T? take(KT key) {
|
||||
if (_map.containsKey(key)) {
|
||||
var v = _map[key];
|
||||
remove(key);
|
||||
@ -89,20 +89,20 @@ class KeyList<KT, T> extends IEventHandler with MapMixin<KT, T> {
|
||||
clear() {
|
||||
if (_removableList)
|
||||
for (var v in _map.values)
|
||||
(v as IDestructible)?.off("destroy", _itemDestroyed);
|
||||
(v as IDestructible).off("destroy", _itemDestroyed);
|
||||
|
||||
_map.clear();
|
||||
|
||||
emitArgs("cleared", [this]);
|
||||
}
|
||||
|
||||
T remove(key) {
|
||||
T? remove(key) {
|
||||
if (!_map.containsKey(key)) return null;
|
||||
|
||||
var value = _map[key];
|
||||
|
||||
if (_removableList)
|
||||
(value as IDestructible)?.off("destroy", _itemDestroyed);
|
||||
(value as IDestructible).off("destroy", _itemDestroyed);
|
||||
|
||||
_map.remove(key);
|
||||
|
||||
|
@ -4,7 +4,7 @@ import 'IRecord.dart';
|
||||
import 'KeyList.dart';
|
||||
|
||||
class Record extends KeyList with IRecord {
|
||||
Map<String, dynamic> _props;
|
||||
Map<String, dynamic> _props = Map<String, dynamic>();
|
||||
|
||||
@override
|
||||
Map<String, dynamic> serialize() {
|
||||
|
@ -1,4 +1,3 @@
|
||||
class SizeObject
|
||||
{
|
||||
int size;
|
||||
}
|
||||
class SizeObject {
|
||||
int size = 0;
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
class StructureMetadata
|
||||
{
|
||||
class StructureMetadata {
|
||||
List<String>? keys; // = <String>[];
|
||||
List<int>? types;//
|
||||
|
||||
List<String> keys;
|
||||
List<int> types;
|
||||
|
||||
//const StructureMetadata(this.keys, this.types);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user