2
0
mirror of https://github.com/esiur/esiur-dart.git synced 2025-05-06 04:02:57 +00:00
This commit is contained in:
Ahmed Zamil 2022-03-12 16:21:29 +03:00
parent 92a26b8ce5
commit 88eba227ae
64 changed files with 38165 additions and 2952 deletions

9
.vscode/launch.json vendored
View File

@ -13,10 +13,17 @@
{
"name": "Test",
"program": "test/template_test/bin/service.dart",
"program": "test/template/bin/service.dart",
"request": "launch",
"type": "dart"
},
{
"name": "Flutter",
"program": "test/flutter_demo/lib/main.dart",
"request": "launch",
"type": "dart",
"flutterMode": "debug"
}
]
}

View File

@ -1,3 +1,6 @@
## [1.4.6] - Release
Added GetX support
## [1.4.3] - Hotfix
Bugfix

14
analysis_options.yaml Normal file
View File

@ -0,0 +1,14 @@
analyzer:
exclude: [build/**]
language:
strict-raw-types: true
strict-casts: true
strict-inference: true
strong-mode:
implicit-casts: false
linter:
rules:
- cancel_subscriptions

View File

@ -58,13 +58,13 @@ void main(List<String> arguments) async {
return;
} else if (cmd == "version") {
await printVersion();
printVersion();
} else {
printUsage();
}
}
printUsage() {
void printUsage() {
// print help
print("Esiur package command line");
print("");
@ -80,7 +80,7 @@ printUsage() {
print("\t-d, --dir\tName of the directory to generate model inside.");
}
printVersion() async {
void printVersion() async {
var p = Platform.script.pathSegments;
var path = p.take(p.length - 2).join('/') + "/pubspec.yaml";
var yaml = await File(path).readAsString();

7
lib/esiur-js.dart Normal file
View File

@ -0,0 +1,7 @@
import 'dart:js' as js;
import "esiur.dart" as esiur;
void main() {
js.context['wh'] = esiur.Warehouse();
}

View File

@ -1,3 +1,4 @@
// Resource
export 'src/Resource/Warehouse.dart';
export 'src/Resource/Instance.dart';
@ -15,8 +16,11 @@ export 'src/Resource/Template/PropertyPermission.dart';
export 'src/Resource/Template/PropertyTemplate.dart';
export 'src/Resource/Template/TypeTemplate.dart';
export 'src/Resource/Template/TemplateDescriber.dart';
// -----------------------------------------------------------------
// Proxy
export 'src/Proxy/TemplateGenerator.dart';
// Core
export 'src/Core/ProgressType.dart';
export 'src/Core/AsyncBag.dart';
@ -27,26 +31,25 @@ export 'src/Core/ErrorType.dart';
export 'src/Core/ExceptionCode.dart';
export 'src/Core/IDestructible.dart';
export 'src/Core/IEventHandler.dart';
export 'src/Core/Tuple.dart';
// -----------------------------------------------------------------
// Data
export 'src/Data/AutoList.dart';
export 'src/Data/BinaryList.dart';
export 'src/Data/Codec.dart';
export 'src/Data/DataType.dart';
export 'src/Data/RepresentationType.dart';
export 'src/Data/DC.dart';
export 'src/Data/Guid.dart';
export 'src/Data/KeyList.dart';
export 'src/Data/NotModified.dart';
export 'src/Data/PropertyValue.dart';
export 'src/Data/ResourceComparisonResult.dart';
export 'src/Data/SizeObject.dart';
export 'src/Data/Structure.dart';
export 'src/Data/StructureComparisonResult.dart';
export 'src/Data/StructureMetadata.dart';
export 'src/Data/ValueObject.dart';
export 'src/Data/IRecord.dart';
export 'src/Data/Record.dart';
export 'src/Data/IEnum.dart';
export 'src/Data/IntType.dart';
// -----------------------------------------------------------------
// Net
export 'src/Net/NetworkBuffer.dart';

BIN
lib/esiur.dill Normal file

Binary file not shown.

34618
lib/esiur.js Normal file

File diff suppressed because it is too large Load Diff

1
lib/esiur.js.map Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,25 +1,15 @@
import 'AsyncReply.dart';
import '../Resource/Warehouse.dart';
// class ReplyIndex<T> {
// int index;
// AsyncReply<T> reply;
// T
// }
class AsyncBag<T> extends AsyncReply<List<T>> {
List<AsyncReply<T>> _replies = <AsyncReply<T>>[];
//List<T?> _results = <T>[];
int _count = 0;
bool _sealedBag = false;
Type? arrayType;
seal() {
//print("SEALED");
void seal() {
if (_sealedBag) return;
_sealedBag = true;

View File

@ -8,7 +8,7 @@ class AsyncException implements Exception {
AsyncException(this.type, this.code, this.message) {}
static toAsyncException(Exception ex) {
static AsyncException toAsyncException(Exception ex) {
return ex is AsyncException
? ex
: new AsyncException(ErrorType.Exception, 0, ex.toString());

View File

@ -45,7 +45,7 @@ class AsyncReply<T> implements Future<T> {
return _resultReady;
}
set ready(value) {
set ready(bool value) {
_resultReady = value;
}
@ -53,7 +53,7 @@ class AsyncReply<T> implements Future<T> {
return _result;
}
setResultReady(bool val) {
void setResultReady(bool val) {
_resultReady = val;
}

View File

@ -8,7 +8,7 @@ class IEventHandler {
Map<String, List<Function>> _events = {};
register(String event) {
void register(String event) {
_events[event.toLowerCase()] = [];
}
@ -17,11 +17,11 @@ class IEventHandler {
Stream<PropertyModificationInfo> get properyModified =>
_propertyModifiedController.stream;
emitProperty(PropertyModificationInfo event) {
void emitProperty(PropertyModificationInfo event) {
_propertyModifiedController.add(event);
}
emitArgs(String event, List arguments) {
bool emitArgs(String event, List arguments) {
//event = event.toLowerCase();
var et = _events[event.toLowerCase()];
@ -33,14 +33,13 @@ class IEventHandler {
return false;
}
on(String event, Function callback) {
void on(String event, Function callback) {
event = event.toLowerCase();
if (!_events.containsKey(event)) register(event);
_events[event]?.add(callback);
return this;
}
off(String event, callback) {
void off(String event, Function? callback) {
event = event.toLowerCase();
if (_events.containsKey(event)) {
if (callback != null)

View File

@ -9,6 +9,6 @@ class PropertyModificationInfo {
String get name => propertyTemplate.name;
PropertyModificationInfo(
const PropertyModificationInfo(
this.resource, this.propertyTemplate, this.value, this.age);
}

63
lib/src/Core/Tuple.dart Normal file
View File

@ -0,0 +1,63 @@
class Tuple {
final List _list;
const Tuple(this._list);
operator [](int index) => _list[index];
void operator []=(int index, value) {
_list[index] = value;
}
int get length => _list.length;
}
class Tuple2<T1, T2> extends Tuple {
Tuple2(T1 v1, T2 v2) : super([v1, v2]);
T1 get value1 => _list[0] as T1;
T2 get value2 => _list[1] as T2;
}
class Tuple3<T1, T2, T3> extends Tuple {
Tuple3(T1 v1, T2 v2, T3 v3) : super([v1, v2, v3]);
T1 get value1 => _list[0] as T1;
T2 get value2 => _list[1] as T2;
T3 get value3 => _list[2] as T3;
}
class Tuple4<T1, T2, T3, T4> extends Tuple {
Tuple4(T1 v1, T2 v2, T3 v3, T4 v4) : super([v1, v2, v3, v4]);
T1 get value1 => _list[0] as T1;
T2 get value2 => _list[1] as T2;
T3 get value3 => _list[2] as T3;
T4 get value4 => _list[3] as T4;
}
class Tuple5<T1, T2, T3, T4, T5> extends Tuple {
Tuple5(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5) : super([v1, v2, v3, v4, v5]);
T1 get value1 => _list[0] as T1;
T2 get value2 => _list[1] as T2;
T3 get value3 => _list[2] as T3;
T4 get value4 => _list[3] as T4;
T5 get value5 => _list[4] as T5;
}
class Tuple6<T1, T2, T3, T4, T5, T6> extends Tuple {
Tuple6(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6)
: super([v1, v2, v3, v4, v5, v6]);
T1 get value1 => _list[0] as T1;
T2 get value2 => _list[1] as T2;
T3 get value3 => _list[2] as T3;
T4 get value4 => _list[3] as T4;
T5 get value5 => _list[4] as T5;
T6 get value6 => _list[5] as T6;
}
class Tuple7<T1, T2, T3, T4, T5, T6, T7> extends Tuple {
Tuple7(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7)
: super([v1, v2, v3, v4, v5, v6, v5]);
T1 get value1 => _list[0] as T1;
T2 get value2 => _list[1] as T2;
T3 get value3 => _list[2] as T3;
T4 get value4 => _list[3] as T4;
T5 get value5 => _list[4] as T5;
T6 get value6 => _list[5] as T6;
T7 get value7 => _list[6] as T7;
}

View File

@ -1,3 +1,6 @@
import '../Core/IEventHandler.dart';
import '../Core/IDestructible.dart';
import 'Codec.dart';
import 'dart:collection';
@ -8,7 +11,7 @@ class AutoList<T, ST> extends IDestructible with IterableMixin<T> {
ST? _state;
late bool _removableList;
sort(int Function(T, T)? compare) {
void sort(int Function(T, T)? compare) {
_list.sort(compare);
}
@ -38,36 +41,17 @@ class AutoList<T, ST> extends IDestructible with IterableMixin<T> {
register("cleared");
}
/// <summary>
/// Synchronization lock of the list
/// </summary>
//public object SyncRoot
//{
// get
// {
// return syncRoot;
// }
//}
/// <summary>
/// First item in the list
/// </summary>
//T first()
//{
// return _list.first;
//}
operator [](index) {
T operator [](int index) {
return _list[index];
}
operator []=(index, value) {
void operator []=(int index, T value) {
var oldValue = _list[index];
if (_removableList) {
if (oldValue != null)
(oldValue as IDestructible).off("destroy", _itemDestroyed);
if (value != null) value.on("destroy", _itemDestroyed);
if (value != null) (value as IEventHandler).on("destroy", _itemDestroyed);
}
//lock (syncRoot)
@ -79,7 +63,7 @@ class AutoList<T, ST> extends IDestructible with IterableMixin<T> {
/// <summary>
/// Add item to the list
/// </summary>
add(T value) {
void add(T value) {
if (_removableList) if (value != null)
(value as IDestructible).on("destroy", _itemDestroyed);
@ -92,18 +76,18 @@ class AutoList<T, ST> extends IDestructible with IterableMixin<T> {
/// <summary>
/// Add an array of items to the list
/// </summary>
addRange(List<T> values) {
void addRange(List<T> values) {
values.forEach((x) => add(x));
}
_itemDestroyed(T sender) {
void _itemDestroyed(T sender) {
remove(sender);
}
/// <summary>
/// Clear the list
/// </summary>
clear() {
void clear() {
if (_removableList)
_list.forEach((x) => (x as IDestructible).off("destroy", _itemDestroyed));
@ -117,7 +101,7 @@ class AutoList<T, ST> extends IDestructible with IterableMixin<T> {
/// Remove an item from the list
/// <param name="value">Item to remove</param>
/// </summary>
remove(T value) {
void remove(T value) {
if (!_list.contains(value)) return;
if (_removableList) if (value != null)
@ -145,7 +129,7 @@ class AutoList<T, ST> extends IDestructible with IterableMixin<T> {
/// Check if any item of the given array is in the list
/// </summary>
/// <param name="values">Array of items</param>
containsAny(values) {
bool containsAny(dynamic values) {
if (values is List<T>) {
for (var v in values) {
if (_list.contains(v)) return true;

View File

@ -27,7 +27,6 @@
import '../Core/AsyncReply.dart';
import 'dart:typed_data';
import 'DC.dart';
import 'DataType.dart';
import 'Guid.dart';
class BinaryList {
@ -35,20 +34,22 @@ class BinaryList {
int get length => _list.length;
void addDateTime(DateTime value) {
_list.addAll(DC.dateTimeToBytes(value));
void addDateTime(DateTime value, [Endian endian = Endian.little]) {
_list.addAll(DC.dateTimeToBytes(value, endian));
}
void insertDateTime(int position, DateTime value) {
_list.insertAll(position, DC.dateTimeToBytes(value));
void insertDateTime(int position, DateTime value,
[Endian endian = Endian.little]) {
_list.insertAll(position, DC.dateTimeToBytes(value, endian));
}
void addDateTimeArray(List<DateTime> value) {
_list.addAll(DC.dateTimeArrayToBytes(value));
void addDateTimeArray(List<DateTime> value, [Endian endian = Endian.little]) {
_list.addAll(DC.dateTimeArrayToBytes(value, endian));
}
void insertDateTimeArray(int position, List<DateTime> value) {
_list.insertAll(position, DC.dateTimeArrayToBytes(value));
void insertDateTimeArray(int position, List<DateTime> value,
[Endian endian = Endian.little]) {
_list.insertAll(position, DC.dateTimeArrayToBytes(value, endian));
}
void addGuid(Guid value) {
@ -59,14 +60,6 @@ class BinaryList {
_list.insertAll(position, DC.guidToBytes(value));
}
void addGuidArray(List<Guid> value) {
_list.addAll(DC.guidArrayToBytes(value));
}
void insertGuidArray(int position, List<Guid> value) {
_list.insertAll(position, DC.guidArrayToBytes(value));
}
void addUint8Array(Uint8List value) {
_list.addAll(value);
}
@ -79,18 +72,6 @@ class BinaryList {
_list.insertAll(position, value);
}
/*
BinaryList addHex(String value)
{
return this.addUint8Array(DC.fromHex(value, null));
}
BinaryList insertHex(int position, String value)
{
return this.insertUint8Array(position, DC.fromHex(value, null));
}
*/
void addString(String value) {
_list.addAll(DC.stringToBytes(value));
}
@ -99,14 +80,6 @@ class BinaryList {
_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);
}
@ -123,30 +96,14 @@ class BinaryList {
_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) {
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));
}
@ -155,237 +112,70 @@ class BinaryList {
_list.insertAll(position, DC.boolToBytes(value));
}
void addBooleanArray(List<bool> value) {
_list.addAll(DC.boolToBytes(value));
void addUint16(int value, [Endian endian = Endian.little]) {
_list.addAll(DC.uint16ToBytes(value, endian));
}
void insertBooleanArray(int position, List<bool> value) {
_list.insertAll(position, DC.boolToBytes(value));
void insertUint16(int position, int value, [Endian endian = Endian.little]) {
_list.insertAll(position, DC.uint16ToBytes(value, endian));
}
void addUint16(int value) {
_list.addAll(DC.uint16ToBytes(value));
void addInt16(int value, [Endian endian = Endian.little]) {
_list.addAll(DC.int16ToBytes(value, endian));
}
void insertUint16(int position, int value) {
_list.insertAll(position, DC.uint16ToBytes(value));
void insertInt16(int position, int value, [Endian endian = Endian.little]) {
_list.insertAll(position, DC.int16ToBytes(value, endian));
}
void addUint16Array(Uint16List value) {
_list.addAll(DC.uint16ArrayToBytes(value));
void addUint32(int value, [Endian endian = Endian.little]) {
_list.addAll(DC.uint32ToBytes(value, endian));
}
void insertUint16Array(int position, Uint16List value) {
_list.insertAll(position, DC.uint16ArrayToBytes(value));
void insertUint32(int position, int value, [Endian endian = Endian.little]) {
_list.insertAll(position, DC.uint32ToBytes(value, endian));
}
void addInt16(int value) {
_list.addAll(DC.int16ToBytes(value));
void addInt32(int value, [Endian endian = Endian.little]) {
_list.addAll(DC.int32ToBytes(value, endian));
}
void insertInt16(int position, int value) {
_list.insertAll(position, DC.int16ToBytes(value));
void insertInt32(int position, int value, [Endian endian = Endian.little]) {
_list.insertAll(position, DC.int32ToBytes(value, endian));
}
void addInt16Array(Int16List value) {
_list.addAll(DC.int16ArrayToBytes(value));
void addUint64(int value, [Endian endian = Endian.little]) {
_list.addAll(DC.uint64ToBytes(value, endian));
}
void insertInt16Array(int position, Int16List value) {
_list.insertAll(position, DC.int16ArrayToBytes(value));
void insertUint64(int position, int value, [Endian endian = Endian.little]) {
_list.insertAll(position, DC.uint64ToBytes(value, endian));
}
void addUint32(int value) {
_list.addAll(DC.uint32ToBytes(value));
void addInt64(int value, [Endian endian = Endian.little]) {
_list.addAll(DC.int64ToBytes(value, endian));
}
void insertUint32(int position, int value) {
_list.insertAll(position, DC.uint32ToBytes(value));
void insertInt64(int position, int value, [Endian endian = Endian.little]) {
_list.insertAll(position, DC.int64ToBytes(value, endian));
}
void addUint32Array(Uint32List value) {
_list.addAll(DC.uint32ArrayToBytes(value));
void addFloat32(double value, [Endian endian = Endian.little]) {
_list.addAll(DC.float32ToBytes(value, endian));
}
void InsertUint32Array(int position, Uint32List value) {
_list.insertAll(position, DC.uint32ArrayToBytes(value));
void insertFloat32(int position, double value,
[Endian endian = Endian.little]) {
_list.insertAll(position, DC.float32ToBytes(value, endian));
}
void addInt32(int value) {
_list.addAll(DC.int32ToBytes(value));
void addFloat64(double value, [Endian endian = Endian.little]) {
_list.addAll(DC.float64ToBytes(value, endian));
}
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;
}
void insertFloat64(int position, double value,
[Endian endian = Endian.little]) {
_list.insertAll(position, DC.float64ToBytes(value, endian));
}
/// <summary>

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,6 @@
* SOFTWARE.
*/
import 'dart:typed_data';
import 'dart:convert';
import 'BinaryList.dart';
@ -55,6 +54,28 @@ class DC with IterableMixin<int> {
_dv = ByteData.view(_data.buffer);
}
String toHex([String separator = " ", int? offset, int? length]) {
var start = offset ?? 0;
var count = length ?? _data.length - start;
if (count == 0) return "";
var rt = _data[start].toRadixString(16).padLeft(2, '0');
for (var i = start + 1; i < count; i++) {
rt += separator + _data[i].toRadixString(16).padLeft(2, '0');
}
return rt;
}
DC.fromHex(String hex, [String separator = ' ']) {
var list =
hex.split(separator).map((e) => int.parse(e, radix: 16)).toList();
_data = Uint8List.fromList(list);
_dv = ByteData.view(_data.buffer);
}
int operator [](int index) => _data[index];
operator []=(int index, int value) => _data[index] = value;
int get length => _data.length;
@ -69,7 +90,7 @@ class DC with IterableMixin<int> {
return rt;
}
static DC boolToBytes(value) {
static DC boolToBytes(bool value) {
var rt = new DC(1);
rt.setBoolean(0, value);
return rt;
@ -81,19 +102,7 @@ class DC with IterableMixin<int> {
return rt;
}
static DC guidArrayToBytes(List<Guid> value) {
var rt = new DC(value.length * 16);
for (var i = 0; i < value.length; i++) rt.setGuid(i * 16, value[i]);
return rt;
}
static DC boolArrayToBytes(List<bool> value) {
var rt = new DC(value.length);
for (var i = 0; i < value.length; i++) rt[i] = value[i] ? 1 : 0;
return rt;
}
static DC int8ToBytes(value) {
static DC int8ToBytes(int value) {
var rt = new DC(1);
rt.setInt8(0, value);
return rt;
@ -105,7 +114,7 @@ class DC with IterableMixin<int> {
return rt;
}
static DC uint8ToBytes(value) {
static DC uint8ToBytes(int value) {
var rt = new DC(1);
rt.setUint8(0, value);
return rt;
@ -123,28 +132,21 @@ class DC with IterableMixin<int> {
return rt;
}
static DC charArrayToBytes(Uint16List value) {
var rt = new DC(value.length * 2);
for (var i = 0; i < value.length; i++) rt.setChar(i * 2, value[i]);
return rt;
}
static DC int16ToBytes(int value) {
static DC int16ToBytes(int value, [Endian endian = Endian.little]) {
var rt = new DC(2);
rt.setInt16(0, value);
rt.setInt16(0, value, endian);
return rt;
}
static DC int16ArrayToBytes(List<int> value) {
static DC int16ArrayToBytes(Int16List value) {
var rt = new DC(value.length * 2);
for (var i = 0; i < value.length; i++) rt.setInt16(i * 2, value[i]);
return rt;
}
static DC uint16ToBytes(int value) {
static DC uint16ToBytes(int value, [Endian endian = Endian.little]) {
var rt = new DC(2);
rt.setUint16(0, value);
rt.setUint16(0, value, endian);
return rt;
}
@ -154,9 +156,9 @@ class DC with IterableMixin<int> {
return rt;
}
static DC int32ToBytes(int value) {
static DC int32ToBytes(int value, [Endian endian = Endian.little]) {
var rt = new DC(4);
rt.setInt32(0, value);
rt.setInt32(0, value, endian);
return rt;
}
@ -166,9 +168,9 @@ class DC with IterableMixin<int> {
return rt;
}
static DC uint32ToBytes(int value) {
static DC uint32ToBytes(int value, [Endian endian = Endian.little]) {
var rt = new DC(4);
rt.setUint32(0, value);
rt.setUint32(0, value, endian);
return rt;
}
@ -178,9 +180,9 @@ class DC with IterableMixin<int> {
return rt;
}
static DC float32ToBytes(double value) {
static DC float32ToBytes(double value, [Endian endian = Endian.little]) {
var rt = new DC(4);
rt.setFloat32(0, value);
rt.setFloat32(0, value, endian);
return rt;
}
@ -190,9 +192,9 @@ class DC with IterableMixin<int> {
return rt;
}
static DC int64ToBytes(int value) {
static DC int64ToBytes(int value, [Endian endian = Endian.little]) {
var rt = new DC(8);
rt.setInt64(0, value);
rt.setInt64(0, value, endian);
return rt;
}
@ -202,9 +204,9 @@ class DC with IterableMixin<int> {
return rt;
}
static DC uint64ToBytes(int value) {
static DC uint64ToBytes(int value, [Endian endian = Endian.little]) {
var rt = new DC(8);
rt.setUint64(0, value);
rt.setUint64(0, value, endian);
return rt;
}
@ -214,9 +216,9 @@ class DC with IterableMixin<int> {
return rt;
}
static DC float64ToBytes(double value) {
static DC float64ToBytes(double value, [Endian endian = Endian.little]) {
var rt = new DC(8);
rt.setFloat64(0, value);
rt.setFloat64(0, value, endian);
return rt;
}
@ -226,15 +228,15 @@ class DC with IterableMixin<int> {
return rt;
}
static DC dateTimeToBytes(DateTime value) {
static DC dateTimeToBytes(DateTime value, [Endian endian = Endian.little]) {
var rt = new DC(8);
rt.setDateTime(0, value);
rt.setDateTime(0, value, endian);
return rt;
}
static DC dateTimeArrayToBytes(List<DateTime> value) {
static DC dateTimeArrayToBytes(List<DateTime> value, [Endian endian = Endian.little]) {
var rt = new DC(value.length * 8);
for (var i = 0; i < value.length; i++) rt.setDateTime(i * 8, value[i]);
for (var i = 0; i < value.length; i++) rt.setDateTime(i * 8, value[i], endian);
return rt;
}
@ -244,26 +246,14 @@ class DC with IterableMixin<int> {
return rt;
}
static DC stringArrayToBytes(List<String> value) {
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());
}
return list.toDC();
}
DC append(DC src, int offset, int length) {
//if (!(src is DC))
// src = new DC(src);
var appendix = src.clip(offset, length);
var rt = new DC(this.length + appendix.length);
rt.set(this, 0);
rt.set(appendix, this.length);
rt.set(this, 0, 0, this.length);
rt.set(appendix, 0, this.length, appendix.length);
this._data = rt._data;
this._dv = rt._dv;
@ -271,25 +261,25 @@ class DC with IterableMixin<int> {
return this;
}
set(DC dc, int offset) {
_data.setRange(offset, offset + dc.length, dc._data);
void set(DC src, int srcOffset, int dstOffset, int length) {
_data.setRange(dstOffset, dstOffset + length, src._data, srcOffset);
}
static combine(a, aOffset, aLength, b, bOffset, bLength) {
if (!(a is DC)) a = new DC(a);
if (!(b is DC)) b = new DC(b);
static DC combine(a, int aOffset, int aLength, b, int bOffset, int bLength) {
if (!(a is DC)) a = DC.fromList(a as List<int>);
if (!(b is DC)) b = DC.fromList(b as List<int>);
a = a.clip(aOffset, aLength);
b = b.clip(bOffset, bLength);
var rt = new DC(a.length + b.length);
rt.set(a, 0);
rt.set(b, a.length);
rt.set(a, 0, 0, a.length);
rt.set(b, 0, a.length, b.length);
return rt;
}
DC clip(offset, length) {
DC clip(int offset, int length) {
return DC.fromUint8Array(
Uint8List.fromList(_data.getRange(offset, offset + length).toList()));
}
@ -302,28 +292,28 @@ class DC with IterableMixin<int> {
return _data[offset]; // this.dv.getUint8(offset);
}
int getInt16(int offset) {
return _dv.getInt16(offset);
int getInt16(int offset, [Endian endian = Endian.little]) {
return _dv.getInt16(offset, endian);
}
int getUint16(int offset) {
return _dv.getUint16(offset);
int getUint16(int offset, [Endian endian = Endian.little]) {
return _dv.getUint16(offset, endian);
}
int getInt32(int offset) {
return _dv.getInt32(offset);
int getInt32(int offset, [Endian endian = Endian.little]) {
return _dv.getInt32(offset, endian);
}
int getUint32(int offset) {
return _dv.getUint32(offset);
int getUint32(int offset, [Endian endian = Endian.little]) {
return _dv.getUint32(offset, endian);
}
double getFloat32(int offset) {
return _dv.getFloat32(offset);
double getFloat32(int offset, [Endian endian = Endian.little]) {
return _dv.getFloat32(offset, endian);
}
double getFloat64(int offset) {
return _dv.getFloat64(offset);
double getFloat64(int offset, [Endian endian = Endian.little]) {
return _dv.getFloat64(offset, endian);
}
void setInt8(int offset, int value) {
@ -334,28 +324,28 @@ class DC with IterableMixin<int> {
return _dv.setUint8(offset, value);
}
void setInt16(int offset, int value) {
return _dv.setInt16(offset, value);
void setInt16(int offset, int value, [Endian endian = Endian.little]) {
return _dv.setInt16(offset, value, endian);
}
void setUint16(int offset, int value) {
return _dv.setUint16(offset, value);
void setUint16(int offset, int value, [Endian endian = Endian.little]) {
return _dv.setUint16(offset, value, endian);
}
void setInt32(int offset, int value) {
return _dv.setInt32(offset, value);
void setInt32(int offset, int value, [Endian endian = Endian.little]) {
return _dv.setInt32(offset, value, endian);
}
void setUint32(int offset, int value) {
return _dv.setUint32(offset, value);
void setUint32(int offset, int value, [Endian endian = Endian.little]) {
return _dv.setUint32(offset, value, endian);
}
void setFloat32(int offset, double value) {
return _dv.setFloat32(offset, value);
void setFloat32(int offset, double value, [Endian endian = Endian.little]) {
return _dv.setFloat32(offset, value, endian);
}
void setFloat64(int offset, double value) {
return _dv.setFloat64(offset, value);
void setFloat64(int offset, double value, [Endian endian = Endian.little]) {
return _dv.setFloat64(offset, value, endian);
}
Int8List getInt8Array(int offset, int length) {
@ -420,12 +410,6 @@ class DC with IterableMixin<int> {
this.setUint8(offset, value ? 1 : 0);
}
List<bool> getBooleanArray(int offset, int length) {
List<bool> rt = [];
for (var i = 0; i < length; i++) rt.add(this.getBoolean(offset + i));
return rt;
}
String getChar(int offset) {
return String.fromCharCode(this.getUint16(offset));
}
@ -434,13 +418,7 @@ class DC with IterableMixin<int> {
this.setUint16(offset, value); //value.codeUnitAt(0));
}
List<String> getCharArray(int offset, int length) {
List<String> rt = [];
for (var i = 0; i < length; i += 2) rt.add(this.getChar(offset + i));
return rt;
}
String getHex(offset, length) {
String getHex(int offset, int length) {
var rt = "";
for (var i = offset; i < offset + length; i++) {
var h = _data[i].toRadixString(16);
@ -461,13 +439,194 @@ class DC with IterableMixin<int> {
Uint8List toArray() => _data;
String getString(offset, length) {
String getString(int offset, int length) {
var bytes = clip(offset, length)._data; // toList(offset, length);
var str = utf8.decode(bytes);
return str;
}
List<String> getStringArray(offset, length) {
int getInt64(int offset, [Endian endian = Endian.little]) {
if (kIsWeb) {
if (endian == Endian.big) {
var bi = BigInt.from(0);
bi |= BigInt.from(getUint8(offset++)) << 56;
bi |= BigInt.from(getUint8(offset++)) << 48;
bi |= BigInt.from(getUint8(offset++)) << 40;
bi |= BigInt.from(getUint8(offset++)) << 32;
bi |= BigInt.from(getUint8(offset++)) << 24;
bi |= BigInt.from(getUint8(offset++)) << 16;
bi |= BigInt.from(getUint8(offset++)) << 8;
bi |= BigInt.from(getUint8(offset++));
return bi.toInt();
} else {
var bi = BigInt.from(0);
bi |= BigInt.from(getUint8(offset++));
bi |= BigInt.from(getUint8(offset++)) << 8;
bi |= BigInt.from(getUint8(offset++)) << 16;
bi |= BigInt.from(getUint8(offset++)) << 24;
bi |= BigInt.from(getUint8(offset++)) << 32;
bi |= BigInt.from(getUint8(offset++)) << 40;
bi |= BigInt.from(getUint8(offset++)) << 48;
bi |= BigInt.from(getUint8(offset++)) << 56;
return bi.toInt();
}
//var l = this.getUint32(offset);
//var h = this.getUint32(offset + 4);
//return h * TWO_PWR_32 + ((l >= 0) ? l : TWO_PWR_32 + l);
} else {
return _dv.getUint64(offset);
}
}
int getUint64(int offset, [Endian endian = Endian.little]) {
if (kIsWeb) {
if (endian == Endian.big) {
var bi = BigInt.from(0);
bi |= BigInt.from(getUint8(offset++)) << 56;
bi |= BigInt.from(getUint8(offset++)) << 48;
bi |= BigInt.from(getUint8(offset++)) << 40;
bi |= BigInt.from(getUint8(offset++)) << 32;
bi |= BigInt.from(getUint8(offset++)) << 24;
bi |= BigInt.from(getUint8(offset++)) << 16;
bi |= BigInt.from(getUint8(offset++)) << 8;
bi |= BigInt.from(getUint8(offset++));
return bi.toInt();
} else {
var bi = BigInt.from(0);
bi |= BigInt.from(getUint8(offset++));
bi |= BigInt.from(getUint8(offset++)) << 8;
bi |= BigInt.from(getUint8(offset++)) << 16;
bi |= BigInt.from(getUint8(offset++)) << 24;
bi |= BigInt.from(getUint8(offset++)) << 32;
bi |= BigInt.from(getUint8(offset++)) << 40;
bi |= BigInt.from(getUint8(offset++)) << 48;
bi |= BigInt.from(getUint8(offset++)) << 56;
return bi.toInt();
}
//var l = this.getUint32(offset);
//var h = this.getUint32(offset + 4);
//return h * TWO_PWR_32 + ((l >= 0) ? l : TWO_PWR_32 + l);
} else {
return _dv.getUint64(offset);
}
// if (kIsWeb) {
// print("getUint64");
// var l = this.getUint32(offset);
// var h = this.getUint32(offset + 4);
// return h * TWO_PWR_32 + ((l >= 0) ? l : TWO_PWR_32 + l);
// } else {
// return _dv.getInt64(offset);
// }
}
void setInt64(int offset, int value, [Endian endian = Endian.little]) {
if (kIsWeb) {
var bi = BigInt.from(value);
var byte = BigInt.from(0xFF);
if (endian == Endian.big) {
_dv.setUint8(offset++, ((bi >> 56) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 48) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 40) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 32) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 24) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 16) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 8) & byte).toInt());
_dv.setUint8(offset++, (bi & byte).toInt());
} else {
_dv.setUint8(offset++, ((bi) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 8) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 16) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 24) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 32) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 40) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 48) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 56) & byte).toInt());
}
} else {
_dv.setInt64(offset, value, endian);
}
}
void setUint64(int offset, int value, [Endian endian = Endian.little]) {
if (kIsWeb) {
// BigInt a = 33 as BigInt;
// int l = BigInt value & 0xFFFFFFFF;
// int h = value >> 32;
// int h = (value % TWO_PWR_32) | 0;
// int l = ((value / TWO_PWR_32)) | 0;
// _dv.setInt32(offset, h, endian);
// _dv.setInt32(offset + 4, l, endian);
var bi = BigInt.from(value);
var byte = BigInt.from(0xFF);
if (endian == Endian.big) {
_dv.setUint8(offset++, ((bi >> 56) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 48) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 40) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 32) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 24) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 16) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 8) & byte).toInt());
_dv.setUint8(offset++, (bi & byte).toInt());
} else {
_dv.setUint8(offset++, ((bi) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 8) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 16) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 24) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 32) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 40) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 48) & byte).toInt());
_dv.setUint8(offset++, ((bi >> 56) & byte).toInt());
}
} else {
_dv.setUint64(offset, value, endian);
}
}
void setDateTime(int offset, DateTime value, [Endian endian = Endian.little]) {
// Unix Epoch
var ticks = UNIX_EPOCH + (value.millisecondsSinceEpoch * 10000);
this.setUint64(offset, ticks, endian);
}
DateTime getDateTime(int offset, [Endian endian = Endian.little]) {
var ticks = this.getUint64(offset, endian);
// there are 10,000 ticks in a millisecond
return DateTime.fromMillisecondsSinceEpoch((ticks - UNIX_EPOCH) ~/ 10000);
}
Guid getGuid(int offset) {
return new Guid(this.clip(offset, 16));
}
void setGuid(int offset, Guid guid) {
set(guid.value, 0, offset, 16);
}
bool sequenceEqual(ar) {
if (ar.length != this.length)
return false;
else {
for (var i = 0; i < this.length; i++) if (ar[i] != this[i]) return false;
}
return true;
}
List<String> getStringArray(int offset, int length) {
List<String> rt = [];
var i = 0;
@ -481,80 +640,15 @@ class DC with IterableMixin<int> {
return rt;
}
int getInt64(offset) {
if (kIsWeb) {
var h = this.getUint32(offset);
var l = this.getUint32(offset + 4);
return h * TWO_PWR_32 + ((l >= 0) ? l : TWO_PWR_32 + l);
} else {
return _dv.getUint64(offset);
}
static DC stringArrayToBytes(List<String> value) {
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());
}
int getUint64(offset) {
if (kIsWeb) {
var h = this.getUint32(offset);
var l = this.getUint32(offset + 4);
return h * TWO_PWR_32 + ((l >= 0) ? l : TWO_PWR_32 + l);
} else {
return _dv.getInt64(offset);
}
}
void setInt64(offset, value) {
_dv.setInt64(offset, value);
}
void setUint64(offset, value) {
if (kIsWeb) {
var l = (value % TWO_PWR_32) | 0;
var h = (value / TWO_PWR_32) | 0;
_dv.setInt32(offset, h);
_dv.setInt32(offset + 4, l);
} else {
_dv.setUint64(offset, value);
}
}
void setDateTime(offset, DateTime value) {
// Unix Epoch
var ticks = UNIX_EPOCH + (value.millisecondsSinceEpoch * 10000);
this.setUint64(offset, ticks);
}
DateTime getDateTime(int offset) {
var ticks = this.getUint64(offset);
// there are 10,000 ticks in a millisecond
return DateTime.fromMillisecondsSinceEpoch((ticks - UNIX_EPOCH) ~/ 10000);
}
List<DateTime> getDateTimeArray(int offset, int length) {
List<DateTime> rt = [];
for (var i = 0; i < length; i += 8) rt.add(this.getDateTime(offset + i));
return rt;
}
Guid getGuid(int offset) {
return new Guid(this.clip(offset, 16));
}
void setGuid(int offset, Guid guid) {
set(guid.value, offset);
}
List<Guid> getGuidArray(int offset, int length) {
List<Guid> rt = [];
for (var i = 0; i < length; i += 16) rt.add(this.getGuid(offset + i));
return rt;
}
bool sequenceEqual(ar) {
if (ar.length != this.length)
return false;
else {
for (var i = 0; i < this.length; i++) if (ar[i] != this[i]) return false;
}
return true;
return list.toDC();
}
}

View File

@ -0,0 +1,508 @@
import 'dart:core';
import 'IEnum.dart';
import '../Core/Tuple.dart';
import '../Resource/Template/TemplateType.dart';
import '../Resource/Warehouse.dart';
import '../../esiur.dart';
import '../Core/AsyncBag.dart';
import '../Core/AsyncReply.dart';
import 'DC.dart';
import '../Net/IIP/DistributedConnection.dart';
import 'NotModified.dart';
import 'RepresentationType.dart';
class PropertyValueParserResults {
final int size;
final AsyncReply<PropertyValue> reply;
PropertyValueParserResults(this.size, this.reply);
}
class DataDeserializer {
static AsyncReply nullParser(
DC data, int offset, int length, DistributedConnection? connection) {
return AsyncReply.ready(null);
}
static AsyncReply booleanTrueParser(
DC data, int offset, int length, DistributedConnection? connection) {
return new AsyncReply<bool>.ready(true);
}
static AsyncReply booleanFalseParser(
DC data, int offset, int length, DistributedConnection? connection) {
return new AsyncReply<bool>.ready(false);
}
static AsyncReply notModifiedParser(
DC data, int offset, int length, DistributedConnection? connection) {
return new AsyncReply<NotModified>.ready(NotModified());
}
static AsyncReply byteParser(
DC data, int offset, int length, DistributedConnection? connection) {
return new AsyncReply<int>.ready(data[offset]);
}
static AsyncReply sByteParser(
DC data, int offset, int length, DistributedConnection? connection) {
return new AsyncReply<int>.ready(
data[offset] > 127 ? data[offset] - 256 : data[offset]);
}
static AsyncReply char16Parser(
DC data, int offset, int length, DistributedConnection? connection) {
return AsyncReply<String>.ready(data.getChar(offset));
}
static AsyncReply char8Parser(
DC data, int offset, int length, DistributedConnection? connection) {
return new AsyncReply<String>.ready(String.fromCharCode(data[offset]));
}
static AsyncReply int16Parser(
DC data, int offset, int length, DistributedConnection? connection) {
return AsyncReply<int>.ready(data.getInt16(offset));
}
static AsyncReply uInt16Parser(
DC data, int offset, int length, DistributedConnection? connection) {
return AsyncReply<int>.ready(data.getUint16(offset));
}
static AsyncReply int32Parser(
DC data, int offset, int length, DistributedConnection? connection) {
return AsyncReply<int>.ready(data.getInt32(offset));
}
static AsyncReply uInt32Parser(
DC data, int offset, int length, DistributedConnection? connection) {
return AsyncReply<int>.ready(data.getUint32(offset));
}
static AsyncReply float32Parser(
DC data, int offset, int length, DistributedConnection? connection) {
return AsyncReply<double>.ready(data.getFloat32(offset));
}
static AsyncReply float64Parser(
DC data, int offset, int length, DistributedConnection? connection) {
return AsyncReply<double>.ready(data.getFloat64(offset));
}
static AsyncReply float128Parser(
DC data, int offset, int length, DistributedConnection? connection) {
// @TODO
return AsyncReply<double>.ready(data.getFloat64(offset));
}
static AsyncReply int128Parser(
DC data, int offset, int length, DistributedConnection? connection) {
// @TODO
return AsyncReply<int>.ready(data.getInt64(offset));
}
static AsyncReply uInt128Parser(
DC data, int offset, int length, DistributedConnection? connection) {
return AsyncReply<int>.ready(data.getUint64(offset));
}
static AsyncReply int64Parser(
DC data, int offset, int length, DistributedConnection? connection) {
return AsyncReply<int>.ready(data.getInt64(offset));
}
static AsyncReply uInt64Parser(
DC data, int offset, int length, DistributedConnection? connection) {
return AsyncReply<int>.ready(data.getUint64(offset));
}
static AsyncReply dateTimeParser(
DC data, int offset, int length, DistributedConnection? connection) {
return AsyncReply<DateTime>.ready(data.getDateTime(offset));
}
static AsyncReply resourceParser(
DC data, int offset, int length, DistributedConnection? connection) {
if (connection != null) {
var id = data.getUint32(offset);
return connection.fetch(id);
}
throw Exception("Can't parse resource with no connection");
}
static AsyncReply localResourceParser(
DC data, int offset, int length, DistributedConnection? connection) {
var id = data.getUint32(offset);
return Warehouse.getById(id);
}
static AsyncReply rawDataParser(
DC data, int offset, int length, DistributedConnection? connection) {
return new AsyncReply<DC>.ready(data.clip(offset, length));
}
static AsyncReply stringParser(
DC data, int offset, int length, DistributedConnection? connection) {
return new AsyncReply<String>.ready(data.getString(offset, length));
}
static AsyncReply recordParser(
DC data, int offset, int length, DistributedConnection? connection) {
var reply = new AsyncReply<IRecord>();
var classId = data.getGuid(offset);
offset += 16;
length -= 16;
var template = Warehouse.getTemplateByClassId(classId, TemplateType.Record);
if (template != null) {
listParser(data, offset, length, connection).then((r) {
var ar = r as List;
IRecord record;
if (template.definedType != null) {
record = Warehouse.createInstance(template.definedType!) as IRecord;
} else {
record = Record();
}
var kv = Map<String, dynamic>();
for (var i = 0; i < template.properties.length; i++)
kv[template.properties[i].name] = ar[i];
record.deserialize(kv);
reply.trigger(record);
});
} else {
if (connection == null)
throw Exception("Can't parse record with no connection");
connection.getTemplate(classId).then((tmp) {
if (tmp == null)
reply.triggerError(Exception("Couldn't fetch record template."));
listParser(data, offset, length, connection).then((r) {
var ar = r as List;
var record = new Record();
var kv = Map<String, dynamic>();
for (var i = 0; i < tmp!.properties.length; i++)
kv[tmp.properties[i].name] = ar[i];
record.deserialize(kv);
reply.trigger(record);
});
}).error((x) => reply.triggerError(x));
}
return reply;
}
static AsyncReply constantParser(
DC data, int offset, int length, DistributedConnection? connection) {
throw Exception("NotImplementedException");
}
static AsyncReply enumParser(
DC data, int offset, int length, DistributedConnection? connection) {
var classId = data.getGuid(offset);
offset += 16;
var index = data[offset++];
var template = Warehouse.getTemplateByClassId(classId, TemplateType.Enum);
if (template != null) {
if (template.definedType != null) {
var enumVal = Warehouse.createInstance(template.definedType!) as IEnum;
enumVal.index = index;
enumVal.name = template.constants[index].name;
enumVal.value = template.constants[index].value;
return new AsyncReply.ready(enumVal);
} else {
return AsyncReply.ready(IEnum(index, template.constants[index].value,
template.constants[index].name));
}
} else {
var reply = new AsyncReply();
if (connection == null)
throw Exception("Can't parse enum with no connection");
connection.getTemplate(classId).then((tmp) {
if (tmp != null) {
if (tmp.definedType != null) {
var enumVal = Warehouse.createInstance(tmp.definedType!) as IEnum;
enumVal.index = index;
enumVal.name = tmp.constants[index].name;
enumVal.value = tmp.constants[index].value;
reply.trigger(enumVal);
} else {
reply.trigger(IEnum(
index, tmp.constants[index].value, tmp.constants[index].name));
}
} else
reply.triggerError(Exception("Template not found for enum"));
}).error((x) => reply.triggerError(x));
return reply;
}
}
static AsyncReply recordListParser(
DC data, int offset, int length, DistributedConnection? connection) {
var rt = new AsyncBag();
while (length > 0) {
var parsed = Codec.parse(data, offset, connection);
rt.add(parsed.reply);
if (parsed.size > 0) {
offset += parsed.size;
length -= parsed.size;
} else
throw new Exception("Error while parsing structured data");
}
rt.seal();
return rt;
}
static AsyncReply resourceListParser(
DC data, int offset, int length, DistributedConnection? connection) {
var rt = new AsyncBag();
while (length > 0) {
var parsed = Codec.parse(data, offset, connection);
rt.add(parsed.reply);
if (parsed.size > 0) {
offset += parsed.size;
length -= parsed.size;
} else
throw new Exception("Error while parsing structured data");
}
rt.seal();
return rt;
}
static AsyncBag listParser(
DC data, int offset, int length, DistributedConnection? connection) {
var rt = new AsyncBag();
while (length > 0) {
var parsed = Codec.parse(data, offset, connection);
rt.add(parsed.reply);
if (parsed.size > 0) {
offset += parsed.size;
length -= parsed.size;
} else
throw new Exception("Error while parsing structured data");
}
rt.seal();
return rt;
}
static AsyncReply typedMapParser(
DC data, int offset, int length, DistributedConnection? connection) {
// get key type
var keyRep = RepresentationType.parse(data, offset);
offset += keyRep.size;
length -= keyRep.size;
var valueRep = RepresentationType.parse(data, offset);
offset += valueRep.size;
length -= valueRep.size;
var map = Map();
var rt = new AsyncReply();
var results = new AsyncBag();
while (length > 0) {
var parsed = Codec.parse(data, offset, connection);
results.add(parsed.reply);
if (parsed.size > 0) {
offset += parsed.size;
length -= parsed.size;
} else
throw new Exception("Error while parsing structured data");
}
results.seal();
results.then((ar) {
for (var i = 0; i < ar.length; i += 2) map[ar[i]] = ar[i + 1];
rt.trigger(map);
});
return rt;
}
static AsyncReply tupleParser(
DC data, int offset, int length, DistributedConnection? connection) {
var results = new AsyncBag();
var rt = new AsyncReply();
var tupleSize = data[offset++];
length--;
var types = <Type>[];
for (var i = 0; i < tupleSize; i++) {
var rep = RepresentationType.parse(data, offset);
if (rep.type != null) types.add(rep.type.getRuntimeType() ?? Object);
offset += rep.size;
length -= rep.size;
}
while (length > 0) {
var parsed = Codec.parse(data, offset, connection);
results.add(parsed.reply);
if (parsed.size > 0) {
offset += parsed.size;
length -= parsed.size;
} else
throw new Exception("Error while parsing structured data");
}
results.seal();
results.then((ar) {
rt.trigger(Tuple(ar));
});
return rt;
}
static AsyncReply typedListParser(
DC data, int offset, int length, DistributedConnection? connection) {
var rt = new AsyncBag();
// get the type
var rep = RepresentationType.parse(data, offset);
offset += rep.size;
length -= rep.size;
var runtimeType = rep.type.getRuntimeType();
rt.arrayType = runtimeType;
while (length > 0) {
var parsed = Codec.parse(data, offset, connection);
rt.add(parsed.reply);
if (parsed.size > 0) {
offset += parsed.size;
length -= parsed.size;
} else
throw new Exception("Error while parsing structured data");
}
rt.seal();
return rt;
}
static AsyncBag<PropertyValue> PropertyValueArrayParser(
DC data,
int offset,
int length,
DistributedConnection? connection) //, bool ageIncluded = true)
{
var rt = new AsyncBag<PropertyValue>();
listParser(data, offset, length, connection).then((x) {
var pvs = <PropertyValue>[];
for (var i = 0; i < x.length; i += 3)
pvs.add(new PropertyValue(x[2], x[0] as int, x[1] as DateTime));
rt.trigger(pvs);
});
return rt;
}
static PropertyValueParserResults propertyValueParser(DC data, int offset,
DistributedConnection? connection) //, bool ageIncluded = true)
{
var reply = new AsyncReply<PropertyValue>();
var age = data.getUint64(offset);
offset += 8;
DateTime date = data.getDateTime(offset);
offset += 8;
var parsed = Codec.parse(data, offset, connection);
parsed.reply.then((value) {
reply.trigger(new PropertyValue(value, age, date));
});
return PropertyValueParserResults(16 + parsed.size, reply);
}
static AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>>
historyParser(DC data, int offset, int length, IResource resource,
DistributedConnection? connection) {
throw Exception("Not implemented");
// @TODO
// var list = new KeyList<PropertyTemplate, List<PropertyValue>>();
// var reply = new AsyncReply<KeyList<PropertyTemplate, List<PropertyValue[]>>>();
// var bagOfBags = new AsyncBag<PropertyValue[]>();
// var ends = offset + length;
// 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;
// var (len, pv) = PropertyValueParser(data, offset, connection);
// bagOfBags.Add(pv);// ParsePropertyValueArray(data, offset, cs, connection));
// offset += len;
// }
// bagOfBags.Seal();
// bagOfBags.Then(x =>
// {
// for (var i = 0; i < list.Count; i++)
// list[list.Keys.ElementAt(i)] = x[i];
// reply.Trigger(list);
// });
// return reply;
}
}

View File

@ -0,0 +1,406 @@
import 'BinaryList.dart';
import 'Codec.dart';
import 'IRecord.dart';
import '../Net/IIP/DistributedResource.dart';
import '../Resource/IResource.dart';
import '../Resource/Warehouse.dart';
import '../Resource/Template/PropertyTemplate.dart';
import 'PropertyValue.dart';
import './TransmissionType.dart';
import '../Net/IIP/DistributedConnection.dart';
import 'DC.dart';
import 'RepresentationType.dart';
import 'IntType.dart';
class DataSerializerComposeResults {
int identifier;
DC data;
DataSerializerComposeResults(this.identifier, this.data);
}
class DataSerializer {
//public delegate byte[] Serializer(object value);
static DC historyComposer(Map<PropertyTemplate, List<PropertyValue>> history,
DistributedConnection connection,
[bool prependLength = false]) {
throw Exception("Not implemented");
}
static DataSerializerComposeResults int32Composer(
value, DistributedConnection? connection) {
var rt = new DC(4);
rt.setInt32(0, (value as Int32).toInt());
return DataSerializerComposeResults(TransmissionTypeIdentifier.Int32, rt);
}
static DataSerializerComposeResults uInt32Composer(
value, DistributedConnection? connection) {
var rt = new DC(4);
rt.setUint32(0, (value as UInt32).toInt());
return DataSerializerComposeResults(TransmissionTypeIdentifier.UInt32, rt);
}
static DataSerializerComposeResults int16Composer(
value, DistributedConnection? connection) {
var rt = new DC(2);
rt.setInt16(0, (value as Int16).toInt());
return DataSerializerComposeResults(TransmissionTypeIdentifier.Int16, rt);
}
static DataSerializerComposeResults uInt16Composer(
value, DistributedConnection? connection) {
var rt = new DC(2);
rt.setUint16(0, (value as UInt16).toInt());
return DataSerializerComposeResults(TransmissionTypeIdentifier.UInt16, rt);
}
static DataSerializerComposeResults float32Composer(
value, DistributedConnection? connection) {
var rt = new DC(4);
rt.setFloat32(0, value as double);
return DataSerializerComposeResults(TransmissionTypeIdentifier.Float32, rt);
}
static DataSerializerComposeResults float64Composer(
value, DistributedConnection? connection) {
var rt = new DC(8);
rt.setFloat64(0, value as double);
return DataSerializerComposeResults(TransmissionTypeIdentifier.Float64, rt);
}
static DataSerializerComposeResults int64Composer(
value, DistributedConnection? connection) {
var rt = new DC(8);
rt.setInt64(0, value as int);
return DataSerializerComposeResults(TransmissionTypeIdentifier.Int64, rt);
}
static DataSerializerComposeResults uInt64Composer(
value, DistributedConnection? connection) {
var rt = new DC(8);
rt.setUint64(0, value as int);
return DataSerializerComposeResults(TransmissionTypeIdentifier.UInt64, rt);
}
static DataSerializerComposeResults dateTimeComposer(
value, DistributedConnection? connection) {
var rt = new DC(8);
rt.setDateTime(0, value as DateTime);
return DataSerializerComposeResults(
TransmissionTypeIdentifier.DateTime, rt);
}
static DataSerializerComposeResults float128Composer(
value, DistributedConnection? connection) {
//@TODO: implement decimal
var rt = new DC(16);
rt.setFloat64(0, value as double);
return DataSerializerComposeResults(TransmissionTypeIdentifier.Float64, rt);
}
static DataSerializerComposeResults stringComposer(
value, DistributedConnection? connection) {
return DataSerializerComposeResults(
TransmissionTypeIdentifier.String, DC.stringToBytes(value as String));
}
static DataSerializerComposeResults enumComposer(
value, DistributedConnection? connection) {
if (value == null)
return DataSerializerComposeResults(
TransmissionTypeIdentifier.Null, DC(0));
var template = Warehouse.getTemplateByType(value.runtimeType);
if (template == null)
return DataSerializerComposeResults(
TransmissionTypeIdentifier.Null, DC(0));
var cts = template.constants.where((x) => x.value == value);
if (cts.isEmpty)
return DataSerializerComposeResults(
TransmissionTypeIdentifier.Null, DC(0));
var rt = BinaryList();
rt.addGuid(template.classId);
rt.addUint8(cts.first.index);
return DataSerializerComposeResults(
TransmissionTypeIdentifier.Enum, rt.toDC());
}
static DataSerializerComposeResults uInt8Composer(
value, DistributedConnection? connection) {
var rt = new DC(1);
rt[0] = (value as UInt8).toInt();
return DataSerializerComposeResults(TransmissionTypeIdentifier.UInt8, rt);
}
static DataSerializerComposeResults int8Composer(
value, DistributedConnection? connection) {
var rt = new DC(1);
rt[0] = (value as Int8).toInt();
return DataSerializerComposeResults(TransmissionTypeIdentifier.Int8, rt);
}
static DataSerializerComposeResults char8Composer(
value, DistributedConnection? connection) {
var rt = new DC(1);
rt[0] = value as int;
return DataSerializerComposeResults(TransmissionTypeIdentifier.Char8, rt);
}
static DataSerializerComposeResults char16Composer(
value, DistributedConnection? connection) {
var rt = new DC(2);
rt.setUint16(0, value as int);
return DataSerializerComposeResults(TransmissionTypeIdentifier.Char16, rt);
}
static DataSerializerComposeResults boolComposer(
value, DistributedConnection? connection) {
return DataSerializerComposeResults(
value as bool
? TransmissionTypeIdentifier.True
: TransmissionTypeIdentifier.False,
DC(0));
}
static DataSerializerComposeResults notModifiedComposer(
value, DistributedConnection? connection) {
return DataSerializerComposeResults(
TransmissionTypeIdentifier.NotModified, DC(0));
}
static DataSerializerComposeResults rawDataComposer(
value, DistributedConnection? connection) {
return DataSerializerComposeResults(
TransmissionTypeIdentifier.RawData, value as DC);
}
static DataSerializerComposeResults listComposer(
value, DistributedConnection? connection) {
if (value == null)
return DataSerializerComposeResults(
TransmissionTypeIdentifier.Null, DC(0));
else
return DataSerializerComposeResults(TransmissionTypeIdentifier.List,
arrayComposer(value as List, connection));
//var rt = new List<byte>();
//var list = (IEnumerable)value;// ((List<object>)value);
//foreach (var o in list)
// rt.AddRange(Codec.Compose(o, connection));
//return (TransmissionTypeIdentifier.List, rt.ToArray());
}
static DataSerializerComposeResults typedListComposer(
value, Type type, DistributedConnection? connection) {
if (value == null)
return DataSerializerComposeResults(
TransmissionTypeIdentifier.Null, DC(0));
var composed = arrayComposer(value as List, connection);
var header =
(RepresentationType.fromType(type) ?? RepresentationType.Dynamic)
.compose();
var rt = new BinaryList()
..addDC(header)
..addDC(composed);
return DataSerializerComposeResults(
TransmissionTypeIdentifier.TypedList, rt.toDC());
}
static DataSerializerComposeResults propertyValueArrayComposer(
value, DistributedConnection? connection) {
if (value == null)
return DataSerializerComposeResults(
TransmissionTypeIdentifier.Null, DC(0));
var rt = BinaryList();
var ar = value as List<PropertyValue>;
for (var pv in ar) {
rt.addDC(Codec.compose(pv.age, connection));
rt.addDC(Codec.compose(pv.date, connection));
rt.addDC(Codec.compose(pv.value, connection));
}
return DataSerializerComposeResults(
TransmissionTypeIdentifier.List, rt.toDC());
}
static DataSerializerComposeResults typedMapComposer(
value, Type keyType, Type valueType, DistributedConnection? connection) {
if (value == null)
return DataSerializerComposeResults(
TransmissionTypeIdentifier.Null, DC(0));
var kt =
(RepresentationType.fromType(keyType) ?? RepresentationType.Dynamic)
.compose();
var vt =
(RepresentationType.fromType(valueType) ?? RepresentationType.Dynamic)
.compose();
var rt = BinaryList();
rt.addDC(kt);
rt.addDC(vt);
var map = value as Map;
for (var el in map.entries) {
rt.addDC(Codec.compose(el.key, connection));
rt.addDC(Codec.compose(el.value, connection));
}
return DataSerializerComposeResults(
TransmissionTypeIdentifier.TypedMap, rt.toDC());
}
static DC arrayComposer(List value, DistributedConnection? connection) {
var rt = BinaryList();
for (var i in value) rt.addDC(Codec.compose(i, connection));
return rt.toDC();
}
static DataSerializerComposeResults resourceListComposer(
value, DistributedConnection? connection) {
if (value == null)
return DataSerializerComposeResults(
TransmissionTypeIdentifier.Null, DC(0));
return DataSerializerComposeResults(TransmissionTypeIdentifier.ResourceList,
arrayComposer(value as List, connection));
}
static DataSerializerComposeResults recordListComposer(
value, DistributedConnection? connection) {
if (value == null)
return DataSerializerComposeResults(
TransmissionTypeIdentifier.Null, DC(0));
return DataSerializerComposeResults(TransmissionTypeIdentifier.RecordList,
arrayComposer(value as List, connection));
}
static DataSerializerComposeResults resourceComposer(
value, DistributedConnection? connection) {
var resource = value as IResource;
var rt = new DC(4);
if (Codec.isLocalResource(resource, connection)) {
rt.setUint32(0, (resource as DistributedResource).id ?? 0);
return DataSerializerComposeResults(
TransmissionTypeIdentifier.ResourceLocal, rt);
} else {
// @TODO: connection.cache.Add(value as IResource, DateTime.UtcNow);
rt.setUint32(0, resource.instance?.id ?? 0);
return DataSerializerComposeResults(
TransmissionTypeIdentifier.Resource, rt);
}
}
static DataSerializerComposeResults mapComposer(
value, DistributedConnection? connection) {
if (value == null)
return DataSerializerComposeResults(
TransmissionTypeIdentifier.Null, DC(0));
var rt = BinaryList();
var map = value as Map;
for (var el in map.entries) {
rt.addDC(Codec.compose(el.key, connection));
rt.addDC(Codec.compose(el.value, connection));
}
return DataSerializerComposeResults(
TransmissionTypeIdentifier.Map, rt.toDC());
}
static DataSerializerComposeResults recordComposer(
value, DistributedConnection? connection) {
var rt = BinaryList();
var record = value as IRecord;
var template = Warehouse.getTemplateByType(record.runtimeType);
if (template == null)
return DataSerializerComposeResults(
TransmissionTypeIdentifier.Null, DC(0));
rt.addDC(DC.guidToBytes(template.classId));
var recordData = record.serialize();
for (var pt in template.properties) {
var propValue = recordData[pt.name];
rt.addDC(Codec.compose(propValue, connection));
}
return DataSerializerComposeResults(
TransmissionTypeIdentifier.Record, rt.toDC());
}
// TODO:
// static DataSerializerComposeResults historyComposer(KeyList<PropertyTemplate, PropertyValue[]> history,
// DistributedConnection connection, bool prependLength = false)
// {
// //@TODO:Test
// var rt = new BinaryList();
// for (var i = 0; i < history.Count; i++)
// rt.AddUInt8(history.Keys.ElementAt(i).Index)
// .AddUInt8Array(Codec.Compose(history.Values.ElementAt(i), connection));
// if (prependLength)
// rt.InsertInt32(0, rt.Length);
// return rt.ToArray();
// }
static DataSerializerComposeResults TupleComposer(
value, DistributedConnection? connection) {
//if (value == null)
return DataSerializerComposeResults(TransmissionTypeIdentifier.Null, DC(0));
//@TODO
// var rt = BinaryList();
// var fields = value.GetType().GetFields();
// var list = fields.Select(x => x.GetValue(value)).ToArray();
// var types = fields.Select(x => RepresentationType.FromType(x.FieldType).Compose()).ToArray();
// rt.Add((byte)list.Length);
// foreach (var t in types)
// rt.AddRange(t);
// var composed = ArrayComposer(list, connection);
// if (composed == null)
// return (TransmissionTypeIdentifier.Null, new byte[0]);
// else
// {
// rt.AddRange(composed);
// return (TransmissionTypeIdentifier.Tuple, rt.ToArray());
// }
}
}

View File

@ -1,116 +0,0 @@
/*
Copyright (c) 2019 Ahmed Kh. Zamil
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
class DataType
{
static const int Void = 0x0,
//Variant,
Bool = 1,
Int8 = 2,
UInt8 = 3,
Char = 4,
Int16 = 5,
UInt16 = 6,
Int32 = 7,
UInt32 = 8,
Int64 = 9,
UInt64 = 0xA,
Float32 = 0xB,
Float64 = 0xC,
Decimal = 0xD,
DateTime = 0xE,
Resource = 0xF,
DistributedResource = 0x10,
ResourceLink = 0x11,
String = 0x12,
Structure = 0x13,
Record = 0x14,
//Stream,
//Array = 0x80,
VarArray = 0x80,
BoolArray = 0x81,
Int8Array = 0x82,
UInt8Array = 0x83,
CharArray = 0x84,
Int16Array = 0x85,
UInt16Array = 0x86,
Int32Array = 0x87,
UInt32Array = 0x88,
Int64Array = 0x89,
UInt64Array = 0x8A,
Float32Array = 0x8B,
Float64Array = 0x8C,
DecimalArray = 0x8D,
DateTimeArray = 0x8E,
ResourceArray = 0x8F,
DistributedResourceArray = 0x90,
ResourceLinkArray = 0x91,
StringArray = 0x92,
StructureArray = 0x93,
RecordArray = 0x94,
NotModified = 0x7F,
Unspecified = 0xFF;
static bool isArray(int type)
{
return ((type & 0x80) == 0x80) && (type != NotModified);
}
static int getElementType(int type)
{
return type & 0x7F;
}
static int size(int type)
{
switch (type)
{
case DataType.Void:
case DataType.NotModified:
return 0;
case DataType.Bool:
case DataType.UInt8:
case DataType.Int8:
return 1;
case DataType.Char:
case DataType.UInt16:
case DataType.Int16:
return 2;
case DataType.Int32:
case DataType.UInt32:
case DataType.Float32:
case DataType.Resource:
return 4;
case DataType.Int64:
case DataType.UInt64:
case DataType.Float64:
case DataType.DateTime:
return 8;
case DataType.DistributedResource:
return 4;
default:
return -1;
}
}
}

View File

@ -1,10 +1,12 @@
import 'DC.dart';
class Guid {
DC _data;
late DC _data;
Guid(this._data) {
Guid(this._data) {}
Guid.fromString(String data) {
_data = DC.fromHex(data, '');
}
DC get value => _data;
@ -18,7 +20,7 @@ class Guid {
@override
String toString() {
return _data.getString(0, _data.length);
return _data.toHex('');
}
@override

15
lib/src/Data/IEnum.dart Normal file
View File

@ -0,0 +1,15 @@
import '../Resource/Template/TemplateDescriber.dart';
class IEnum {
int index = 0;
dynamic value;
String name = '';
IEnum([this.index = 0, this.value, this.name = ""]);
TemplateDescriber get template => TemplateDescriber("IEnum");
@override
String toString() {
return '${name}<$value>';
}
}

View File

@ -24,9 +24,13 @@ SOFTWARE.
import '../Resource/Template/TemplateDescriber.dart';
abstract class IRecord {
Map<String, dynamic> serialize();
void deserialize(Map<String, dynamic> value);
TemplateDescriber get template;
@override
String toString() {
return serialize().toString();
}
}

69
lib/src/Data/IntType.dart Normal file
View File

@ -0,0 +1,69 @@
class IntType {
int _value = 0;
bool operator ==(Object other) {
if (other is IntType)
return this._value == other._value;
else if (other is int) return this._value == other;
return false;
}
IntType(this._value);
bool operator >(IntType other) {
return this._value > other._value;
}
bool operator <(IntType other) {
return this._value < other._value;
}
bool operator >=(IntType other) {
return this._value >= other._value;
}
bool operator <=(IntType other) {
return this._value <= other._value;
}
operator +(IntType other) {
this._value += other._value;
}
operator -(IntType other) {
this._value -= other._value;
}
int toInt() => _value;
@override
String toString() => _value.toString();
@override
int get hashCode => _value.hashCode;
}
class Int32 extends IntType {
Int32(int value) : super(value);
}
class Int16 extends IntType {
Int16(int value) : super(value);
}
class Int8 extends IntType {
Int8(int value) : super(value);
}
class UInt32 extends IntType {
UInt32(int value) : super(value);
}
class UInt16 extends IntType {
UInt16(int value) : super(value);
}
class UInt8 extends IntType {
UInt8(int value) : super(value);
}

View File

@ -37,9 +37,12 @@ class KeyList<KT, T> extends IEventHandler with MapMixin<KT, T> {
Iterable<KT> get keys => _map.keys;
Iterable<T> get values => _map.values;
operator [](index) => _map[index];
//T? operator [](Object? key);
//operator []=(KT key, T value);
operator []=(index, value) => add(index, value);
T? operator [](Object? index) => _map[index];
operator []=(KT index, T value) => add(index, value);
at(int index) => _map.values.elementAt(index);
@ -101,8 +104,7 @@ class KeyList<KT, T> extends IEventHandler with MapMixin<KT, T> {
var value = _map[key];
if (_removableList)
(value as IDestructible).off("destroy", _itemDestroyed);
if (_removableList) (value as IDestructible).off("destroy", _itemDestroyed);
_map.remove(key);

View File

@ -1,9 +1,11 @@
import 'dart:collection';
import '../Resource/Template/TemplateDescriber.dart';
import 'IRecord.dart';
import 'KeyList.dart';
class Record extends KeyList with IRecord {
class Record extends IRecord with MapMixin<String, dynamic> {
Map<String, dynamic> _props = Map<String, dynamic>();
@override
@ -17,9 +19,29 @@ class Record extends KeyList with IRecord {
}
operator [](index) => _props[index];
operator []=(index, value) => _props[index] = value;
operator []=(String index, value) => _props[index] = value;
@override
String toString() {
return _props.toString();
}
@override
// TODO: implement template
TemplateDescriber get template => throw UnimplementedError();
@override
void clear() {
// TODO: implement clear
}
@override
// TODO: implement keys
Iterable<String> get keys => _props.keys;
@override
remove(Object? key) {
// TODO: implement remove
throw UnimplementedError();
}
}

View File

@ -1,8 +0,0 @@
class RecordComparisonResult {
static const Null = 0;
static const Record = 1;
static const RecordSameType = 2;
static const Same = 3;
static const Empty = 4;
}

View File

@ -0,0 +1,242 @@
import 'IEnum.dart';
import '../Resource/Template/TemplateType.dart';
import 'IRecord.dart';
import '../Resource/IResource.dart';
import '../Resource/Warehouse.dart';
import 'BinaryList.dart';
import 'DC.dart';
import 'Guid.dart';
import 'package:collection/collection.dart';
class RepresentationTypeIdentifier {
static const int Void = 0x0,
Dynamic = 0x1,
Bool = 0x2,
UInt8 = 0x3,
Int8 = 0x4,
Char = 0x5,
Int16 = 0x6,
UInt16 = 0x7,
Int32 = 0x8,
UInt32 = 0x9,
Float32 = 0xA,
Int64 = 0xB,
UInt64 = 0xC,
Float64 = 0xD,
DateTime = 0xE,
Int128 = 0xF,
UInt128 = 0x10,
Decimal = 0x11,
String = 0x12,
RawData = 0x13,
Resource = 0x14,
Record = 0x15,
List = 0x16,
Map = 0x17,
Enum = 0x18,
TypedResource = 0x45, // Followed by UUID
TypedRecord = 0x46, // Followed by UUID
TypedList = 0x48, // Followed by element type
Tuple2 = 0x50, // Followed by element type
TypedMap = 0x51, // Followed by key type and value type
Tuple3 = 0x58,
Tuple4 = 0x60,
Tuple5 = 0x68,
Tuple6 = 0x70,
Tuple7 = 0x78;
}
class DumClass<T> {
Type type = T;
}
Type getNullableType<T>() => DumClass<T?>().type;
Type getTypeOf<T>() => DumClass<T>().type;
class RepresentationTypeParseResults {
RepresentationType type;
int size;
RepresentationTypeParseResults(this.size, this.type);
}
class RepresentationType {
static Type getTypeFromName(String name) {
const Map<String, Type> types = {
"int": int,
"bool": bool,
"double": double,
"String": String,
"IResource": IResource,
"IRecord": IRecord,
"IEnum": IEnum,
"DC": DC,
};
if (types.containsKey(name)) {
return types[name]!;
} else
return Object().runtimeType;
}
RepresentationType toNullable() {
return RepresentationType(identifier, true, guid, subTypes);
}
static RepresentationType Void =
RepresentationType(RepresentationTypeIdentifier.Void, true, null, null);
static RepresentationType Dynamic = RepresentationType(
RepresentationTypeIdentifier.Dynamic, true, null, null);
static RepresentationType? fromType(Type type) {
return Warehouse.typesFactory[type]?.representationType;
//Warehouse.typesFactory.values.firstWhereOrNull(x => x.representationType == )
//return RepresentationType(
// RepresentationTypeIdentifier.Dynamic, true, null, null);
}
// @TODO : complete this;
// static RepresentationType? fromType(Type type)
// {
// var typeName = type.toString();
// var nullable = typeName.endsWith('?');
// if (nullable)
// typeName = typeName.substring(0, typeName.length - 1);
// if (typeName.endsWith('>')) // generic type
// {
// // get args
// var argsRex = RegExp(r"(\b[^<>]+)\<(.*)\>$");
// var matches = argsRex.allMatches(typeName);
// var name = matches.elementAt(0).input; // name
// var argsStr = matches.elementAt(1).input;
// var eachArg = RegExp(r"([^,]+\(.+?\))|([^,]+)");
// var args = eachArg.allMatches(argsStr);
// // parse sub types
// if (name == "List") {
// // get sub type
// getTypeFromName(args.first.input);
// return RepresentationType(RepresentationTypeIdentifier.TypedList, nullable, guid, subTypes)
// }
// }
// }
Map<int, List<Type>> runtimeTypes = {
RepresentationTypeIdentifier.Void: [dynamic, dynamic],
RepresentationTypeIdentifier.Dynamic: [dynamic, dynamic],
RepresentationTypeIdentifier.Bool: [bool, getNullableType<bool>()],
RepresentationTypeIdentifier.Char: [String, getNullableType<String>()],
RepresentationTypeIdentifier.UInt8: [int, getNullableType<int>()],
RepresentationTypeIdentifier.Int8: [int, getNullableType<int>()],
RepresentationTypeIdentifier.Int16: [int, getNullableType<int>()],
RepresentationTypeIdentifier.UInt16: [int, getNullableType<int>()],
RepresentationTypeIdentifier.Int32: [int, getNullableType<int>()],
RepresentationTypeIdentifier.UInt32: [int, getNullableType<int>()],
RepresentationTypeIdentifier.Int64: [int, getNullableType<int>()],
RepresentationTypeIdentifier.UInt64: [int, getNullableType<int>()],
RepresentationTypeIdentifier.Float32: [double, getNullableType<double>()],
RepresentationTypeIdentifier.Float64: [double, getNullableType<double>()],
RepresentationTypeIdentifier.Decimal: [double, getNullableType<double>()],
RepresentationTypeIdentifier.String: [String, getNullableType<String>()],
RepresentationTypeIdentifier.DateTime: [
DateTime,
getNullableType<DateTime>()
],
RepresentationTypeIdentifier.Resource: [
IResource,
getNullableType<IResource>()
],
RepresentationTypeIdentifier.Record: [IRecord, getNullableType<IRecord>()],
};
Type? getRuntimeType() {
if (runtimeTypes.containsKey(identifier))
return nullable
? runtimeTypes[identifier]![1]
: runtimeTypes[identifier]![0];
if (identifier == RepresentationTypeIdentifier.TypedRecord)
return Warehouse.getTemplateByClassId(guid!, TemplateType.Record)
?.definedType;
else if (identifier == RepresentationTypeIdentifier.TypedResource)
return Warehouse.getTemplateByClassId(guid!, TemplateType.Unspecified)
?.definedType;
else if (identifier == RepresentationTypeIdentifier.Enum)
return Warehouse.getTemplateByClassId(guid!, TemplateType.Enum)
?.definedType;
return null;
}
int identifier;
bool nullable;
Guid? guid;
List<RepresentationType>? subTypes;
RepresentationType(this.identifier, this.nullable,
[this.guid, this.subTypes]) {}
DC compose() {
var rt = BinaryList();
if (nullable)
rt.addUint8(0x80 | identifier);
else
rt.addUint8(identifier);
if (guid != null) rt.addDC(DC.guidToBytes(guid!));
if (subTypes != null)
for (var i = 0; i < subTypes!.length; i++)
rt.addDC(subTypes![i].compose());
return rt.toDC();
}
//public override string ToString() => Identifier.ToString() + (Nullable ? "?" : "")
// + TypeTemplate != null ? "<" + TypeTemplate.ClassName + ">" : "";
static RepresentationTypeParseResults parse(DC data, int offset) {
var oOffset = offset;
var header = data[offset++];
bool nullable = (header & 0x80) > 0;
var identifier = (header & 0x7F);
if ((header & 0x40) > 0) {
var hasGUID = (header & 0x4) > 0;
var subsCount = (header >> 3) & 0x7;
Guid? guid = null;
if (hasGUID) {
guid = data.getGuid(offset);
offset += 16;
}
var subs = <RepresentationType>[];
for (var i = 0; i < subsCount; i++) {
var parsed = RepresentationType.parse(data, offset);
subs.add(parsed.type);
offset += parsed.size;
}
return RepresentationTypeParseResults(offset - oOffset,
RepresentationType(identifier, nullable, guid, subs));
} else {
return RepresentationTypeParseResults(
1, RepresentationType(identifier, nullable, null, null));
}
}
}

View File

@ -1,7 +0,0 @@
class ResourceComparisonResult {
static const Null = 0;
static const Distributed = 1;
static const Local = 2;
static const Same = 3;
static const Empty = 4;
}

View File

@ -1,59 +0,0 @@
/*
Copyright (c) 2019 Ahmed Kh. Zamil
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import 'dart:collection';
class Structure with MapMixin<String, Object>//, IterableMixin<String>
{
Map<String, Object> _map = new Map<String, Object>();
Iterator<String> get iterator => _map.keys.iterator;
Iterable<String> get keys => _map.keys;
operator[](index) => _map[index];
operator []= (index, value) => _map[index] = value;
remove(key) => _map.remove(key);
clear() => _map.clear();
at(int index) => _map.values.elementAt(index);
List<String> getKeys() => _map.keys.toList();
Structure.fromMap(Map map)
{
for(var i in map.keys)
_map[i.toString()] = map[i];
}
Structure()
{
// do nothing
}
}

View File

@ -1,8 +0,0 @@
class StructureComparisonResult
{
static const int Null = 0;
static const int Structure = 1;
static const int StructureSameKeys = 2;
static const int StructureSameTypes = 3;
static const int Same = 4;
}

View File

@ -1,6 +0,0 @@
class StructureMetadata {
List<String>? keys; // = <String>[];
List<int>? types;//
//const StructureMetadata(this.keys, this.types);
}

View File

@ -0,0 +1,189 @@
import "DC.dart";
class TransmissionTypeIdentifier {
static const int Null = 0x0,
False = 0x1,
True = 0x2,
NotModified = 0x3,
UInt8 = 0x8,
Int8 = 0x9,
Char8 = 0xA,
Int16 = 0x10,
UInt16 = 0x11,
Char16 = 0x12,
Int32 = 0x18,
UInt32 = 0x19,
Float32 = 0x1A,
Resource = 0x1B,
ResourceLocal = 0x1C,
Int64 = 0x20,
UInt64 = 0x21,
Float64 = 0x22,
DateTime = 0x23,
Int128 = 0x28,
UInt128 = 0x29,
Float128 = 0x2A,
RawData = 0x40,
String = 0x41,
List = 0x42,
ResourceList = 0x43,
RecordList = 0x44,
Map = 0x45,
MapList = 0x46,
//Tuple = 0x47,
Record = 0x80,
TypedList = 0x81,
TypedMap = 0x82,
Tuple = 0x83,
Enum = 0x84,
Constant = 0x85;
//TypedResourceList = 0x81,
//TypedRecordList = 0x82,
}
class TransmissionTypeClass {
static const int Fixed = 0, Dynamic = 1, Typed = 2;
}
class TransmissionTypeParseResults {
int size;
TransmissionType? type;
TransmissionTypeParseResults(this.size, this.type) {}
}
class TransmissionType {
final int identifier;
final int index;
final int classType;
final int offset;
final int contentLength;
final int exponent;
static const TransmissionType Null =
TransmissionType(TransmissionTypeIdentifier.Null, 0, 0, 0, 0);
const TransmissionType(this.identifier, this.classType, this.index,
this.offset, this.contentLength,
[this.exponent = 0]);
static DC compose(int identifier, DC data) {
if (data.length == 0) return DC.fromList([identifier]);
var cls = identifier >> 6;
if (cls == TransmissionTypeClass.Fixed) {
return DC.combine([identifier], 0, 1, data, 0, data.length);
} else {
var len = data.length;
if (len == 0) {
return DC.fromList([identifier]);
} else if (len <= 0xFF) {
var rt = DC(2 + len);
rt[0] = identifier | 0x8;
rt[1] = len;
rt.set(data, 0, 2, len);
return rt;
} else if (len <= 0xFFFF) {
var rt = DC(3 + len);
rt[0] = identifier | 0x10;
rt[1] = (len >> 8) & 0xFF;
rt[2] = len & 0xFF;
rt.set(data, 0, 3, len);
return rt;
} else if (len <= 0xFFFFFF) {
var rt = DC(4 + len);
rt[0] = identifier | 0x18;
rt[1] = (len >> 16) & 0xFF;
rt[2] = (len >> 8) & 0xFF;
rt[3] = len & 0xFF;
rt.set(data, 0, 4, len);
return rt;
} else if (len <= 0xFFFFFFFF) {
var rt = DC(5 + len);
rt[0] = (identifier | 0x20);
rt[1] = ((len >> 24) & 0xFF);
rt[2] = ((len >> 16) & 0xFF);
rt[3] = ((len >> 8) & 0xFF);
rt[4] = (len & 0xFF);
rt.set(data, 0, 5, len);
return rt;
} else if (len <= 0xFFFFFFFFFF) {
var rt = DC(6 + len);
rt[0] = identifier | 0x28;
rt[1] = ((len >> 32) & 0xFF);
rt[2] = ((len >> 24) & 0xFF);
rt[3] = ((len >> 16) & 0xFF);
rt[4] = ((len >> 8) & 0xFF);
rt[5] = (len & 0xFF);
rt.set(data, 0, 6, len);
return rt;
} else if (len <= 0xFFFFFFFFFFFF) {
var rt = DC(7 + len);
rt[0] = identifier | 0x30;
rt[1] = (len >> 40) & 0xFF;
rt[2] = (len >> 32) & 0xFF;
rt[3] = (len >> 24) & 0xFF;
rt[4] = (len >> 16) & 0xFF;
rt[5] = (len >> 8) & 0xFF;
rt[6] = len & 0xFF;
rt.set(data, 0, 7, len);
return rt;
} else //if (len <= 0xFF_FF_FF_FF_FF_FF_FF)
{
var rt = DC(8 + len);
rt[0] = identifier | 0x38;
rt[1] = (len >> 48) & 0xFF;
rt[2] = (len >> 40) & 0xFF;
rt[3] = (len >> 32) & 0xFF;
rt[4] = (len >> 24) & 0xFF;
rt[5] = (len >> 16) & 0xFF;
rt[6] = (len >> 8) & 0xFF;
rt[7] = len & 0xFF;
data.set(data, 0, 8, len);
return rt;
}
}
}
static TransmissionTypeParseResults parse(DC data, int offset, int ends) {
var h = data[offset++];
var cls = h >> 6;
if (cls == TransmissionTypeClass.Fixed) {
var exp = (h & 0x38) >> 3;
if (exp == 0)
return TransmissionTypeParseResults(
1, TransmissionType(h, cls, h & 0x7, 0, exp));
int cl = (1 << (exp - 1));
if (ends - offset < cl)
return TransmissionTypeParseResults(ends - offset - cl, null);
return TransmissionTypeParseResults(
1 + cl, new TransmissionType(h, cls, h & 0x7, offset, cl, exp));
} else {
int cll = (h >> 3) & 0x7;
if (ends - offset < cll)
return TransmissionTypeParseResults(ends - offset - cll, null);
int cl = 0;
for (var i = 0; i < cll; i++) cl = cl << 8 | data[offset++];
return TransmissionTypeParseResults(
1 + cl + cll, TransmissionType((h & 0xC7), cls, h & 0x7, offset, cl));
}
}
}

View File

@ -3,7 +3,7 @@ import 'dart:math';
class Global {
static String generateCode(
[int length = 16,
chars =
String chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"]) {
var rand = Random();

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,8 @@ SOFTWARE.
import 'dart:async';
import '../../Data/IntType.dart';
import '../../Resource/Instance.dart';
import '../../Core/AsyncException.dart';
@ -37,7 +39,6 @@ import '../../Data/KeyValuePair.dart';
import '../../Resource/IResource.dart';
import '../../Core/AsyncReply.dart';
import '../../Data/PropertyValue.dart';
import '../../Data/Structure.dart';
import '../../Data/Codec.dart';
import './DistributedConnection.dart';
import '../Packets/IIPPacketAction.dart';
@ -196,7 +197,7 @@ class DistributedResource extends IResource {
EventTemplate? et = event is EventTemplate
? event
: instance?.template.getEventTemplateByName(event);
: instance?.template.getEventTemplateByName(event.toString());
if (et == null)
return AsyncReply<dynamic>().triggerError(new AsyncException(
@ -216,7 +217,7 @@ class DistributedResource extends IResource {
EventTemplate? et = event is EventTemplate
? event
: instance?.template.getEventTemplateByName(event);
: instance?.template.getEventTemplateByName(event.toString());
if (et == null)
return AsyncReply().triggerError(new AsyncException(
@ -237,28 +238,11 @@ class DistributedResource extends IResource {
var et = instance?.template.getEventTemplateByIndex(index);
if (et != null) {
emitArgs(et.name, [args]);
instance?.emitResourceEvent(null, null, et.name, args);
instance?.emitResourceEvent(null, null, et, args);
}
}
AsyncReply<dynamic> internal_invokeByNamedArguments(
int index, Structure namedArgs) {
if (_destroyed) throw new Exception("Trying to access destroyed object");
if (_suspended) throw new Exception("Trying to access suspended object");
if (instance == null) throw Exception("Object not initialized.");
var ins = instance as Instance;
if (index >= ins.template.functions.length)
throw new Exception("Function index is incorrect");
return connection?.sendInvokeByNamedArguments(
_instanceId as int, index, namedArgs) as AsyncReply<dynamic>;
}
AsyncReply<dynamic> internal_invokeByArrayArguments(
int index, List<dynamic> args) {
AsyncReply<dynamic> internal_invoke(int index, Map<UInt8, dynamic> args) {
if (_destroyed) throw new Exception("Trying to access destroyed object");
if (_suspended) throw new Exception("Trying to access suspended object");
@ -269,8 +253,8 @@ class DistributedResource extends IResource {
if (index >= ins.template.functions.length)
throw new Exception("Function index is incorrect");
return _connection?.sendInvokeByArrayArguments(
_instanceId as int, index, args) as AsyncReply;
return _connection?.sendInvoke(_instanceId as int, index, args)
as AsyncReply;
}
operator [](String index) {
@ -299,17 +283,25 @@ class DistributedResource extends IResource {
var ft = instance?.template.getFunctionTemplateByName(memberName);
if (_attached && ft != null) {
if (invocation.namedArguments.length > 0) {
var namedArgs = new Structure();
for (var p in invocation.namedArguments.keys)
namedArgs[_getMemberName(p)] = invocation.namedArguments[p];
var args = Map<UInt8, dynamic>();
return internal_invokeByNamedArguments(ft.index, namedArgs);
} else {
return internal_invokeByArrayArguments(
ft.index, invocation.positionalArguments);
for (var i = 0;
i < invocation.positionalArguments.length &&
i < ft.arguments.length;
i++) args[UInt8(i)] = invocation.positionalArguments[i];
for (var i = invocation.positionalArguments.length;
i < ft.arguments.length;
i++) {
for (var j = 0; j < invocation.namedArguments.length; j++) {
if (ft.arguments[i].name ==
_getMemberName(invocation.namedArguments.keys.elementAt(j))) ;
args[UInt8(i)] = invocation.namedArguments.values.elementAt(j);
}
}
return internal_invoke(ft.index, args);
}
} else if (invocation.isSetter) {
var pt = instance?.template.getPropertyTemplateByName(memberName);
@ -381,4 +373,9 @@ class DistributedResource extends IResource {
return reply;
}
@override
String toString() {
return "DR<${instance?.template.className ?? ''}>";
}
}

View File

@ -31,5 +31,4 @@ class DistributedServer extends IResource {
@override
TemplateDescriber get template =>
TemplateDescriber("Esiur.Net.IIP.DistributedServer");
}

View File

@ -21,6 +21,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import '../../Data/TransmissionType.dart';
import '../../Data/DC.dart';
import '../../Data/Guid.dart';
@ -29,7 +31,6 @@ import 'IIPPacketCommand.dart';
import 'IIPPacketEvent.dart';
import 'IIPPacketReport.dart';
import '../../Data/Codec.dart';
import '../../Data/DataType.dart';
class IIPPacket {
int report = 0;
@ -53,7 +54,7 @@ class IIPPacket {
int storeId = 0;
int resourceAge = 0;
DC content = DC(0);
//DC content = DC(0);
int errorCode = 0;
String errorMessage = "";
String className = "";
@ -68,6 +69,9 @@ class IIPPacket {
DateTime toDate = DateTime(2000);
int fromAge = 0;
int toAge = 0;
String resourceName = "";
TransmissionType? dataType;
int _dataLengthNeeded = 0;
int _originalOffset = 0;
@ -137,7 +141,7 @@ class IIPPacket {
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
content = data.clip(offset, cl);
resourceName = data.getString(offset, cl);
offset += cl;
} else if (event == IIPPacketEvent.PropertyUpdated ||
@ -146,25 +150,12 @@ class IIPPacket {
methodIndex = data[offset++];
var dt = data[offset++];
var size = DataType.size(dt);
var parsed = TransmissionType.parse(data, offset, ends);
if (size < 0) {
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
if (parsed.type == null) return -parsed.size;
var cl = data.getUint32(offset);
offset += 4;
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
content = data.clip(offset - 5, cl + 5);
offset += cl;
} else {
if (_notEnough(offset, ends, size)) return -_dataLengthNeeded;
content = data.clip(offset - 1, size + 1);
offset += size;
}
dataType = parsed.type;
offset += parsed.size;
}
// else if (event == IIPPacketEvent.EventOccurred)
// {
@ -192,7 +183,8 @@ class IIPPacket {
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
content = data.clip(offset, cl);
//@TODO: fix this
//content = data.clip(offset, cl);
offset += cl;
}
@ -228,7 +220,8 @@ class IIPPacket {
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
content = data.clip(offset, cl);
//@TODO: fix this
//content = data.clip(offset, cl);
} else if (action == IIPPacketAction.DeleteResource) {
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
@ -252,7 +245,7 @@ class IIPPacket {
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
content = data.clip(offset, cl);
resourceName = data.getString(offset, cl);
offset += cl;
} else if (action == IIPPacketAction.TemplateFromClassName) {
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
@ -301,22 +294,20 @@ class IIPPacket {
toDate = data.getDateTime(offset);
offset += 8;
} else if (action == IIPPacketAction.InvokeFunctionArrayArguments ||
action == IIPPacketAction.InvokeFunctionNamedArguments) {
if (_notEnough(offset, ends, 9)) return -_dataLengthNeeded;
} else if (action == IIPPacketAction.InvokeFunction) {
if (_notEnough(offset, ends, 6)) return -_dataLengthNeeded;
resourceId = data.getUint32(offset);
offset += 4;
methodIndex = data[offset++];
var cl = data.getUint32(offset);
offset += 4;
var parsed = TransmissionType.parse(data, offset, ends);
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
if (parsed.type == null) return -parsed.size;
content = data.clip(offset, cl);
offset += cl;
dataType = parsed.type;
offset += parsed.size;
} else if (action == IIPPacketAction.Listen ||
action == IIPPacketAction.Unlisten) {
if (_notEnough(offset, ends, 5)) return -_dataLengthNeeded;
@ -358,26 +349,12 @@ class IIPPacket {
offset += 4;
methodIndex = data[offset++];
var parsed = TransmissionType.parse(data, offset, ends);
var dt = data[offset++];
var size = DataType.size(dt);
if (parsed.type == null) return -parsed.size;
if (size < 0) {
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
var cl = data.getUint32(offset);
offset += 4;
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
content = data.clip(offset - 5, cl + 5);
offset += cl;
} else {
if (_notEnough(offset, ends, size)) return -_dataLengthNeeded;
content = data.clip(offset - 1, size + 1);
offset += size;
}
dataType = parsed.type;
offset += parsed.size;
}
// Attributes
else if (action == IIPPacketAction.UpdateAllAttributes ||
@ -393,7 +370,8 @@ class IIPPacket {
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
content = data.clip(offset, cl);
//@TODO: fix this
//content = data.clip(offset, cl);
offset += cl;
}
} else if (command == IIPPacketCommand.Reply) {
@ -415,15 +393,12 @@ class IIPPacket {
resourceLink = data.getString(offset, cl);
offset += cl;
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
var parsed = TransmissionType.parse(data, offset, ends);
cl = data.getUint32(offset);
offset += 4;
if (parsed.type == null) return -parsed.size;
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
content = data.clip(offset, cl);
offset += cl;
dataType = parsed.type;
offset += parsed.size;
} else if (action == IIPPacketAction.DetachResource) {
// nothing to do
} else if (action == IIPPacketAction.CreateResource) {
@ -450,41 +425,26 @@ class IIPPacket {
||
action == IIPPacketAction.GetAllAttributes ||
action == IIPPacketAction.GetAttributes) {
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
var cl = data.getUint32(offset);
offset += 4;
var parsed = TransmissionType.parse(data, offset, ends);
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
if (parsed.type == null) return -parsed.size;
content = data.clip(offset, cl);
offset += cl;
} else if (action == IIPPacketAction.InvokeFunctionArrayArguments ||
action == IIPPacketAction.InvokeFunctionNamedArguments)
dataType = parsed.type;
offset += parsed.size;
} else if (action == IIPPacketAction.InvokeFunction)
//|| action == IIPPacketAction.GetProperty
//|| action == IIPPacketAction.GetPropertyIfModified)
{
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
var dt = data[offset++];
var size = DataType.size(dt);
var parsed = TransmissionType.parse(data, offset, ends);
if (size < 0) {
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
if (parsed.type == null) return -parsed.size;
var cl = data.getUint32(offset);
offset += 4;
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
content = data.clip(offset - 5, cl + 5);
offset += cl;
} else {
if (_notEnough(offset, ends, size)) return -_dataLengthNeeded;
content = data.clip(offset - 1, size + 1);
offset += size;
}
dataType = parsed.type;
offset += parsed.size;
} else if (action == IIPPacketAction.SetProperty ||
action == IIPPacketAction.Listen ||
action == IIPPacketAction.Unlisten) {
@ -521,25 +481,12 @@ class IIPPacket {
} else if (report == IIPPacketReport.ChunkStream) {
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
var dt = data[offset++];
var size = DataType.size(dt);
var parsed = TransmissionType.parse(data, offset, ends);
if (size < 0) {
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
if (parsed.type == null) return -parsed.size;
var cl = data.getUint32(offset);
offset += 4;
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
content = data.clip(offset - 5, cl + 5);
offset += cl;
} else {
if (_notEnough(offset, ends, size)) return -_dataLengthNeeded;
content = data.clip(offset - 1, size + 1);
offset += size;
}
dataType = parsed.type;
offset += parsed.size;
}
}

View File

@ -20,8 +20,8 @@ class IIPPacketAction {
static const int LinkTemplates = 0xF;
// Request Invoke
static const int InvokeFunctionArrayArguments = 0x10;
static const int InvokeFunctionNamedArguments = 0x11;
static const int InvokeFunction = 0x10;
static const int Reserved = 0x11;
static const int Listen = 0x12;
static const int Unlisten = 0x13;
static const int SetProperty = 0x14;

View File

@ -71,7 +71,7 @@ class WSocket extends ISocket {
if (_state == SocketState.Closed || _state == SocketState.Terminated)
return;
var dc = new DC.fromList(data);
var dc = new DC.fromList(data as List<int>);
receiveNetworkBuffer.write(dc, 0, dc.length);
receiver?.networkReceive(this, receiveNetworkBuffer);
} catch (ex) {

View File

@ -1,12 +1,11 @@
import 'dart:io';
import '../Data/DataType.dart';
import '../Data/RepresentationType.dart';
import '../Net/IIP/DistributedConnection.dart';
import '../Resource/Template/TemplateType.dart';
import '../Resource/Warehouse.dart';
import '../Resource/Template/TemplateDataType.dart';
import '../Resource/Template/TypeTemplate.dart';
class TemplateGenerator {
@ -18,10 +17,22 @@ class TemplateGenerator {
var className = template.className.split('.').last;
var rt = StringBuffer();
String? parentName;
if (template.parentId != null) {
parentName = _translateClassName(templates
.singleWhere((x) =>
(x.classId == template.parentId) &&
(x.type == TemplateType.Record))
.className);
rt.writeln("class ${className} extends ${parentName} {");
} else {
rt.writeln("class ${className} extends IRecord {");
}
template.properties.forEach((p) {
var ptTypeName = getTypeName(template, p.valueType, templates, false);
if (p.inherited) return;
var ptTypeName = getTypeName(template, p.valueType, templates);
rt.writeln("${ptTypeName}? ${p.name};");
rt.writeln();
});
@ -50,15 +61,16 @@ class TemplateGenerator {
rt.writeln("}");
// add template
var descProps = template.properties.map((p) {
var isArray = p.valueType.type & 0x80 == 0x80;
var ptType = p.valueType.type & 0x7F;
var ptTypeName = getTypeName(template,
TemplateDataType(ptType, p.valueType.typeGuid), templates, false);
// return "Prop(\"${p.name}\", ${ptTypeName}, ${isArray})";
return "Prop('${p.name}', ${ptTypeName}, ${isArray}, ${_escape(p.readExpansion)}, ${_escape(p.writeExpansion)})";
var descProps = template.properties //.where((p) => !p.inherited)
.map((p) {
var ptTypeName = getTypeName(template, p.valueType, templates);
return "Prop('${p.name}', getTypeOf<${ptTypeName}>(), ${_escape(p.readExpansion)}, ${_escape(p.writeExpansion)})";
}).join(', ');
if (parentName != null)
rt.writeln("""@override
TemplateDescriber get template => TemplateDescriber('${template.className}', parent: ${parentName}, properties: [${descProps}]);""");
else
rt.writeln("""@override
TemplateDescriber get template => TemplateDescriber('${template.className}', properties: [${descProps}]);""");
@ -67,144 +79,140 @@ class TemplateGenerator {
return rt.toString();
}
static String _translateClassName(String className, bool nullable) {
static String _translateClassName(String className) {
var cls = className.split('.');
var nameSpace = cls.take(cls.length - 1).join('_').toLowerCase();
return "$nameSpace.${cls.last}${nullable ? '?' : ''}";
return "$nameSpace.${cls.last}";
}
static String getTypeName(
TypeTemplate forTemplate,
TemplateDataType templateDataType,
List<TypeTemplate> templates,
bool nullable) {
if (templateDataType.type == DataType.Resource) {
if (templateDataType.typeGuid == forTemplate.classId)
return forTemplate.className.split('.').last + (nullable ? "?" : "");
else {
var tmp = templates.firstWhere((x) =>
x.classId == templateDataType.typeGuid &&
static String getTypeName(TypeTemplate forTemplate,
RepresentationType representationType, List<TypeTemplate> templates) {
String name;
if (representationType.identifier ==
RepresentationTypeIdentifier.TypedResource) {
if (representationType.guid == forTemplate.classId)
name = forTemplate.className.split('.').last;
else
name = _translateClassName(templates
.singleWhere((x) =>
x.classId == representationType.guid &&
(x.type == TemplateType.Resource ||
x.type == TemplateType.Wrapper));
if (tmp == null) return "dynamic"; // something went wrong
return _translateClassName(tmp.className, nullable);
}
} else if (templateDataType.type == DataType.ResourceArray) {
if (templateDataType.typeGuid == forTemplate.classId)
return "List<${forTemplate.className.split('.').last + (nullable ? '?' : '')}>";
x.type == TemplateType.Wrapper))
.className);
} else if (representationType.identifier ==
RepresentationTypeIdentifier.TypedRecord) {
if (representationType.guid == forTemplate.classId)
name = forTemplate.className.split('.').last;
else
name = _translateClassName(templates
.singleWhere((x) =>
x.classId == representationType.guid &&
x.type == TemplateType.Record)
.className);
} else if (representationType.identifier ==
RepresentationTypeIdentifier
.Enum) if (representationType.guid == forTemplate.classId)
name = forTemplate.className.split('.').last;
else
name = _translateClassName(templates
.singleWhere((x) =>
x.classId == representationType.guid &&
x.type == TemplateType.Enum)
.className);
else if (representationType.identifier ==
RepresentationTypeIdentifier.TypedList)
name = "List<" +
getTypeName(forTemplate, representationType.subTypes![0], templates) +
">";
else if (representationType.identifier ==
RepresentationTypeIdentifier.TypedMap)
name = "Map<" +
getTypeName(forTemplate, representationType.subTypes![0], templates) +
"," +
getTypeName(forTemplate, representationType.subTypes![1], templates) +
">";
else if (representationType.identifier ==
RepresentationTypeIdentifier.Tuple2 ||
representationType.identifier == RepresentationTypeIdentifier.Tuple3 ||
representationType.identifier == RepresentationTypeIdentifier.Tuple4 ||
representationType.identifier == RepresentationTypeIdentifier.Tuple5 ||
representationType.identifier == RepresentationTypeIdentifier.Tuple6 ||
representationType.identifier == RepresentationTypeIdentifier.Tuple7)
name = "Tuple";
//name = "(" + String.Join(",", representationType.SubTypes.Select(x=> GetTypeName(x, templates)))
// + ")";
else {
var tmp = templates.firstWhere((x) =>
x.classId == templateDataType.typeGuid &&
(x.type == TemplateType.Resource ||
x.type == TemplateType.Wrapper));
if (tmp == null) return "dynamic"; // something went wrong
return "List<${_translateClassName(tmp.className, nullable)}>";
}
} else if (templateDataType.type == DataType.Record) {
if (templateDataType.typeGuid == forTemplate.classId)
return forTemplate.className.split('.').last + (nullable ? '?' : '');
else {
var tmp = templates.firstWhere((x) =>
x.classId == templateDataType.typeGuid &&
x.type == TemplateType.Record);
if (tmp == null) return "dynamic"; // something went wrong
return _translateClassName(tmp.className, nullable);
}
} else if (templateDataType.type == DataType.RecordArray) {
if (templateDataType.typeGuid == forTemplate.classId)
return "List<${forTemplate.className.split('.').last + (nullable ? '?' : '')}?>";
else {
var tmp = templates.firstWhere((x) =>
x.classId == templateDataType.typeGuid &&
x.type == TemplateType.Record);
if (tmp == null) return "dynamic"; // something went wrong
return "List<${_translateClassName(tmp.className, nullable)}>";
}
}
var name = ((x) {
switch (x) {
case DataType.Bool:
return "bool";
case DataType.BoolArray:
return "List<bool>";
case DataType.Char:
return "String" + (nullable ? "?" : "");
case DataType.CharArray:
return "List<String${nullable ? '?' : ''}>";
case DataType.DateTime:
return "DateTime";
case DataType.DateTimeArray:
return "List<DateTime${nullable ? '?' : ''}>";
case DataType.Decimal:
return "double";
case DataType.DecimalArray:
return "List<double>";
case DataType.Float32:
return "double";
case DataType.Float32Array:
return "List<double>";
case DataType.Float64:
return "double";
case DataType.Float64Array:
return "List<double>";
case DataType.Int16:
return "int";
case DataType.Int16Array:
return "List<int>";
case DataType.Int32:
return "int";
case DataType.Int32Array:
return "List<int>";
case DataType.Int64:
return "int";
case DataType.Int64Array:
return "List<int>";
case DataType.Int8:
return "int";
case DataType.Int8Array:
return "List<int>";
case DataType.String:
return "String";
case DataType.StringArray:
return "List<String${nullable ? '?' : ''}>";
case DataType.Structure:
return "Structure" + (nullable ? "?" : "");
case DataType.StructureArray:
return "List<Structure${(nullable ? '?' : '')}>";
case DataType.UInt16:
return "int";
case DataType.UInt16Array:
return "List<int>";
case DataType.UInt32:
return "int";
case DataType.UInt32Array:
return "List<int>";
case DataType.UInt64:
return "int";
case DataType.UInt64Array:
return "List<int>";
case DataType.UInt8:
return "int";
case DataType.UInt8Array:
return "List<int>";
case DataType.VarArray:
return "List<dynamic>";
case DataType.Void:
return "dynamic";
switch (representationType.identifier) {
case RepresentationTypeIdentifier.Dynamic:
name = "dynamic";
break;
case RepresentationTypeIdentifier.Bool:
name = "bool";
break;
case RepresentationTypeIdentifier.Char:
name = "String";
break;
case RepresentationTypeIdentifier.DateTime:
name = "DateTime";
break;
case RepresentationTypeIdentifier.Decimal:
name = "double";
break;
case RepresentationTypeIdentifier.Float32:
name = "double";
break;
case RepresentationTypeIdentifier.Float64:
name = "double";
break;
case RepresentationTypeIdentifier.Int16:
name = "int";
break;
case RepresentationTypeIdentifier.Int32:
name = "int";
break;
case RepresentationTypeIdentifier.Int64:
name = "int";
break;
case RepresentationTypeIdentifier.Int8:
name = "int";
break;
case RepresentationTypeIdentifier.String:
name = "String";
break;
case RepresentationTypeIdentifier.Map:
name = "Map";
break;
case RepresentationTypeIdentifier.UInt16:
name = "int";
break;
case RepresentationTypeIdentifier.UInt32:
name = "int";
break;
case RepresentationTypeIdentifier.UInt64:
name = "int";
break;
case RepresentationTypeIdentifier.UInt8:
name = "int";
break;
case RepresentationTypeIdentifier.List:
name = "List";
break;
case RepresentationTypeIdentifier.Resource:
name = "IResource";
break;
case RepresentationTypeIdentifier.Record:
name = "IRecord";
break;
default:
return "dynamic";
name = "dynamic";
}
})(templateDataType.type);
return name;
}
static isNullOrEmpty(v) {
return (representationType.nullable) ? name + "?" : name;
}
static bool isNullOrEmpty(v) {
return v == null || v == "";
}
@ -222,8 +230,8 @@ class TemplateGenerator {
var path = _urlRegex.allMatches(url).first;
var con = await Warehouse.get<DistributedConnection>(
(path[1] as String) + "://" + (path[2] as String),
!isNullOrEmpty(username) && !isNullOrEmpty(password)
? {"username": username, "password": password}
username != null
? {"username": username, "password": password ?? ""}
: null);
if (con == null) throw Exception("Can't connect to server");
@ -273,20 +281,33 @@ class TemplateGenerator {
generateClass(tmp, templates, getx: getx, namedArgs: namedArgs);
} else if (tmp.type == TemplateType.Record) {
source = makeImports(tmp) + generateRecord(tmp, templates);
} else if (tmp.type == TemplateType.Enum) {
source = makeImports(tmp) + generateEnum(tmp, templates);
}
f.writeAsStringSync(source);
});
// generate info class
// Warehouse.defineType<test.MyService>(
// () => test.MyService(),
// RepresentationType(RepresentationTypeIdentifier.TypedResource, false,
// Guid(DC.fromList([1, 2, 3]))));
var defineCreators = templates.map((tmp) {
// creator
var className = _translateClassName(tmp.className, false);
return "Warehouse.defineCreator(${className}, () => ${className}(), () => <${className}?>[]);";
var className = _translateClassName(tmp.className);
if (tmp.type == TemplateType.Resource ||
tmp.type == TemplateType.Wrapper) {
return "Warehouse.defineType<${className}>(() => ${className}(), RepresentationType(RepresentationTypeIdentifier.TypedResource, false, Guid.fromString('${tmp.classId.toString()}')));\r\n";
} else if (tmp.type == TemplateType.Record) {
return "Warehouse.defineType<${className}>(() => ${className}(), RepresentationType(RepresentationTypeIdentifier.TypedRecord, false, Guid.fromString('${tmp.classId.toString()}')));\r\n";
} else if (tmp.type == TemplateType.Enum) {
return "Warehouse.defineType<${className}>(() => ${className}(), RepresentationType(RepresentationTypeIdentifier.Enum, false, Guid.fromString('${tmp.classId.toString()}')));\r\n";
}
}).join("\r\n");
var putTemplates = templates.map((tmp) {
var className = _translateClassName(tmp.className, false);
var className = _translateClassName(tmp.className);
return "Warehouse.putTemplate(TypeTemplate.fromType(${className}));";
}).join("\r\n");
@ -311,6 +332,38 @@ class TemplateGenerator {
return "r'$str'";
}
static String generateEnum(
TypeTemplate template, List<TypeTemplate> templates) {
var className = template.className.split('.').last;
var rt = StringBuffer();
rt.writeln("class ${className} extends IEnum {");
template.constants.forEach((c) {
rt.writeln(
"static ${className} ${c.name} = ${className}(${c.index}, ${c.value}, '${c.name}');");
rt.writeln();
});
rt.writeln();
rt.writeln(
"${className}([int index = 0, value, String name = '']) : super(index, value, name);");
// add template
var descConsts = template.constants.map((p) {
var ctTypeName = getTypeName(template, p.valueType, templates);
return "Const('${p.name}', getTypeOf<${ctTypeName}>(), ${p.value}, ${_escape(p.expansion)})";
}).join(', ');
rt.writeln("""@override
TemplateDescriber get template => TemplateDescriber('${template.className}', constants: [${descConsts}]);""");
rt.writeln("\r\n}");
return rt.toString();
}
static String generateClass(
TypeTemplate template,
List<TypeTemplate> templates, {
@ -319,14 +372,25 @@ class TemplateGenerator {
}) {
var className = template.className.split('.').last;
String? parentName;
var rt = StringBuffer();
rt.writeln("class $className extends DistributedResource {");
rt.writeln(
// "$className(DistributedConnection connection, int instanceId, int age, String link) : super(connection, instanceId, age, link) {");
"$className() {");
if (template.parentId != null) {
parentName = _translateClassName(templates
.singleWhere((x) =>
(x.classId == template.parentId) &&
(x.type == TemplateType.Resource ||
x.type == TemplateType.Wrapper))
.className);
rt.writeln("class ${className} extends ${parentName} {");
} else {
rt.writeln("class ${className} extends DistributedResource {");
}
template.events.forEach((e) {
rt.writeln("$className() {");
template.events.where((e) => !e.inherited).forEach((e) {
rt.writeln("on('${e.name}', (x) => _${e.name}Controller.add(x));");
});
@ -349,42 +413,50 @@ class TemplateGenerator {
}""");
}
template.functions.forEach((f) {
var rtTypeName = getTypeName(template, f.returnType, templates, true);
template.functions.where((f) => !f.inherited).forEach((f) {
var rtTypeName = getTypeName(template, f.returnType, templates);
var positionalArgs = f.arguments.where((x) => !x.optional);
var optionalArgs = f.arguments.where((x) => x.optional);
rt.write("AsyncReply<$rtTypeName> ${f.name}(");
if (f.arguments.isNotEmpty && namedArgs) {
rt.write("{");
}
rt.write(f.arguments.map((x) {
final typeName = getTypeName(template, x.type, templates, true);
return typeName +
(namedArgs && !typeName.endsWith("?") ? "?" : "") +
" " +
x.name;
}).join(","));
if (f.arguments.isNotEmpty && namedArgs) {
rt.write("}");
if (positionalArgs.length > 0)
rt.write(
"${positionalArgs.map((a) => getTypeName(template, a.type, templates) + " " + a.name).join(',')}");
if (optionalArgs.length > 0) {
if (positionalArgs.length > 0) rt.write(",");
rt.write(
"[${optionalArgs.map((a) => getTypeName(template, a.type.toNullable(), templates) + " " + a.name).join(',')}]");
}
rt.writeln(") {");
rt.writeln("var rt = AsyncReply<$rtTypeName>();");
rt.writeln(
"internal_invokeByArrayArguments(${f.index}, [${f.arguments.map((x) => x.name).join(',')}])");
"var args = <UInt8, dynamic>{${positionalArgs.map((e) => "UInt8(" + e.index.toString() + ') :' + e.name).join(',')}};");
optionalArgs.forEach((a) {
rt.writeln(
"if (${a.name} != null) args[UInt8(${a.index})] = ${a.name};");
});
rt.writeln("var rt = AsyncReply<$rtTypeName>();");
rt.writeln("internal_invoke(${f.index}, args)");
rt.writeln(".then<dynamic>((x) => rt.trigger(x))");
rt.writeln(".error((x) => rt.triggerError(x))");
rt.writeln(".chunk((x) => rt.triggerChunk(x));");
rt.writeln("return rt; }");
});
template.properties.forEach((p) {
var ptTypeName = getTypeName(template, p.valueType, templates, true);
template.properties.where((p) => !p.inherited).forEach((p) {
var ptTypeName = getTypeName(template, p.valueType, templates);
rt.writeln("${ptTypeName} get ${p.name} { return get(${p.index}); }");
rt.writeln(
"set ${p.name}(${ptTypeName} value) { set(${p.index}, value); }");
});
template.events.forEach((e) {
var etTypeName = getTypeName(template, e.argumentType, templates, true);
template.events.where((e) => !e.inherited).forEach((e) {
var etTypeName = getTypeName(template, e.argumentType, templates);
rt.writeln(
"final _${e.name}Controller = StreamController<$etTypeName>();");
@ -394,39 +466,35 @@ class TemplateGenerator {
});
// add template
var descProps = template.properties.map((p) {
var isArray = p.valueType.type & 0x80 == 0x80;
var ptType = p.valueType.type & 0x7F;
var ptTypeName = getTypeName(template,
TemplateDataType(ptType, p.valueType.typeGuid), templates, false);
return "Prop('${p.name}', ${ptTypeName}, ${isArray}, ${_escape(p.readExpansion)}, ${_escape(p.writeExpansion)})";
var descProps = template.properties //.where((p) => !p.inherited)
.map((p) {
var ptTypeName = getTypeName(template, p.valueType, templates);
return "Prop('${p.name}', getTypeOf<${ptTypeName}>(), ${_escape(p.readExpansion)}, ${_escape(p.writeExpansion)})";
}).join(', ');
var descFuncs = template.functions.map((f) {
var isArray = f.returnType.type & 0x80 == 0x80;
var ftType = f.returnType.type & 0x7F;
var ftTypeName = getTypeName(template,
TemplateDataType(ftType, f.returnType.typeGuid), templates, false);
var descFuncs = template.functions //.where((f) => !f.inherited)
.map((f) {
var ftTypeName = getTypeName(template, f.returnType, templates);
var args = f.arguments.map((a) {
var isArray = a.type.type & 0x80 == 0x80;
var atType = a.type.type & 0x7F;
var atTypeName = getTypeName(template,
TemplateDataType(atType, a.type.typeGuid), templates, false);
return "Arg('${a.name}', ${atTypeName}, ${isArray})";
var atTypeName = getTypeName(template, a.type, templates);
return "Arg('${a.name}', getTypeOf<${atTypeName}>(), ${a.optional})";
}).join(', ');
return "Func('${f.name}', ${ftTypeName}, ${isArray}, [${args}], ${_escape(f.expansion)})";
return "Func('${f.name}', getTypeOf<${ftTypeName}>(), [${args}], ${_escape(f.expansion)})";
}).join(', ');
var descEvents = template.events.map((e) {
var isArray = e.argumentType.type & 0x80 == 0x80;
var etType = e.argumentType.type & 0x7F;
var etTypeName = getTypeName(template,
TemplateDataType(etType, e.argumentType.typeGuid), templates, false);
return "Evt('${e.name}', ${etTypeName}, ${isArray}, ${e.listenable}, ${_escape(e.expansion)})";
var descEvents = template.events
//.where((e) => !e.inherited)
.map((e) {
var etTypeName = getTypeName(template, e.argumentType, templates);
return "Evt('${e.name}', getTypeOf<${etTypeName}>(), ${e.listenable}, ${_escape(e.expansion)})";
}).join(', ');
if (parentName != null)
rt.writeln(
"TemplateDescriber get template => TemplateDescriber('${template.className}', parent: ${parentName}, properties: [${descProps}], functions: [${descFuncs}], events: [$descEvents]);");
else
rt.writeln(
"TemplateDescriber get template => TemplateDescriber('${template.className}', properties: [${descProps}], functions: [${descFuncs}], events: [$descEvents]);");

View File

@ -0,0 +1,18 @@
import '../Security/Authority/Session.dart';
import 'IResource.dart';
import 'Template/EventTemplate.dart';
class EventOccurredInfo {
final EventTemplate eventTemplate;
String get name => eventTemplate.name;
final IResource resource;
final dynamic value;
final issuer;
final bool Function(Session)? receivers;
EventOccurredInfo(this.resource, this.eventTemplate, this.value, this.issuer,
this.receivers) {}
}

View File

@ -1,7 +1,33 @@
class FactoryEntry {
final Type type;
final Function instanceCreator;
final Function arrayCreator;
import '../Data/RepresentationType.dart';
FactoryEntry(this.type, this.instanceCreator, this.arrayCreator);
// class DumClass<T> {
// Type type = T;
// }
// Type getNullableType<T>() => DumClass<T?>().type;
// Type getTypeOf<T>() => DumClass<T>().type;
class FactoryEntry<T> {
Type get type => T;
late Type nullableType;
final Function instanceCreator;
final Function arrayCreator = () => <T>[];
final RepresentationType representationType;
bool isMapKeySubType(Map map) {
return map is Map<T, dynamic>;
}
bool isMapValueSubType(Map map) {
return map is Map<dynamic, T>;
}
bool isListSubType(List list) {
return list is List<T>;
}
FactoryEntry(this.instanceCreator, this.representationType) {
nullableType = getNullableType<T>();
}
}

View File

@ -36,10 +36,10 @@ abstract class IStore implements IResource {
AsyncReply<IResource?> retrieve(int iid);
AsyncReply<bool> put(IResource resource);
String? link(IResource resource);
bool record(IResource resource, String propertyName, dynamic value, int age,
DateTime dateTime);
bool modify(IResource resource, String propertyName, dynamic value, int age,
DateTime dateTime);
bool record(IResource resource, String propertyName, dynamic value, int? age,
DateTime? dateTime);
bool modify(IResource resource, String propertyName, dynamic value, int? age,
DateTime? dateTime);
bool remove(IResource resource);
AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>?> getRecord(

View File

@ -1,7 +1,6 @@
import 'dart:core';
import '../Data/DC.dart';
import '../Data/Structure.dart';
import '../Data/AutoList.dart';
import './IStore.dart';
import './IResource.dart';
@ -12,6 +11,7 @@ import '../Core/IEventHandler.dart';
import '../Security/Permissions/Ruling.dart';
import '../Security/Permissions/IPermissionsManager.dart';
import '../Security/Permissions/ActionType.dart';
import 'EventOccurredInfo.dart';
import 'Template/TypeTemplate.dart';
import './Template/PropertyTemplate.dart';
import './Template/FunctionTemplate.dart';
@ -24,7 +24,6 @@ import 'Warehouse.dart';
import '../Core/PropertyModificationInfo.dart';
class Instance extends IEventHandler {
String _name;
@ -64,8 +63,8 @@ class Instance extends IEventHandler {
return true;
}
Structure getAttributes([List<String>? attributes = null]) {
var st = new Structure();
Map<String, dynamic> getAttributes([List<String>? attributes = null]) {
var st = Map<String, dynamic>();
if (attributes == null) {
var clone = this.attributes.keys.toList();
@ -77,10 +76,10 @@ class Instance extends IEventHandler {
if (attr == "name")
st["name"] = _name;
else if (attr == "managers") {
var mngrs = <Structure>[];
var mngrs = <Map<String, dynamic>>[];
for (var i = 0; i < _managers.length; i++) {
var mst = new Structure();
var mst = Map<String, dynamic>();
mst["type"] = _managers[i].runtimeType;
mst["settings"] = _managers[i].settings;
@ -103,7 +102,8 @@ class Instance extends IEventHandler {
return st;
}
bool setAttributes(Structure attributes, [bool clearAttributes = false]) {
bool setAttributes(Map<String, dynamic> attributes,
[bool clearAttributes = false]) {
try {
if (clearAttributes) _attributes.clear();
@ -256,7 +256,7 @@ class Instance extends IEventHandler {
/// </summary>
int get age => _instanceAge;
// this must be internal
set age(value) => _instanceAge = value;
set age(int value) => _instanceAge = value;
/// <summary>
/// Last modification date.
@ -381,18 +381,19 @@ class Instance extends IEventHandler {
_ages[pt.index] = _instanceAge;
_modificationDates[pt.index] = now;
if (pt.storage == StorageMode.NonVolatile) {
_store?.modify(_resource, pt.name, value, _ages[pt.index], now);
} else if (pt.storage == StorageMode.Recordable) {
if (pt.recordable) {
_store?.record(_resource, pt.name, value, _ages[pt.index], now);
} else {
_store?.modify(_resource, pt.name, value, _ages[pt.index], now);
}
emitArgs("resourceModified", [_resource, pt.name, value]);
var pmInfo = PropertyModificationInfo(_resource, pt, value, _instanceAge);
emitArgs("PropertyModified", [pmInfo]);
//_resource.emitArgs("modified", [pt.name, value]);
_resource.emitArgs(":${pt.name}", [value]);
_resource.emitProperty(
PropertyModificationInfo(_resource, pt, value, _instanceAge));
_resource.emitProperty(pmInfo);
}
/// <summary>
@ -409,10 +410,11 @@ class Instance extends IEventHandler {
}
}
emitResourceEvent(
issuer, List<Session>? receivers, String name, dynamic args) {
emitArgs(
"resourceEventOccurred", [_resource, issuer, receivers, name, args]);
emitResourceEvent(issuer, bool Function(Session)? receivers,
EventTemplate eventTemplate, dynamic value) {
emitArgs("EventOccurred", [
EventOccurredInfo(_resource, eventTemplate, value, issuer, receivers)
]);
}
/// <summary>

View File

@ -0,0 +1,14 @@
import 'IResource.dart';
import 'Template/PropertyTemplate.dart';
class PropertyModificationInfo {
final IResource resource;
final PropertyTemplate propertyTemplate;
final int age;
final value;
String get name => propertyTemplate.name;
PropertyModificationInfo(
this.resource, this.propertyTemplate, this.value, this.age) {}
}

View File

@ -1,29 +1,34 @@
import '../../Data/RepresentationType.dart';
import '../../Data/DC.dart';
import '../../Data/BinaryList.dart';
import "../../Data/ParseResult.dart";
import './TemplateDataType.dart';
class ArgumentTemplate {
String name;
final String name;
final bool optional;
final RepresentationType type;
final int index;
TemplateDataType type;
static ParseResult<ArgumentTemplate> parse(DC data, int offset, int index) {
var optional = (data[offset++] & 0x1) == 0x1;
static ParseResult<ArgumentTemplate> parse(DC data, int offset) {
var cs = data[offset++];
var name = data.getString(offset, cs);
offset += cs;
var tdr = TemplateDataType.parse(data, offset);
var tdr = RepresentationType.parse(data, offset);
return ParseResult<ArgumentTemplate>(
cs + 1 + tdr.size, ArgumentTemplate(name, tdr.value));
cs + 2 + tdr.size, ArgumentTemplate(name, tdr.type, optional, index));
}
ArgumentTemplate(this.name, this.type);
ArgumentTemplate(this.name, this.type, this.optional, this.index);
DC compose() {
var name = DC.stringToBytes(this.name);
return (BinaryList()
..addUint8(optional ? 1 : 0)
..addUint8(name.length)
..addDC(name)
..addDC(type.compose()))

View File

@ -0,0 +1,46 @@
import '../../Data/BinaryList.dart';
import '../../Data/Codec.dart';
import '../../Data/DC.dart';
import '../../Data/RepresentationType.dart';
import 'MemberTemplate.dart';
import 'TypeTemplate.dart';
class ConstantTemplate extends MemberTemplate {
final dynamic value;
final String? expansion;
final RepresentationType valueType;
ConstantTemplate(TypeTemplate template, int index, String name,
bool inherited, this.valueType, this.value, this.expansion)
: super(template, index, name, inherited) {}
DC compose() {
var name = super.compose();
var hdr = inherited ? 0x80 : 0;
if (expansion != null) {
var exp = DC.stringToBytes(expansion!);
hdr |= 0x70;
return (BinaryList()
..addUint8(hdr)
..addUint8(name.length)
..addDC(name)
..addDC(valueType.compose())
..addDC(Codec.compose(value, null))
..addInt32(exp.length)
..addDC(exp))
.toDC();
} else {
hdr |= 0x60;
return (BinaryList()
..addUint8(hdr)
..addUint8(name.length)
..addDC(name)
..addDC(valueType.compose())
..addDC(Codec.compose(value, null)))
.toDC();
}
}
}

View File

@ -3,20 +3,25 @@ import '../../Data/DC.dart';
import '../../Data/BinaryList.dart';
import 'TypeTemplate.dart';
import 'MemberType.dart';
import 'TemplateDataType.dart';
import '../../Data/RepresentationType.dart';
class EventTemplate extends MemberTemplate {
String? expansion;
bool listenable;
TemplateDataType argumentType;
final String? expansion;
final bool listenable;
final RepresentationType argumentType;
DC compose() {
var name = super.compose();
var hdr = inherited ? 0x80 : 0;
if (listenable) hdr |= 0x8;
if (expansion != null) {
var exp = DC.stringToBytes(expansion as String);
hdr |= 0x50;
return (BinaryList()
..addUint8(listenable ? 0x58 : 0x50)
..addUint8(hdr)
..addUint8(name.length)
..addDC(name)
..addDC(argumentType.compose())
@ -24,8 +29,9 @@ class EventTemplate extends MemberTemplate {
..addDC(exp))
.toDC();
} else {
hdr |= 0x40;
return (BinaryList()
..addUint8(listenable ? 0x48 : 0x40)
..addUint8(hdr)
..addUint8(name.length)
..addDC(name)
..addDC(argumentType.compose()))
@ -33,7 +39,8 @@ class EventTemplate extends MemberTemplate {
}
}
EventTemplate(TypeTemplate template, int index, String name,
this.argumentType, this.expansion, this.listenable)
: super(template, MemberType.Property, index, name) {}
EventTemplate(TypeTemplate template, int index, String name, bool inherited,
this.argumentType,
[this.expansion = null, this.listenable = false])
: super(template, index, name, inherited) {}
}

View File

@ -4,17 +4,16 @@ import '../../Data/BinaryList.dart';
import 'TypeTemplate.dart';
import 'MemberType.dart';
import 'ArgumentTemplate.dart';
import 'TemplateDataType.dart';
import '../../Data/RepresentationType.dart';
class FunctionTemplate extends MemberTemplate {
String? expansion;
// bool isVoid;
TemplateDataType returnType;
List<ArgumentTemplate> arguments;
RepresentationType returnType;
DC compose() {
var name = super.compose();
var bl = new BinaryList()
@ -23,27 +22,22 @@ class FunctionTemplate extends MemberTemplate {
..addDC(returnType.compose())
..addUint8(arguments.length);
for (var i = 0; i < arguments.length; i++)
bl.addDC(arguments[i].compose());
for (var i = 0; i < arguments.length; i++) bl.addDC(arguments[i].compose());
if (expansion != null)
{
if (expansion != null) {
var exp = DC.stringToBytes(expansion as String);
bl..addInt32(exp.length)
bl
..addInt32(exp.length)
..addDC(exp);
bl.insertUint8(0, 0x10);
}
else
bl.insertUint8(0, 0x0);
bl.insertUint8(0, inherited ? 0x90 : 0x10);
} else
bl.insertUint8(0, inherited ? 0x80 : 0x0);
return bl.toDC();
}
FunctionTemplate(TypeTemplate template, int index, String name,
this.arguments, this.returnType, this.expansion)
: super(template, MemberType.Property, index, name) {
}
bool inherited, this.arguments, this.returnType,
[this.expansion = null])
: super(template, index, name, inherited) {}
}

View File

@ -1,30 +1,18 @@
import 'MemberType.dart';
import '../../Data/DC.dart';
import 'TypeTemplate.dart';
class MemberTemplate
{
class MemberTemplate {
final TypeTemplate template;
final String name;
final int index;
final bool inherited;
int get index => _index;
String get name => _name;
MemberType get type => _type;
MemberTemplate(this.template, this.index, this.name, this.inherited) {}
TypeTemplate _template;
String _name;
MemberType _type;
int _index;
String get fullname => template.className + "." + name;
TypeTemplate get template => _template;
MemberTemplate(this._template, this._type, this._index, this._name)
{
}
String get fullname => _template.className + "." + _name;
DC compose()
{
return DC.stringToBytes(_name);
DC compose() {
return DC.stringToBytes(name);
}
}

View File

@ -1,18 +1,17 @@
import 'TemplateDataType.dart';
import 'MemberTemplate.dart';
import '../../Data/DC.dart';
import '../../Data/BinaryList.dart';
import 'TypeTemplate.dart';
import 'MemberType.dart';
import '../StorageMode.dart';
import '../../Data/RepresentationType.dart';
class PropertyTemplate extends MemberTemplate {
TemplateDataType valueType;
RepresentationType valueType;
int permission = 0;
int storage;
bool recordable;
String? readExpansion;
@ -20,7 +19,9 @@ class PropertyTemplate extends MemberTemplate {
DC compose() {
var name = super.compose();
var pv = ((permission) << 1) | (storage == StorageMode.Recordable ? 1 : 0);
var pv = (permission << 1) | (recordable ? 1 : 0);
if (inherited) pv |= 0x80;
if (writeExpansion != null && readExpansion != null) {
var rexp = DC.stringToBytes(readExpansion as String);
@ -65,8 +66,9 @@ class PropertyTemplate extends MemberTemplate {
}
PropertyTemplate(TypeTemplate template, int index, String name,
this.valueType, this.readExpansion, this.writeExpansion, this.storage)
: super(template, MemberType.Property, index, name) {
//this.Recordable = recordable;
}
bool inherited, this.valueType,
[this.readExpansion = null,
this.writeExpansion = null,
this.recordable = false])
: super(template, index, name, inherited) {}
}

View File

@ -1,125 +1,124 @@
//import 'dart:ffi';
import '../../Data/IRecord.dart';
import '../../Resource/IResource.dart';
// import '../../Data/IRecord.dart';
// import '../../Resource/IResource.dart';
import '../../Data/Structure.dart';
// import '../../Data/Structure.dart';
import '../../Data/ParseResult.dart';
// import '../../Data/ParseResult.dart';
import '../../Data/DataType.dart';
import '../../Data/Guid.dart';
import '../../Data/DC.dart';
import '../../Data/BinaryList.dart';
import 'TypeTemplate.dart';
import '../../Resource/Warehouse.dart';
import 'TemplateType.dart';
// import '../../Data/DataType.dart';
// import '../../Data/Guid.dart';
// import '../../Data/DC.dart';
// import '../../Data/BinaryList.dart';
// import 'TypeTemplate.dart';
// import '../../Resource/Warehouse.dart';
// import 'TemplateType.dart';
class TemplateDataType {
late int type;
TypeTemplate? get typeTemplate => typeGuid == null
? null
: Warehouse.getTemplateByClassId(typeGuid as Guid);
// class TemplateDataType {
// late int type;
// TypeTemplate? get typeTemplate => typeGuid == null
// ? null
// : Warehouse.getTemplateByClassId(typeGuid as Guid);
Guid? typeGuid;
// Guid? typeGuid;
// @TODO: implement fromType
TemplateDataType.fromType(type, bool isArray) {
int dt;
// // @TODO: implement fromType
// TemplateDataType.fromType(type, bool isArray) {
// int dt;
if (type == null || type == dynamic) {
dt = DataType.Void;
}
// else if (type is int) {
// dt = type;
else if (type == bool)
dt = DataType.Bool;
// else if (type == Uint8)
// dt = DataType.UInt8;
// else if (type == Int8)
// dt = DataType.Int8;
// else if (type == Uint16)
// dt = DataType.UInt16;
// else if (type == Int16)
// dt = DataType.Int16;
// else if (type == Uint32)
// dt = DataType.UInt32;
// else if (type == Int32)
// dt = DataType.Int32;
// else if (type == Uint64)
// dt = DataType.UInt64;
else if (/* type == Int64 || */ type == int)
dt = DataType.Int64;
// else if (type == Float)
// dt = DataType.Float32;
else if (/* type == Double || */ type == double)
dt = DataType.Float64;
else if (type == String)
dt = DataType.String;
else if (type == DateTime)
dt = DataType.DateTime;
else if (type == Structure)
dt = DataType.Structure;
else if (type == IResource) // Dynamic resource (unspecified type)
dt = DataType.Void;
else if (type == IRecord) // Dynamic record (unspecified type)
dt = DataType.Void;
else {
var template = Warehouse.getTemplateByType(type);
// if (type == null || type == dynamic) {
// dt = DataType.Void;
// }
// // else if (type is int) {
// // dt = type;
// else if (type == bool)
// dt = DataType.Bool;
// // else if (type == Uint8)
// // dt = DataType.UInt8;
// // else if (type == Int8)
// // dt = DataType.Int8;
// // else if (type == Uint16)
// // dt = DataType.UInt16;
// // else if (type == Int16)
// // dt = DataType.Int16;
// // else if (type == Uint32)
// // dt = DataType.UInt32;
// // else if (type == Int32)
// // dt = DataType.Int32;
// // else if (type == Uint64)
// // dt = DataType.UInt64;
// else if (/* type == Int64 || */ type == int)
// dt = DataType.Int64;
// // else if (type == Float)
// // dt = DataType.Float32;
// else if (/* type == Double || */ type == double)
// dt = DataType.Float64;
// else if (type == String)
// dt = DataType.String;
// else if (type == DateTime)
// dt = DataType.DateTime;
// else if (type == Structure)
// dt = DataType.Structure;
// else if (type == IResource) // Dynamic resource (unspecified type)
// dt = DataType.Void;
// else if (type == IRecord) // Dynamic record (unspecified type)
// dt = DataType.Void;
// else {
// var template = Warehouse.getTemplateByType(type);
if (template != null) {
typeGuid = template.classId;
dt = template.type == TemplateType.Resource
? DataType.Resource
: DataType.Record;
} else
dt = DataType.Void;
// if (template != null) {
// typeGuid = template.classId;
// dt = template.type == TemplateType.Resource
// ? DataType.Resource
// : DataType.Record;
// } else
// dt = DataType.Void;
// if (template)
// try {
// var ins = Warehouse.createInstance(type);
// if (ins is IResource) {
// typeGuid = TypeTemplate.getTypeGuid(ins.template.nameSpace);
// } else if (ins is IRecord) {
// typeGuid = TypeTemplate.getTypeGuid(ins.template.nameSpace);
// } else {
// dt = DataType.Void;
// }
// } catch (ex) {
// dt = DataType.Void;
// }
}
// // if (template)
// // try {
// // var ins = Warehouse.createInstance(type);
// // if (ins is IResource) {
// // typeGuid = TypeTemplate.getTypeGuid(ins.template.nameSpace);
// // } else if (ins is IRecord) {
// // typeGuid = TypeTemplate.getTypeGuid(ins.template.nameSpace);
// // } else {
// // dt = DataType.Void;
// // }
// // } catch (ex) {
// // dt = DataType.Void;
// // }
// }
if (isArray) dt = dt | 0x80;
// if (isArray) dt = dt | 0x80;
this.type = dt;
}
// this.type = dt;
// }
DC compose() {
if (type == DataType.Resource ||
type == DataType.ResourceArray ||
type == DataType.Record ||
type == DataType.RecordArray) {
return (BinaryList()
..addUint8(type)
..addDC((typeGuid as Guid).value))
.toDC();
} else
return DC.fromList([type]);
}
// DC compose() {
// if (type == DataType.Resource ||
// type == DataType.ResourceArray ||
// type == DataType.Record ||
// type == DataType.RecordArray) {
// return (BinaryList()
// ..addUint8(type)
// ..addDC((typeGuid as Guid).value))
// .toDC();
// } else
// return DC.fromList([type]);
// }
TemplateDataType(this.type, this.typeGuid);
// TemplateDataType(this.type, this.typeGuid);
static ParseResult<TemplateDataType> parse(DC data, int offset) {
var type = data[offset++];
if (type == DataType.Resource ||
type == DataType.ResourceArray ||
type == DataType.Record ||
type == DataType.RecordArray) {
var guid = data.getGuid(offset);
return ParseResult<TemplateDataType>(
17, new TemplateDataType(type, guid));
} else
return ParseResult<TemplateDataType>(1, new TemplateDataType(type, null));
}
}
// static ParseResult<TemplateDataType> parse(DC data, int offset) {
// var type = data[offset++];
// if (type == DataType.Resource ||
// type == DataType.ResourceArray ||
// type == DataType.Record ||
// type == DataType.RecordArray) {
// var guid = data.getGuid(offset);
// return ParseResult<TemplateDataType>(
// 17, new TemplateDataType(type, guid));
// } else
// return ParseResult<TemplateDataType>(1, new TemplateDataType(type, null));
// }
// }

View File

@ -1,14 +1,21 @@
import '../../Data/DataType.dart';
class TemplateDescriber {
final List<Prop>? properties;
final List<Evt>? events;
final List<Func>? functions;
final List<Const>? constants;
final String nameSpace;
final int version;
final Type? parent;
TemplateDescriber(this.nameSpace,
{this.properties, this.functions, this.events, this.version = 0});
const TemplateDescriber(this.nameSpace,
{this.parent,
this.properties,
this.functions,
this.events,
this.constants,
this.version = 0});
}
// class Property<T> {
@ -46,10 +53,10 @@ class TemplateDescriber {
class Prop {
final String name;
final Type type;
final bool isArray;
//final bool isNullable;
final String? readAnnotation;
final String? writeAnnotation;
Prop(this.name, this.type, this.isArray,
const Prop(this.name, this.type,
[this.readAnnotation = null, this.writeAnnotation = null]);
}
@ -57,28 +64,36 @@ class Evt {
final String name;
final bool listenable;
final Type type;
final bool isArray;
//final bool isNullable;
final String? annotation;
const Evt(this.name, this.type, [this.listenable = false, this.annotation]);
}
Evt(this.name, this.type, this.isArray,
[this.listenable = false, this.annotation]);
class Const {
final String name;
final Type type;
//final bool isNullable;
final String? annotation;
final value;
const Const(this.name, this.type, this.value, [this.annotation]);
}
class Func {
final String name;
final Type returnType;
final List<Arg> argsType;
final bool isArray;
//final bool isNullable;
final String? annotation;
Func(this.name, this.returnType, this.isArray, this.argsType,
const Func(this.name, this.returnType, this.argsType,
[this.annotation = null]);
}
class Arg {
final String name;
final Type type;
final bool isArray;
Arg(this.name, this.type, this.isArray);
//final bool isNullable;
final bool optional;
const Arg(this.name, this.type, this.optional);
}

View File

@ -3,4 +3,5 @@ enum TemplateType {
Resource,
Record,
Wrapper,
Enum
}

View File

@ -1,4 +1,6 @@
//import 'dart:ffi';
import '../../Data/Codec.dart';
import '../../Data/IEnum.dart';
import '../../Data/RepresentationType.dart';
import '../../Net/IIP/DistributedResource.dart';
@ -16,18 +18,21 @@ import '../../Data/DC.dart';
import './EventTemplate.dart';
import './PropertyTemplate.dart';
import './FunctionTemplate.dart';
import '../StorageMode.dart';
import 'ArgumentTemplate.dart';
import 'TemplateDataType.dart';
import 'ConstantTemplate.dart';
import 'TemplateType.dart';
class TypeTemplate {
late Guid _classId;
Guid? _parentId = null;
late String _className;
List<MemberTemplate> _members = [];
List<FunctionTemplate> _functions = [];
List<EventTemplate> _events = [];
List<PropertyTemplate> _properties = [];
List<ConstantTemplate> _constants = [];
late int _version;
//bool isReady;
@ -39,22 +44,14 @@ class TypeTemplate {
TemplateType get type => _templateType;
Guid? get parentId => _parentId;
Type? _definedType;
Type? get definedType => _definedType;
/*
MemberTemplate getMemberTemplate(MemberInfo member)
{
if (member is MethodInfo)
return getFunctionTemplate(member.Name);
else if (member is EventInfo)
return getEventTemplate(member.Name);
else if (member is PropertyInfo)
return getPropertyTemplate(member.Name);
else
return null;
}
*/
Type? get parentDefinedType => _parentDefinedType;
Type? _parentDefinedType;
//@TODO: implement
static List<TypeTemplate> getDependencies(TypeTemplate template) => [];
@ -89,6 +86,16 @@ class TypeTemplate {
return null;
}
ConstantTemplate? getConstantByIndex(int index) {
for (var i in _constants) if (i.index == index) return i;
return null;
}
ConstantTemplate? getConstantByName(String constantName) {
for (var i in _constants) if (i.name == constantName) return i;
return null;
}
static Guid getTypeGuid(String typeName) {
var tn = DC.stringToBytes(typeName);
var hash = SHA256.compute(tn).clip(0, 16);
@ -107,20 +114,30 @@ class TypeTemplate {
List<PropertyTemplate> get properties => _properties;
List<ConstantTemplate> get constants => _constants;
TypeTemplate.fromType(Type type, [bool addToWarehouse = false]) {
// debugging print("FromType ${type.toString()}");
var instance = Warehouse.createInstance(type);
if (instance is DistributedResource)
TemplateDescriber describer;
if (instance is DistributedResource) {
_templateType = TemplateType.Wrapper;
else if (instance is IResource)
describer = instance.template;
} else if (instance is IResource) {
_templateType = TemplateType.Resource;
else if (instance is IRecord)
describer = instance.template;
} else if (instance is IRecord) {
_templateType = TemplateType.Record;
else
describer = instance.template;
} else if (instance is IEnum) {
_templateType = TemplateType.Enum;
describer = instance.template;
} else
throw new Exception(
"Type must implement IResource, IRecord or inherit from DistributedResource.");
"Type must implement IResource, IRecord, IEnum or a subtype of DistributedResource.");
// if (instance is IRecord)
// _templateType = TemplateType.Record;
@ -129,8 +146,6 @@ class TypeTemplate {
// else
// throw new Exception("Type is neither a resource nor a record.");
TemplateDescriber describer = instance.template;
_definedType = type;
_className = describer.nameSpace;
@ -143,6 +158,23 @@ class TypeTemplate {
if (addToWarehouse) Warehouse.putTemplate(this);
// _templates.add(template.classId, template);
if (describer.constants != null) {
var consts = describer.constants as List<Const>;
for (var i = 0; i < consts.length; i++) {
var ci = consts[i];
var ct = ConstantTemplate(
this,
i,
ci.name,
false,
RepresentationType.fromType(ci.type) ?? RepresentationType.Void,
ci.value,
ci.annotation);
constants.add(ct);
}
}
if (describer.properties != null) {
var props = describer.properties as List<Prop>;
@ -152,10 +184,11 @@ class TypeTemplate {
this,
i,
pi.name,
TemplateDataType.fromType(pi.type, pi.isArray),
false,
RepresentationType.fromType(pi.type) ?? RepresentationType.Dynamic,
pi.readAnnotation,
pi.writeAnnotation,
0);
false);
properties.add(pt);
}
}
@ -167,16 +200,24 @@ class TypeTemplate {
var fi = funcs[i];
List<ArgumentTemplate> args = fi.argsType
.asMap()
.entries
.map((arg) => ArgumentTemplate(
arg.name, TemplateDataType.fromType(arg.type, arg.isArray)))
arg.value.name,
RepresentationType.fromType(arg.value.type) ??
RepresentationType.Dynamic,
arg.value.optional,
arg.key))
.toList();
var ft = FunctionTemplate(
this,
i,
fi.name,
false,
args,
TemplateDataType.fromType(fi.returnType, fi.isArray),
RepresentationType.fromType(fi.returnType) ??
RepresentationType.Void,
fi.annotation);
functions.add(ft);
@ -192,7 +233,8 @@ class TypeTemplate {
this,
i,
ei.name,
TemplateDataType.fromType(ei.type, ei.isArray),
false,
RepresentationType.fromType(ei.type) ?? RepresentationType.Dynamic,
ei.annotation,
ei.listenable);
@ -204,8 +246,10 @@ class TypeTemplate {
events.forEach(_members.add);
// append slots
functions.forEach(_members.add);
// append properties
// append properties
properties.forEach(_members.add);
// append constants
constants.forEach(_members.add);
// bake it binarily
var b = BinaryList()
@ -440,22 +484,29 @@ class TypeTemplate {
// cool Dart feature
contentLength ??= data.length;
int ends = offset + contentLength;
//int ends = offset + contentLength;
int oOffset = offset;
//int oOffset = offset;
// start parsing...
//var od = new TypeTemplate();
_content = data.clip(offset, contentLength);
_templateType = TemplateType.values[data.getUint8(offset++)];
var hasParent = (data.getUint8(offset) & 0x80) > 0;
_templateType = TemplateType.values[data.getUint8(offset++) & 0xF];
_classId = data.getGuid(offset);
offset += 16;
_className = data.getString(offset + 1, data[offset]);
offset += data[offset] + 1;
if (hasParent) {
_parentId = data.getGuid(offset);
offset += 16;
}
_version = data.getInt32(offset);
offset += 4;
@ -465,9 +516,11 @@ class TypeTemplate {
var functionIndex = 0;
var propertyIndex = 0;
var eventIndex = 0;
var constantIndex = 0;
for (int i = 0; i < methodsCount; i++) {
var type = data[offset] >> 5;
var inherited = (data[offset] & 0x80) > 0;
var type = (data[offset] >> 5) & 0x3;
if (type == 0) // function
{
@ -477,7 +530,7 @@ class TypeTemplate {
var name = data.getString(offset + 1, data[offset]);
offset += data[offset] + 1;
var dt = TemplateDataType.parse(data, offset);
var dt = RepresentationType.parse(data, offset);
offset += dt.size;
// arguments count
@ -485,7 +538,7 @@ class TypeTemplate {
List<ArgumentTemplate> arguments = [];
for (var a = 0; a < argsCount; a++) {
var art = ArgumentTemplate.parse(data, offset);
var art = ArgumentTemplate.parse(data, offset, a);
arguments.add(art.value);
offset += art.size;
}
@ -498,8 +551,8 @@ class TypeTemplate {
offset += cs;
}
var ft = new FunctionTemplate(
this, functionIndex++, name, arguments, dt.value, expansion);
var ft = new FunctionTemplate(this, functionIndex++, name, inherited,
arguments, dt.type, expansion);
_functions.add(ft);
} else if (type == 1) // property
@ -514,7 +567,7 @@ class TypeTemplate {
offset += data[offset] + 1;
var dt = TemplateDataType.parse(data, offset);
var dt = RepresentationType.parse(data, offset);
offset += dt.size;
@ -534,14 +587,8 @@ class TypeTemplate {
offset += cs;
}
var pt = new PropertyTemplate(
this,
propertyIndex++,
name,
dt.value,
readExpansion,
writeExpansion,
recordable ? StorageMode.Recordable : StorageMode.Volatile);
var pt = new PropertyTemplate(this, propertyIndex++, name, inherited,
dt.type, readExpansion, writeExpansion, recordable);
_properties.add(pt);
} else if (type == 2) // Event
@ -553,7 +600,7 @@ class TypeTemplate {
var name = data.getString(offset + 1, data[offset]);
offset += data[offset] + 1;
var dt = TemplateDataType.parse(data, offset);
var dt = RepresentationType.parse(data, offset);
offset += dt.size;
@ -565,10 +612,37 @@ class TypeTemplate {
offset += cs;
}
var et = new EventTemplate(
this, eventIndex++, name, dt.value, expansion, listenable);
var et = new EventTemplate(this, eventIndex++, name, inherited, dt.type,
expansion, listenable);
_events.add(et);
} else if (type == 3) {
String? expansion = null;
var hasExpansion = ((data[offset++] & 0x10) == 0x10);
var name = data.getString(offset + 1, data[offset]);
offset += data[offset] + 1;
var dt = RepresentationType.parse(data, offset);
offset += dt.size;
var parsed = Codec.parse(data, offset, null);
offset += parsed.size;
if (hasExpansion) // expansion ?
{
var cs = data.getUint32(offset);
offset += 4;
expansion = data.getString(offset, cs);
offset += cs;
}
var ct = new ConstantTemplate(this, constantIndex++, name, inherited,
dt.type, parsed.reply.result, expansion);
_constants.add(ct);
}
}
@ -578,5 +652,7 @@ class TypeTemplate {
for (int i = 0; i < _functions.length; i++) _members.add(_functions[i]);
// append properties
for (int i = 0; i < _properties.length; i++) _members.add(_properties[i]);
// append constant
for (int i = 0; i < _constants.length; i++) _members.add(_constants[i]);
}
}

View File

@ -22,6 +22,16 @@ SOFTWARE.
*/
import '../Data/IntType.dart';
import '../Data/TransmissionType.dart';
import '../Data/RepresentationType.dart';
import '../Data/Record.dart';
import '../Core/Tuple.dart';
import '../Data/IRecord.dart';
import '../Core/AsyncException.dart';
import '../Core/ErrorType.dart';
import '../Core/ExceptionCode.dart';
@ -32,7 +42,6 @@ import 'Template/TemplateType.dart';
import 'Template/TypeTemplate.dart';
import '../Data/Guid.dart';
import '../Data/KeyList.dart';
import '../Data/Structure.dart';
import '../Security/Permissions/IPermissionsManager.dart';
import 'IResource.dart';
import 'Instance.dart';
@ -52,7 +61,7 @@ class Warehouse {
static KeyList<TemplateType, KeyList<Guid, TypeTemplate>> _templates =
_initTemplates(); //
static _initTemplates() {
static KeyList<TemplateType, KeyList<Guid, TypeTemplate>> _initTemplates() {
var rt = new KeyList<TemplateType, KeyList<Guid, TypeTemplate>>();
rt.add(TemplateType.Unspecified, new KeyList<Guid, TypeTemplate>());
@ -427,8 +436,7 @@ class Warehouse {
resource.instance = new Instance(
resourceCounter++, name, resource, store, customTemplate, age);
if (attributes != null)
resource.instance?.setAttributes(Structure.fromMap(attributes));
if (attributes != null) resource.instance?.setAttributes(attributes);
if (manager != null) resource.instance?.managers.add(manager);
@ -482,12 +490,14 @@ class Warehouse {
return rt;
}
static KeyList<Type, FactoryEntry> get typesFactory => _factory;
static T createInstance<T>(Type type) {
return _factory[type]?.instanceCreator.call();
return _factory[type]?.instanceCreator.call() as T;
}
static List<T> createArray<T>(Type type) {
return _factory[type]?.arrayCreator.call();
return _factory[type]?.arrayCreator.call() as List<T>;
}
static AsyncReply<T> newResource<T extends IResource>(String name,
@ -495,17 +505,17 @@ class Warehouse {
IResource? parent = null,
IPermissionsManager? manager = null,
Map<String, dynamic>? attributes = null,
properties = null]) {
Map<String, dynamic>? properties = null]) {
if (_factory[T] == null)
throw Exception("No Instance Creator was found for type ${T}");
var resource = _factory[T]?.instanceCreator.call();
var resource = _factory[T]?.instanceCreator.call() as T;
if (properties != null) {
dynamic d = resource;
for (var i = 0; i < properties.length; i++)
d[properties.keys.elementAt(i)] = properties.at(i);
d[properties.keys.elementAt(i)] = properties.values.elementAt(i);
//setProperty(resource, properties.keys.elementAt(i), properties.at(i));
}
@ -669,17 +679,112 @@ class Warehouse {
return rt;
}
static defineCreator(
Type type, Function instanceCreator, Function arrayCreator) {
_factory.add(type, FactoryEntry(type, instanceCreator, arrayCreator));
static List<FactoryEntry> _getTypeEntries<T>(
Function instanceCreator, RepresentationType representationType) {
return [
FactoryEntry<T>(instanceCreator, representationType),
FactoryEntry<T?>(instanceCreator, representationType.toNullable()),
FactoryEntry<List<T>>(
() => <T>[],
RepresentationType(RepresentationTypeIdentifier.TypedList, false,
null, [representationType])),
FactoryEntry<List<T>?>(
() => <T>[],
RepresentationType(RepresentationTypeIdentifier.TypedList, true, null,
[representationType])),
FactoryEntry<List<T?>>(
() => <T?>[],
RepresentationType(RepresentationTypeIdentifier.TypedList, false,
null, [representationType.toNullable()])),
FactoryEntry<List<T?>?>(
() => <T?>[],
RepresentationType(RepresentationTypeIdentifier.TypedList, true, null,
[representationType.toNullable()])),
];
}
static void defineType<T>(
Function instanceCreator, RepresentationType representationType) {
var entries = _getTypeEntries<T>(instanceCreator, representationType);
entries.forEach((e) {
_factory.add(e.type, e);
});
}
static KeyList<Type, FactoryEntry> _getBuiltInTypes() {
var rt = KeyList<Type, FactoryEntry>();
rt.add(
DistributedConnection,
FactoryEntry(DistributedConnection, () => DistributedConnection(),
() => DistributedConnection()));
var types = <FactoryEntry>[
FactoryEntry<DistributedConnection>(
() => DistributedConnection(), RepresentationType.Void)
];
types
..addAll(_getTypeEntries<Int8>(() => 0,
RepresentationType(RepresentationTypeIdentifier.Int8, false)))
..addAll(_getTypeEntries<UInt8>(() => 0,
RepresentationType(RepresentationTypeIdentifier.UInt8, false)))
..addAll(_getTypeEntries<Int16>(() => 0,
RepresentationType(RepresentationTypeIdentifier.Int16, false)))
..addAll(_getTypeEntries<UInt16>(() => 0,
RepresentationType(RepresentationTypeIdentifier.UInt16, false)))
..addAll(_getTypeEntries<Int32>(() => 0,
RepresentationType(RepresentationTypeIdentifier.Int32, false)))
..addAll(_getTypeEntries<UInt32>(() => 0,
RepresentationType(RepresentationTypeIdentifier.UInt32, false)))
..addAll(_getTypeEntries<int>(() => 0,
RepresentationType(RepresentationTypeIdentifier.Int64, false)))
..addAll(_getTypeEntries<bool>(() => false,
RepresentationType(RepresentationTypeIdentifier.Bool, false)))
..addAll(_getTypeEntries<double>(() => 0.0,
RepresentationType(RepresentationTypeIdentifier.Float64, false)))
..addAll(_getTypeEntries<String>(() => "",
RepresentationType(RepresentationTypeIdentifier.String, false)))
..addAll(_getTypeEntries<DateTime>(() => DateTime.now(),
RepresentationType(RepresentationTypeIdentifier.DateTime, false)))
..addAll(_getTypeEntries<Record>(() => Record(),
RepresentationType(RepresentationTypeIdentifier.Record, false)))
..addAll(_getTypeEntries<IResource>(() => null,
RepresentationType(RepresentationTypeIdentifier.Resource, false)))
..addAll(_getTypeEntries<List>(() => [],
RepresentationType(RepresentationTypeIdentifier.List, false)))
..addAll(_getTypeEntries<Map>(() => Map(),
RepresentationType(RepresentationTypeIdentifier.Map, false)))
..addAll(_getTypeEntries<Map<String, dynamic>>(
() => Map<String, dynamic>,
RepresentationType(
RepresentationTypeIdentifier.TypedMap, false, null, [
RepresentationType(RepresentationTypeIdentifier.String, false),
RepresentationType.Dynamic
])))
..addAll(_getTypeEntries<Map<int, dynamic>>(
() => Map<int, dynamic>(),
RepresentationType(
RepresentationTypeIdentifier.TypedMap, false, null, [
RepresentationType(RepresentationTypeIdentifier.Int64, false),
RepresentationType.Dynamic
])))
..addAll(_getTypeEntries<Map<Int32, dynamic>>(
() => Map<Int32, dynamic>(),
RepresentationType(
RepresentationTypeIdentifier.TypedMap, false, null, [
RepresentationType(RepresentationTypeIdentifier.Int32, false),
RepresentationType.Dynamic
])))
..addAll(_getTypeEntries<Map<UInt8, dynamic>>(
() => Map<UInt8, dynamic>(),
RepresentationType(
RepresentationTypeIdentifier.TypedMap, false, null, [
RepresentationType(RepresentationTypeIdentifier.UInt8, false),
RepresentationType.Dynamic
])))
..addAll(
_getTypeEntries<dynamic>(() => Object(), RepresentationType.Dynamic));
types.forEach((element) {
rt.add(element.type, element);
});
return rt;
}
}

View File

@ -123,7 +123,7 @@ class SHA256 {
var data = (BinaryList()
..addDC(msg)
..addDC(paddingBytes)
..addUint64(L))
..addUint64(L, Endian.big))
.toDC();
// append L as a 64-bit big-endian integer, making the total post-processed length a multiple of 512 bits
@ -138,7 +138,8 @@ class SHA256 {
// copy chunk into first 16 words w[0..15] of the message schedule array
var w = new Uint32List(64); // new Uint64List(64); // uint[64];
for (var i = 0; i < 16; i++) w[i] = data.getUint32(chunk + (i * 4));
for (var i = 0; i < 16; i++)
w[i] = data.getUint32(chunk + (i * 4), Endian.big);
//for(var i = 16; i < 64; i++)
// w[i] = 0;
@ -204,7 +205,7 @@ class SHA256 {
//digest := hash := h0 append h1 append h2 append h3 append h4 append h5 append h6 append h7
var results = new BinaryList();
for (var i = 0; i < 8; i++) results.addUint32(hash[i]);
for (var i = 0; i < 8; i++) results.addUint32(hash[i], Endian.big);
return results.toDC();
}

View File

@ -24,13 +24,11 @@ SOFTWARE.
import 'Ruling.dart';
import 'ActionType.dart';
import '../../Data/Structure.dart';
import '../../Resource/IResource.dart';
import '../Authority/Session.dart';
import '../../Resource/Template/MemberTemplate.dart';
abstract class IPermissionsManager
{
abstract class IPermissionsManager {
/// <summary>
/// Check for permission.
/// </summary>
@ -40,9 +38,11 @@ abstract class IPermissionsManager
/// <param name="member">Function, property or event to check for permission.</param>
/// <param name="inquirer">Permission inquirer object.</param>
/// <returns>Allowed or denined.</returns>
Ruling applicable(IResource resource, Session session, ActionType action, MemberTemplate member, [dynamic inquirer = null]);
Ruling applicable(IResource resource, Session session, ActionType action,
MemberTemplate? member,
[dynamic inquirer = null]);
bool initialize(Structure settings, IResource resource);
bool initialize(Map<String, dynamic> settings, IResource resource);
Structure get settings;
Map<String, dynamic> get settings;
}

View File

@ -15,6 +15,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.1"
args:
dependency: "direct main"
description:
@ -29,6 +36,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.1"
bazel_worker:
dependency: transitive
description:
name: bazel_worker
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
boolean_selector:
dependency: transitive
description:
@ -36,6 +50,76 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
build:
dependency: transitive
description:
name: build
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
build_config:
dependency: transitive
description:
name: build_config
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
build_daemon:
dependency: transitive
description:
name: build_daemon
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
build_modules:
dependency: transitive
description:
name: build_modules
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.4"
build_resolvers:
dependency: transitive
description:
name: build_resolvers
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.4"
build_runner:
dependency: "direct dev"
description:
name: build_runner
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.7"
build_runner_core:
dependency: transitive
description:
name: build_runner_core
url: "https://pub.dartlang.org"
source: hosted
version: "7.2.3"
build_web_compilers:
dependency: "direct dev"
description:
name: build_web_compilers
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.2"
built_collection:
dependency: transitive
description:
name: built_collection
url: "https://pub.dartlang.org"
source: hosted
version: "5.1.1"
built_value:
dependency: transitive
description:
name: built_value
url: "https://pub.dartlang.org"
source: hosted
version: "8.1.4"
charcode:
dependency: transitive
description:
@ -57,6 +141,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.3"
code_builder:
dependency: transitive
description:
name: code_builder
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.0"
collection:
dependency: transitive
description:
@ -85,6 +176,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
dart_style:
dependency: transitive
description:
name: dart_style
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
file:
dependency: transitive
description:
@ -92,6 +190,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.2"
fixnum:
dependency: transitive
description:
name: fixnum
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
frontend_server_client:
dependency: transitive
description:
@ -106,6 +211,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
graphs:
dependency: transitive
description:
name: graphs
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
http_multi_server:
dependency: transitive
description:
@ -204,6 +316,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.0"
protobuf:
dependency: transitive
description:
name: protobuf
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
pub_semver:
dependency: transitive
description:
@ -218,6 +337,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
scratch_space:
dependency: transitive
description:
name: scratch_space
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
shelf:
dependency: transitive
description:
@ -281,6 +407,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
stream_transform:
dependency: transitive
description:
name: stream_transform
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
string_scanner:
dependency: transitive
description:
@ -316,6 +449,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.0"
timing:
dependency: transitive
description:
name: timing
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
typed_data:
dependency: transitive
description:
@ -359,4 +499,4 @@ packages:
source: hosted
version: "3.1.0"
sdks:
dart: ">=2.14.0 <3.0.0"
dart: ">=2.15.0 <3.0.0"

View File

@ -1,12 +1,12 @@
name: esiur
description: Distributed Object Framework.
version: 1.4.5
version: 2.0.0
#author: Ahmed Zamil <ahmed@esiur.com>
homepage: https://github.com/esiur/esiur-dart
environment:
sdk: ">=2.14.0 <3.0.0"
sdk: ">=2.15.0 <3.0.0"
dependencies:
# source_gen: ^1.0.5
@ -16,7 +16,8 @@ dependencies:
dev_dependencies:
test:
build_runner: ">=1.6.2 <3.0.0"
build_web_compilers: ">=2.12.0 < 4.0.0"
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

View File

@ -1,9 +1,18 @@
import 'package:esiur/esiur.dart';
import 'TestResource.dart';
main() async {
void main() async {
try {
List<int> a = [2, 1, 2];
Map<Type, int> map = Map();
map[<int?>[].runtimeType] = 33;
print(map[a.runtimeType]);
print(a.runtimeType.toString());
print("Test");
} catch (ex) {
print("Error occured");
print(ex);