mirror of
https://github.com/esiur/esiur-dart.git
synced 2025-05-06 04:02:57 +00:00
2.0.0
This commit is contained in:
parent
92a26b8ce5
commit
88eba227ae
11
.vscode/launch.json
vendored
11
.vscode/launch.json
vendored
@ -13,10 +13,17 @@
|
|||||||
{
|
{
|
||||||
|
|
||||||
"name": "Test",
|
"name": "Test",
|
||||||
"program": "test/template_test/bin/service.dart",
|
"program": "test/template/bin/service.dart",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "dart"
|
"type": "dart"
|
||||||
|
},
|
||||||
|
|
||||||
}
|
{
|
||||||
|
"name": "Flutter",
|
||||||
|
"program": "test/flutter_demo/lib/main.dart",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "dart",
|
||||||
|
"flutterMode": "debug"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -1,3 +1,6 @@
|
|||||||
|
## [1.4.6] - Release
|
||||||
|
Added GetX support
|
||||||
|
|
||||||
## [1.4.3] - Hotfix
|
## [1.4.3] - Hotfix
|
||||||
Bugfix
|
Bugfix
|
||||||
|
|
||||||
|
14
analysis_options.yaml
Normal file
14
analysis_options.yaml
Normal 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
|
@ -58,13 +58,13 @@ void main(List<String> arguments) async {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
} else if (cmd == "version") {
|
} else if (cmd == "version") {
|
||||||
await printVersion();
|
printVersion();
|
||||||
} else {
|
} else {
|
||||||
printUsage();
|
printUsage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printUsage() {
|
void printUsage() {
|
||||||
// print help
|
// print help
|
||||||
print("Esiur package command line");
|
print("Esiur package command line");
|
||||||
print("");
|
print("");
|
||||||
@ -80,7 +80,7 @@ printUsage() {
|
|||||||
print("\t-d, --dir\tName of the directory to generate model inside.");
|
print("\t-d, --dir\tName of the directory to generate model inside.");
|
||||||
}
|
}
|
||||||
|
|
||||||
printVersion() async {
|
void printVersion() async {
|
||||||
var p = Platform.script.pathSegments;
|
var p = Platform.script.pathSegments;
|
||||||
var path = p.take(p.length - 2).join('/') + "/pubspec.yaml";
|
var path = p.take(p.length - 2).join('/') + "/pubspec.yaml";
|
||||||
var yaml = await File(path).readAsString();
|
var yaml = await File(path).readAsString();
|
||||||
|
7
lib/esiur-js.dart
Normal file
7
lib/esiur-js.dart
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import 'dart:js' as js;
|
||||||
|
|
||||||
|
import "esiur.dart" as esiur;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
js.context['wh'] = esiur.Warehouse();
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
// Resource
|
// Resource
|
||||||
export 'src/Resource/Warehouse.dart';
|
export 'src/Resource/Warehouse.dart';
|
||||||
export 'src/Resource/Instance.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/PropertyTemplate.dart';
|
||||||
export 'src/Resource/Template/TypeTemplate.dart';
|
export 'src/Resource/Template/TypeTemplate.dart';
|
||||||
export 'src/Resource/Template/TemplateDescriber.dart';
|
export 'src/Resource/Template/TemplateDescriber.dart';
|
||||||
|
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
|
|
||||||
|
// Proxy
|
||||||
|
export 'src/Proxy/TemplateGenerator.dart';
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
export 'src/Core/ProgressType.dart';
|
export 'src/Core/ProgressType.dart';
|
||||||
export 'src/Core/AsyncBag.dart';
|
export 'src/Core/AsyncBag.dart';
|
||||||
@ -27,26 +31,25 @@ export 'src/Core/ErrorType.dart';
|
|||||||
export 'src/Core/ExceptionCode.dart';
|
export 'src/Core/ExceptionCode.dart';
|
||||||
export 'src/Core/IDestructible.dart';
|
export 'src/Core/IDestructible.dart';
|
||||||
export 'src/Core/IEventHandler.dart';
|
export 'src/Core/IEventHandler.dart';
|
||||||
|
export 'src/Core/Tuple.dart';
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
// Data
|
// Data
|
||||||
export 'src/Data/AutoList.dart';
|
export 'src/Data/AutoList.dart';
|
||||||
export 'src/Data/BinaryList.dart';
|
export 'src/Data/BinaryList.dart';
|
||||||
export 'src/Data/Codec.dart';
|
export 'src/Data/Codec.dart';
|
||||||
export 'src/Data/DataType.dart';
|
export 'src/Data/RepresentationType.dart';
|
||||||
export 'src/Data/DC.dart';
|
export 'src/Data/DC.dart';
|
||||||
export 'src/Data/Guid.dart';
|
export 'src/Data/Guid.dart';
|
||||||
export 'src/Data/KeyList.dart';
|
export 'src/Data/KeyList.dart';
|
||||||
export 'src/Data/NotModified.dart';
|
export 'src/Data/NotModified.dart';
|
||||||
export 'src/Data/PropertyValue.dart';
|
export 'src/Data/PropertyValue.dart';
|
||||||
export 'src/Data/ResourceComparisonResult.dart';
|
|
||||||
export 'src/Data/SizeObject.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/ValueObject.dart';
|
||||||
export 'src/Data/IRecord.dart';
|
export 'src/Data/IRecord.dart';
|
||||||
export 'src/Data/Record.dart';
|
export 'src/Data/Record.dart';
|
||||||
|
export 'src/Data/IEnum.dart';
|
||||||
|
export 'src/Data/IntType.dart';
|
||||||
|
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
// Net
|
// Net
|
||||||
export 'src/Net/NetworkBuffer.dart';
|
export 'src/Net/NetworkBuffer.dart';
|
||||||
|
BIN
lib/esiur.dill
Normal file
BIN
lib/esiur.dill
Normal file
Binary file not shown.
34618
lib/esiur.js
Normal file
34618
lib/esiur.js
Normal file
File diff suppressed because it is too large
Load Diff
1
lib/esiur.js.map
Normal file
1
lib/esiur.js.map
Normal file
File diff suppressed because one or more lines are too long
@ -1,25 +1,15 @@
|
|||||||
import 'AsyncReply.dart';
|
import 'AsyncReply.dart';
|
||||||
import '../Resource/Warehouse.dart';
|
import '../Resource/Warehouse.dart';
|
||||||
|
|
||||||
// class ReplyIndex<T> {
|
|
||||||
// int index;
|
|
||||||
// AsyncReply<T> reply;
|
|
||||||
// T
|
|
||||||
// }
|
|
||||||
|
|
||||||
class AsyncBag<T> extends AsyncReply<List<T>> {
|
class AsyncBag<T> extends AsyncReply<List<T>> {
|
||||||
List<AsyncReply<T>> _replies = <AsyncReply<T>>[];
|
List<AsyncReply<T>> _replies = <AsyncReply<T>>[];
|
||||||
|
|
||||||
//List<T?> _results = <T>[];
|
|
||||||
|
|
||||||
int _count = 0;
|
int _count = 0;
|
||||||
bool _sealedBag = false;
|
bool _sealedBag = false;
|
||||||
|
|
||||||
Type? arrayType;
|
Type? arrayType;
|
||||||
|
|
||||||
seal() {
|
void seal() {
|
||||||
//print("SEALED");
|
|
||||||
|
|
||||||
if (_sealedBag) return;
|
if (_sealedBag) return;
|
||||||
_sealedBag = true;
|
_sealedBag = true;
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ class AsyncException implements Exception {
|
|||||||
|
|
||||||
AsyncException(this.type, this.code, this.message) {}
|
AsyncException(this.type, this.code, this.message) {}
|
||||||
|
|
||||||
static toAsyncException(Exception ex) {
|
static AsyncException toAsyncException(Exception ex) {
|
||||||
return ex is AsyncException
|
return ex is AsyncException
|
||||||
? ex
|
? ex
|
||||||
: new AsyncException(ErrorType.Exception, 0, ex.toString());
|
: new AsyncException(ErrorType.Exception, 0, ex.toString());
|
||||||
|
@ -45,7 +45,7 @@ class AsyncReply<T> implements Future<T> {
|
|||||||
return _resultReady;
|
return _resultReady;
|
||||||
}
|
}
|
||||||
|
|
||||||
set ready(value) {
|
set ready(bool value) {
|
||||||
_resultReady = value;
|
_resultReady = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ class AsyncReply<T> implements Future<T> {
|
|||||||
return _result;
|
return _result;
|
||||||
}
|
}
|
||||||
|
|
||||||
setResultReady(bool val) {
|
void setResultReady(bool val) {
|
||||||
_resultReady = val;
|
_resultReady = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ class IEventHandler {
|
|||||||
|
|
||||||
Map<String, List<Function>> _events = {};
|
Map<String, List<Function>> _events = {};
|
||||||
|
|
||||||
register(String event) {
|
void register(String event) {
|
||||||
_events[event.toLowerCase()] = [];
|
_events[event.toLowerCase()] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,11 +17,11 @@ class IEventHandler {
|
|||||||
Stream<PropertyModificationInfo> get properyModified =>
|
Stream<PropertyModificationInfo> get properyModified =>
|
||||||
_propertyModifiedController.stream;
|
_propertyModifiedController.stream;
|
||||||
|
|
||||||
emitProperty(PropertyModificationInfo event) {
|
void emitProperty(PropertyModificationInfo event) {
|
||||||
_propertyModifiedController.add(event);
|
_propertyModifiedController.add(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
emitArgs(String event, List arguments) {
|
bool emitArgs(String event, List arguments) {
|
||||||
//event = event.toLowerCase();
|
//event = event.toLowerCase();
|
||||||
|
|
||||||
var et = _events[event.toLowerCase()];
|
var et = _events[event.toLowerCase()];
|
||||||
@ -33,14 +33,13 @@ class IEventHandler {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
on(String event, Function callback) {
|
void on(String event, Function callback) {
|
||||||
event = event.toLowerCase();
|
event = event.toLowerCase();
|
||||||
if (!_events.containsKey(event)) register(event);
|
if (!_events.containsKey(event)) register(event);
|
||||||
_events[event]?.add(callback);
|
_events[event]?.add(callback);
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
off(String event, callback) {
|
void off(String event, Function? callback) {
|
||||||
event = event.toLowerCase();
|
event = event.toLowerCase();
|
||||||
if (_events.containsKey(event)) {
|
if (_events.containsKey(event)) {
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
|
@ -9,6 +9,6 @@ class PropertyModificationInfo {
|
|||||||
|
|
||||||
String get name => propertyTemplate.name;
|
String get name => propertyTemplate.name;
|
||||||
|
|
||||||
PropertyModificationInfo(
|
const PropertyModificationInfo(
|
||||||
this.resource, this.propertyTemplate, this.value, this.age);
|
this.resource, this.propertyTemplate, this.value, this.age);
|
||||||
}
|
}
|
||||||
|
63
lib/src/Core/Tuple.dart
Normal file
63
lib/src/Core/Tuple.dart
Normal 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;
|
||||||
|
}
|
@ -1,3 +1,6 @@
|
|||||||
|
|
||||||
|
import '../Core/IEventHandler.dart';
|
||||||
|
|
||||||
import '../Core/IDestructible.dart';
|
import '../Core/IDestructible.dart';
|
||||||
import 'Codec.dart';
|
import 'Codec.dart';
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
@ -8,7 +11,7 @@ class AutoList<T, ST> extends IDestructible with IterableMixin<T> {
|
|||||||
ST? _state;
|
ST? _state;
|
||||||
late bool _removableList;
|
late bool _removableList;
|
||||||
|
|
||||||
sort(int Function(T, T)? compare) {
|
void sort(int Function(T, T)? compare) {
|
||||||
_list.sort(compare);
|
_list.sort(compare);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,36 +41,17 @@ class AutoList<T, ST> extends IDestructible with IterableMixin<T> {
|
|||||||
register("cleared");
|
register("cleared");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
T operator [](int index) {
|
||||||
/// 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) {
|
|
||||||
return _list[index];
|
return _list[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
operator []=(index, value) {
|
void operator []=(int index, T value) {
|
||||||
var oldValue = _list[index];
|
var oldValue = _list[index];
|
||||||
|
|
||||||
if (_removableList) {
|
if (_removableList) {
|
||||||
if (oldValue != null)
|
if (oldValue != null)
|
||||||
(oldValue as IDestructible).off("destroy", _itemDestroyed);
|
(oldValue as IDestructible).off("destroy", _itemDestroyed);
|
||||||
if (value != null) value.on("destroy", _itemDestroyed);
|
if (value != null) (value as IEventHandler).on("destroy", _itemDestroyed);
|
||||||
}
|
}
|
||||||
|
|
||||||
//lock (syncRoot)
|
//lock (syncRoot)
|
||||||
@ -79,7 +63,7 @@ class AutoList<T, ST> extends IDestructible with IterableMixin<T> {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add item to the list
|
/// Add item to the list
|
||||||
/// </summary>
|
/// </summary>
|
||||||
add(T value) {
|
void add(T value) {
|
||||||
if (_removableList) if (value != null)
|
if (_removableList) if (value != null)
|
||||||
(value as IDestructible).on("destroy", _itemDestroyed);
|
(value as IDestructible).on("destroy", _itemDestroyed);
|
||||||
|
|
||||||
@ -92,18 +76,18 @@ class AutoList<T, ST> extends IDestructible with IterableMixin<T> {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add an array of items to the list
|
/// Add an array of items to the list
|
||||||
/// </summary>
|
/// </summary>
|
||||||
addRange(List<T> values) {
|
void addRange(List<T> values) {
|
||||||
values.forEach((x) => add(x));
|
values.forEach((x) => add(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
_itemDestroyed(T sender) {
|
void _itemDestroyed(T sender) {
|
||||||
remove(sender);
|
remove(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clear the list
|
/// Clear the list
|
||||||
/// </summary>
|
/// </summary>
|
||||||
clear() {
|
void clear() {
|
||||||
if (_removableList)
|
if (_removableList)
|
||||||
_list.forEach((x) => (x as IDestructible).off("destroy", _itemDestroyed));
|
_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
|
/// Remove an item from the list
|
||||||
/// <param name="value">Item to remove</param>
|
/// <param name="value">Item to remove</param>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
remove(T value) {
|
void remove(T value) {
|
||||||
if (!_list.contains(value)) return;
|
if (!_list.contains(value)) return;
|
||||||
|
|
||||||
if (_removableList) if (value != null)
|
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
|
/// Check if any item of the given array is in the list
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="values">Array of items</param>
|
/// <param name="values">Array of items</param>
|
||||||
containsAny(values) {
|
bool containsAny(dynamic values) {
|
||||||
if (values is List<T>) {
|
if (values is List<T>) {
|
||||||
for (var v in values) {
|
for (var v in values) {
|
||||||
if (_list.contains(v)) return true;
|
if (_list.contains(v)) return true;
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
import '../Core/AsyncReply.dart';
|
import '../Core/AsyncReply.dart';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'DC.dart';
|
import 'DC.dart';
|
||||||
import 'DataType.dart';
|
|
||||||
import 'Guid.dart';
|
import 'Guid.dart';
|
||||||
|
|
||||||
class BinaryList {
|
class BinaryList {
|
||||||
@ -35,20 +34,22 @@ class BinaryList {
|
|||||||
|
|
||||||
int get length => _list.length;
|
int get length => _list.length;
|
||||||
|
|
||||||
void addDateTime(DateTime value) {
|
void addDateTime(DateTime value, [Endian endian = Endian.little]) {
|
||||||
_list.addAll(DC.dateTimeToBytes(value));
|
_list.addAll(DC.dateTimeToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertDateTime(int position, DateTime value) {
|
void insertDateTime(int position, DateTime value,
|
||||||
_list.insertAll(position, DC.dateTimeToBytes(value));
|
[Endian endian = Endian.little]) {
|
||||||
|
_list.insertAll(position, DC.dateTimeToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addDateTimeArray(List<DateTime> value) {
|
void addDateTimeArray(List<DateTime> value, [Endian endian = Endian.little]) {
|
||||||
_list.addAll(DC.dateTimeArrayToBytes(value));
|
_list.addAll(DC.dateTimeArrayToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertDateTimeArray(int position, List<DateTime> value) {
|
void insertDateTimeArray(int position, List<DateTime> value,
|
||||||
_list.insertAll(position, DC.dateTimeArrayToBytes(value));
|
[Endian endian = Endian.little]) {
|
||||||
|
_list.insertAll(position, DC.dateTimeArrayToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addGuid(Guid value) {
|
void addGuid(Guid value) {
|
||||||
@ -59,14 +60,6 @@ class BinaryList {
|
|||||||
_list.insertAll(position, DC.guidToBytes(value));
|
_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) {
|
void addUint8Array(Uint8List value) {
|
||||||
_list.addAll(value);
|
_list.addAll(value);
|
||||||
}
|
}
|
||||||
@ -79,18 +72,6 @@ class BinaryList {
|
|||||||
_list.insertAll(position, value);
|
_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) {
|
void addString(String value) {
|
||||||
_list.addAll(DC.stringToBytes(value));
|
_list.addAll(DC.stringToBytes(value));
|
||||||
}
|
}
|
||||||
@ -99,14 +80,6 @@ class BinaryList {
|
|||||||
_list.insertAll(position, DC.stringToBytes(value));
|
_list.insertAll(position, DC.stringToBytes(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addStringArray(List<String> value) {
|
|
||||||
_list.addAll(DC.stringArrayToBytes(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void insertStringArray(int position, List<String> value) {
|
|
||||||
_list.insertAll(position, DC.stringArrayToBytes(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void insertUint8(int position, int value) {
|
void insertUint8(int position, int value) {
|
||||||
_list.insert(position, value);
|
_list.insert(position, value);
|
||||||
}
|
}
|
||||||
@ -123,30 +96,14 @@ class BinaryList {
|
|||||||
_list.insert(position, value);
|
_list.insert(position, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addInt8Array(Int8List value) {
|
|
||||||
_list.addAll(DC.int8ArrayToBytes(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void insertInt8Array(int position, Int8List value) {
|
|
||||||
_list.insertAll(position, DC.int8ArrayToBytes(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void addChar(int value) {
|
void addChar(int value) {
|
||||||
_list.addAll(DC.charToBytes(value));
|
_list.addAll(DC.charToBytes(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InsertChar(int position, int value) {
|
void insertChar(int position, int value) {
|
||||||
_list.insertAll(position, DC.charToBytes(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) {
|
void addBoolean(bool value) {
|
||||||
_list.addAll(DC.boolToBytes(value));
|
_list.addAll(DC.boolToBytes(value));
|
||||||
}
|
}
|
||||||
@ -155,237 +112,70 @@ class BinaryList {
|
|||||||
_list.insertAll(position, DC.boolToBytes(value));
|
_list.insertAll(position, DC.boolToBytes(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addBooleanArray(List<bool> value) {
|
void addUint16(int value, [Endian endian = Endian.little]) {
|
||||||
_list.addAll(DC.boolToBytes(value));
|
_list.addAll(DC.uint16ToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertBooleanArray(int position, List<bool> value) {
|
void insertUint16(int position, int value, [Endian endian = Endian.little]) {
|
||||||
_list.insertAll(position, DC.boolToBytes(value));
|
_list.insertAll(position, DC.uint16ToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addUint16(int value) {
|
void addInt16(int value, [Endian endian = Endian.little]) {
|
||||||
_list.addAll(DC.uint16ToBytes(value));
|
_list.addAll(DC.int16ToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertUint16(int position, int value) {
|
void insertInt16(int position, int value, [Endian endian = Endian.little]) {
|
||||||
_list.insertAll(position, DC.uint16ToBytes(value));
|
_list.insertAll(position, DC.int16ToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addUint16Array(Uint16List value) {
|
void addUint32(int value, [Endian endian = Endian.little]) {
|
||||||
_list.addAll(DC.uint16ArrayToBytes(value));
|
_list.addAll(DC.uint32ToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertUint16Array(int position, Uint16List value) {
|
void insertUint32(int position, int value, [Endian endian = Endian.little]) {
|
||||||
_list.insertAll(position, DC.uint16ArrayToBytes(value));
|
_list.insertAll(position, DC.uint32ToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addInt16(int value) {
|
void addInt32(int value, [Endian endian = Endian.little]) {
|
||||||
_list.addAll(DC.int16ToBytes(value));
|
_list.addAll(DC.int32ToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertInt16(int position, int value) {
|
void insertInt32(int position, int value, [Endian endian = Endian.little]) {
|
||||||
_list.insertAll(position, DC.int16ToBytes(value));
|
_list.insertAll(position, DC.int32ToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addInt16Array(Int16List value) {
|
void addUint64(int value, [Endian endian = Endian.little]) {
|
||||||
_list.addAll(DC.int16ArrayToBytes(value));
|
_list.addAll(DC.uint64ToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertInt16Array(int position, Int16List value) {
|
void insertUint64(int position, int value, [Endian endian = Endian.little]) {
|
||||||
_list.insertAll(position, DC.int16ArrayToBytes(value));
|
_list.insertAll(position, DC.uint64ToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addUint32(int value) {
|
void addInt64(int value, [Endian endian = Endian.little]) {
|
||||||
_list.addAll(DC.uint32ToBytes(value));
|
_list.addAll(DC.int64ToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertUint32(int position, int value) {
|
void insertInt64(int position, int value, [Endian endian = Endian.little]) {
|
||||||
_list.insertAll(position, DC.uint32ToBytes(value));
|
_list.insertAll(position, DC.int64ToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addUint32Array(Uint32List value) {
|
void addFloat32(double value, [Endian endian = Endian.little]) {
|
||||||
_list.addAll(DC.uint32ArrayToBytes(value));
|
_list.addAll(DC.float32ToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InsertUint32Array(int position, Uint32List value) {
|
void insertFloat32(int position, double value,
|
||||||
_list.insertAll(position, DC.uint32ArrayToBytes(value));
|
[Endian endian = Endian.little]) {
|
||||||
|
_list.insertAll(position, DC.float32ToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void addInt32(int value) {
|
void addFloat64(double value, [Endian endian = Endian.little]) {
|
||||||
_list.addAll(DC.int32ToBytes(value));
|
_list.addAll(DC.float64ToBytes(value, endian));
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertInt32(int position, int value) {
|
void insertFloat64(int position, double value,
|
||||||
_list.insertAll(position, DC.int32ToBytes(value));
|
[Endian endian = Endian.little]) {
|
||||||
}
|
_list.insertAll(position, DC.float64ToBytes(value, endian));
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -20,7 +20,6 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'BinaryList.dart';
|
import 'BinaryList.dart';
|
||||||
@ -55,6 +54,28 @@ class DC with IterableMixin<int> {
|
|||||||
_dv = ByteData.view(_data.buffer);
|
_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];
|
int operator [](int index) => _data[index];
|
||||||
operator []=(int index, int value) => _data[index] = value;
|
operator []=(int index, int value) => _data[index] = value;
|
||||||
int get length => _data.length;
|
int get length => _data.length;
|
||||||
@ -69,7 +90,7 @@ class DC with IterableMixin<int> {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DC boolToBytes(value) {
|
static DC boolToBytes(bool value) {
|
||||||
var rt = new DC(1);
|
var rt = new DC(1);
|
||||||
rt.setBoolean(0, value);
|
rt.setBoolean(0, value);
|
||||||
return rt;
|
return rt;
|
||||||
@ -81,19 +102,7 @@ class DC with IterableMixin<int> {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DC guidArrayToBytes(List<Guid> value) {
|
static DC int8ToBytes(int 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) {
|
|
||||||
var rt = new DC(1);
|
var rt = new DC(1);
|
||||||
rt.setInt8(0, value);
|
rt.setInt8(0, value);
|
||||||
return rt;
|
return rt;
|
||||||
@ -105,7 +114,7 @@ class DC with IterableMixin<int> {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DC uint8ToBytes(value) {
|
static DC uint8ToBytes(int value) {
|
||||||
var rt = new DC(1);
|
var rt = new DC(1);
|
||||||
rt.setUint8(0, value);
|
rt.setUint8(0, value);
|
||||||
return rt;
|
return rt;
|
||||||
@ -123,28 +132,21 @@ class DC with IterableMixin<int> {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DC charArrayToBytes(Uint16List value) {
|
static DC int16ToBytes(int value, [Endian endian = Endian.little]) {
|
||||||
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) {
|
|
||||||
var rt = new DC(2);
|
var rt = new DC(2);
|
||||||
rt.setInt16(0, value);
|
rt.setInt16(0, value, endian);
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DC int16ArrayToBytes(List<int> value) {
|
static DC int16ArrayToBytes(Int16List value) {
|
||||||
var rt = new DC(value.length * 2);
|
var rt = new DC(value.length * 2);
|
||||||
for (var i = 0; i < value.length; i++) rt.setInt16(i * 2, value[i]);
|
for (var i = 0; i < value.length; i++) rt.setInt16(i * 2, value[i]);
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DC uint16ToBytes(int value) {
|
static DC uint16ToBytes(int value, [Endian endian = Endian.little]) {
|
||||||
var rt = new DC(2);
|
var rt = new DC(2);
|
||||||
rt.setUint16(0, value);
|
rt.setUint16(0, value, endian);
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,9 +156,9 @@ class DC with IterableMixin<int> {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DC int32ToBytes(int value) {
|
static DC int32ToBytes(int value, [Endian endian = Endian.little]) {
|
||||||
var rt = new DC(4);
|
var rt = new DC(4);
|
||||||
rt.setInt32(0, value);
|
rt.setInt32(0, value, endian);
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,9 +168,9 @@ class DC with IterableMixin<int> {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DC uint32ToBytes(int value) {
|
static DC uint32ToBytes(int value, [Endian endian = Endian.little]) {
|
||||||
var rt = new DC(4);
|
var rt = new DC(4);
|
||||||
rt.setUint32(0, value);
|
rt.setUint32(0, value, endian);
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,9 +180,9 @@ class DC with IterableMixin<int> {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DC float32ToBytes(double value) {
|
static DC float32ToBytes(double value, [Endian endian = Endian.little]) {
|
||||||
var rt = new DC(4);
|
var rt = new DC(4);
|
||||||
rt.setFloat32(0, value);
|
rt.setFloat32(0, value, endian);
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,9 +192,9 @@ class DC with IterableMixin<int> {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DC int64ToBytes(int value) {
|
static DC int64ToBytes(int value, [Endian endian = Endian.little]) {
|
||||||
var rt = new DC(8);
|
var rt = new DC(8);
|
||||||
rt.setInt64(0, value);
|
rt.setInt64(0, value, endian);
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,9 +204,9 @@ class DC with IterableMixin<int> {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DC uint64ToBytes(int value) {
|
static DC uint64ToBytes(int value, [Endian endian = Endian.little]) {
|
||||||
var rt = new DC(8);
|
var rt = new DC(8);
|
||||||
rt.setUint64(0, value);
|
rt.setUint64(0, value, endian);
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,9 +216,9 @@ class DC with IterableMixin<int> {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DC float64ToBytes(double value) {
|
static DC float64ToBytes(double value, [Endian endian = Endian.little]) {
|
||||||
var rt = new DC(8);
|
var rt = new DC(8);
|
||||||
rt.setFloat64(0, value);
|
rt.setFloat64(0, value, endian);
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,15 +228,15 @@ class DC with IterableMixin<int> {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DC dateTimeToBytes(DateTime value) {
|
static DC dateTimeToBytes(DateTime value, [Endian endian = Endian.little]) {
|
||||||
var rt = new DC(8);
|
var rt = new DC(8);
|
||||||
rt.setDateTime(0, value);
|
rt.setDateTime(0, value, endian);
|
||||||
return rt;
|
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);
|
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;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,26 +246,14 @@ class DC with IterableMixin<int> {
|
|||||||
return rt;
|
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) {
|
DC append(DC src, int offset, int length) {
|
||||||
//if (!(src is DC))
|
//if (!(src is DC))
|
||||||
// src = new DC(src);
|
// src = new DC(src);
|
||||||
|
|
||||||
var appendix = src.clip(offset, length);
|
var appendix = src.clip(offset, length);
|
||||||
var rt = new DC(this.length + appendix.length);
|
var rt = new DC(this.length + appendix.length);
|
||||||
rt.set(this, 0);
|
rt.set(this, 0, 0, this.length);
|
||||||
rt.set(appendix, this.length);
|
rt.set(appendix, 0, this.length, appendix.length);
|
||||||
|
|
||||||
this._data = rt._data;
|
this._data = rt._data;
|
||||||
this._dv = rt._dv;
|
this._dv = rt._dv;
|
||||||
@ -271,25 +261,25 @@ class DC with IterableMixin<int> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
set(DC dc, int offset) {
|
void set(DC src, int srcOffset, int dstOffset, int length) {
|
||||||
_data.setRange(offset, offset + dc.length, dc._data);
|
_data.setRange(dstOffset, dstOffset + length, src._data, srcOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static combine(a, aOffset, aLength, b, bOffset, bLength) {
|
static DC combine(a, int aOffset, int aLength, b, int bOffset, int bLength) {
|
||||||
if (!(a is DC)) a = new DC(a);
|
if (!(a is DC)) a = DC.fromList(a as List<int>);
|
||||||
if (!(b is DC)) b = new DC(b);
|
if (!(b is DC)) b = DC.fromList(b as List<int>);
|
||||||
|
|
||||||
a = a.clip(aOffset, aLength);
|
a = a.clip(aOffset, aLength);
|
||||||
b = b.clip(bOffset, bLength);
|
b = b.clip(bOffset, bLength);
|
||||||
|
|
||||||
var rt = new DC(a.length + b.length);
|
var rt = new DC(a.length + b.length);
|
||||||
|
|
||||||
rt.set(a, 0);
|
rt.set(a, 0, 0, a.length);
|
||||||
rt.set(b, a.length);
|
rt.set(b, 0, a.length, b.length);
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
DC clip(offset, length) {
|
DC clip(int offset, int length) {
|
||||||
return DC.fromUint8Array(
|
return DC.fromUint8Array(
|
||||||
Uint8List.fromList(_data.getRange(offset, offset + length).toList()));
|
Uint8List.fromList(_data.getRange(offset, offset + length).toList()));
|
||||||
}
|
}
|
||||||
@ -302,28 +292,28 @@ class DC with IterableMixin<int> {
|
|||||||
return _data[offset]; // this.dv.getUint8(offset);
|
return _data[offset]; // this.dv.getUint8(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getInt16(int offset) {
|
int getInt16(int offset, [Endian endian = Endian.little]) {
|
||||||
return _dv.getInt16(offset);
|
return _dv.getInt16(offset, endian);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getUint16(int offset) {
|
int getUint16(int offset, [Endian endian = Endian.little]) {
|
||||||
return _dv.getUint16(offset);
|
return _dv.getUint16(offset, endian);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getInt32(int offset) {
|
int getInt32(int offset, [Endian endian = Endian.little]) {
|
||||||
return _dv.getInt32(offset);
|
return _dv.getInt32(offset, endian);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getUint32(int offset) {
|
int getUint32(int offset, [Endian endian = Endian.little]) {
|
||||||
return _dv.getUint32(offset);
|
return _dv.getUint32(offset, endian);
|
||||||
}
|
}
|
||||||
|
|
||||||
double getFloat32(int offset) {
|
double getFloat32(int offset, [Endian endian = Endian.little]) {
|
||||||
return _dv.getFloat32(offset);
|
return _dv.getFloat32(offset, endian);
|
||||||
}
|
}
|
||||||
|
|
||||||
double getFloat64(int offset) {
|
double getFloat64(int offset, [Endian endian = Endian.little]) {
|
||||||
return _dv.getFloat64(offset);
|
return _dv.getFloat64(offset, endian);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setInt8(int offset, int value) {
|
void setInt8(int offset, int value) {
|
||||||
@ -334,28 +324,28 @@ class DC with IterableMixin<int> {
|
|||||||
return _dv.setUint8(offset, value);
|
return _dv.setUint8(offset, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setInt16(int offset, int value) {
|
void setInt16(int offset, int value, [Endian endian = Endian.little]) {
|
||||||
return _dv.setInt16(offset, value);
|
return _dv.setInt16(offset, value, endian);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUint16(int offset, int value) {
|
void setUint16(int offset, int value, [Endian endian = Endian.little]) {
|
||||||
return _dv.setUint16(offset, value);
|
return _dv.setUint16(offset, value, endian);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setInt32(int offset, int value) {
|
void setInt32(int offset, int value, [Endian endian = Endian.little]) {
|
||||||
return _dv.setInt32(offset, value);
|
return _dv.setInt32(offset, value, endian);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUint32(int offset, int value) {
|
void setUint32(int offset, int value, [Endian endian = Endian.little]) {
|
||||||
return _dv.setUint32(offset, value);
|
return _dv.setUint32(offset, value, endian);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setFloat32(int offset, double value) {
|
void setFloat32(int offset, double value, [Endian endian = Endian.little]) {
|
||||||
return _dv.setFloat32(offset, value);
|
return _dv.setFloat32(offset, value, endian);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setFloat64(int offset, double value) {
|
void setFloat64(int offset, double value, [Endian endian = Endian.little]) {
|
||||||
return _dv.setFloat64(offset, value);
|
return _dv.setFloat64(offset, value, endian);
|
||||||
}
|
}
|
||||||
|
|
||||||
Int8List getInt8Array(int offset, int length) {
|
Int8List getInt8Array(int offset, int length) {
|
||||||
@ -420,12 +410,6 @@ class DC with IterableMixin<int> {
|
|||||||
this.setUint8(offset, value ? 1 : 0);
|
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) {
|
String getChar(int offset) {
|
||||||
return String.fromCharCode(this.getUint16(offset));
|
return String.fromCharCode(this.getUint16(offset));
|
||||||
}
|
}
|
||||||
@ -434,13 +418,7 @@ class DC with IterableMixin<int> {
|
|||||||
this.setUint16(offset, value); //value.codeUnitAt(0));
|
this.setUint16(offset, value); //value.codeUnitAt(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> getCharArray(int offset, int length) {
|
String getHex(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) {
|
|
||||||
var rt = "";
|
var rt = "";
|
||||||
for (var i = offset; i < offset + length; i++) {
|
for (var i = offset; i < offset + length; i++) {
|
||||||
var h = _data[i].toRadixString(16);
|
var h = _data[i].toRadixString(16);
|
||||||
@ -461,13 +439,194 @@ class DC with IterableMixin<int> {
|
|||||||
|
|
||||||
Uint8List toArray() => _data;
|
Uint8List toArray() => _data;
|
||||||
|
|
||||||
String getString(offset, length) {
|
String getString(int offset, int length) {
|
||||||
var bytes = clip(offset, length)._data; // toList(offset, length);
|
var bytes = clip(offset, length)._data; // toList(offset, length);
|
||||||
var str = utf8.decode(bytes);
|
var str = utf8.decode(bytes);
|
||||||
return str;
|
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 = [];
|
List<String> rt = [];
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|
||||||
@ -481,80 +640,15 @@ class DC with IterableMixin<int> {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getInt64(offset) {
|
static DC stringArrayToBytes(List<String> value) {
|
||||||
if (kIsWeb) {
|
var list = new BinaryList();
|
||||||
var h = this.getUint32(offset);
|
for (var i = 0; i < value.length; i++) {
|
||||||
var l = this.getUint32(offset + 4);
|
var s = DC.stringToBytes(value[i]);
|
||||||
return h * TWO_PWR_32 + ((l >= 0) ? l : TWO_PWR_32 + l);
|
list
|
||||||
} else {
|
..addUint32(s.length)
|
||||||
return _dv.getUint64(offset);
|
..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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
508
lib/src/Data/DataDeserializer.dart
Normal file
508
lib/src/Data/DataDeserializer.dart
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
406
lib/src/Data/DataSerializer.dart
Normal file
406
lib/src/Data/DataSerializer.dart
Normal 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());
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,12 @@
|
|||||||
import 'DC.dart';
|
import 'DC.dart';
|
||||||
|
|
||||||
class Guid {
|
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;
|
DC get value => _data;
|
||||||
@ -18,7 +20,7 @@ class Guid {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return _data.getString(0, _data.length);
|
return _data.toHex('');
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
15
lib/src/Data/IEnum.dart
Normal file
15
lib/src/Data/IEnum.dart
Normal 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>';
|
||||||
|
}
|
||||||
|
}
|
@ -24,9 +24,13 @@ SOFTWARE.
|
|||||||
|
|
||||||
import '../Resource/Template/TemplateDescriber.dart';
|
import '../Resource/Template/TemplateDescriber.dart';
|
||||||
|
|
||||||
|
|
||||||
abstract class IRecord {
|
abstract class IRecord {
|
||||||
Map<String, dynamic> serialize();
|
Map<String, dynamic> serialize();
|
||||||
void deserialize(Map<String, dynamic> value);
|
void deserialize(Map<String, dynamic> value);
|
||||||
TemplateDescriber get template;
|
TemplateDescriber get template;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return serialize().toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
69
lib/src/Data/IntType.dart
Normal file
69
lib/src/Data/IntType.dart
Normal 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);
|
||||||
|
}
|
@ -37,9 +37,12 @@ class KeyList<KT, T> extends IEventHandler with MapMixin<KT, T> {
|
|||||||
Iterable<KT> get keys => _map.keys;
|
Iterable<KT> get keys => _map.keys;
|
||||||
Iterable<T> get values => _map.values;
|
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);
|
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];
|
var value = _map[key];
|
||||||
|
|
||||||
if (_removableList)
|
if (_removableList) (value as IDestructible).off("destroy", _itemDestroyed);
|
||||||
(value as IDestructible).off("destroy", _itemDestroyed);
|
|
||||||
|
|
||||||
_map.remove(key);
|
_map.remove(key);
|
||||||
|
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
import 'dart:collection';
|
||||||
|
|
||||||
import '../Resource/Template/TemplateDescriber.dart';
|
import '../Resource/Template/TemplateDescriber.dart';
|
||||||
|
|
||||||
import 'IRecord.dart';
|
import 'IRecord.dart';
|
||||||
import 'KeyList.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>();
|
Map<String, dynamic> _props = Map<String, dynamic>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -17,9 +19,29 @@ class Record extends KeyList with IRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
operator [](index) => _props[index];
|
operator [](index) => _props[index];
|
||||||
operator []=(index, value) => _props[index] = value;
|
operator []=(String index, value) => _props[index] = value;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return _props.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// TODO: implement template
|
// TODO: implement template
|
||||||
TemplateDescriber get template => throw UnimplementedError();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
|
||||||
|
|
||||||
}
|
|
242
lib/src/Data/RepresentationType.dart
Normal file
242
lib/src/Data/RepresentationType.dart
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
class StructureMetadata {
|
|
||||||
List<String>? keys; // = <String>[];
|
|
||||||
List<int>? types;//
|
|
||||||
|
|
||||||
//const StructureMetadata(this.keys, this.types);
|
|
||||||
}
|
|
189
lib/src/Data/TransmissionType.dart
Normal file
189
lib/src/Data/TransmissionType.dart
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@ import 'dart:math';
|
|||||||
class Global {
|
class Global {
|
||||||
static String generateCode(
|
static String generateCode(
|
||||||
[int length = 16,
|
[int length = 16,
|
||||||
chars =
|
String chars =
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"]) {
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"]) {
|
||||||
var rand = Random();
|
var rand = Random();
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -24,6 +24,8 @@ SOFTWARE.
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import '../../Data/IntType.dart';
|
||||||
|
|
||||||
import '../../Resource/Instance.dart';
|
import '../../Resource/Instance.dart';
|
||||||
|
|
||||||
import '../../Core/AsyncException.dart';
|
import '../../Core/AsyncException.dart';
|
||||||
@ -37,7 +39,6 @@ import '../../Data/KeyValuePair.dart';
|
|||||||
import '../../Resource/IResource.dart';
|
import '../../Resource/IResource.dart';
|
||||||
import '../../Core/AsyncReply.dart';
|
import '../../Core/AsyncReply.dart';
|
||||||
import '../../Data/PropertyValue.dart';
|
import '../../Data/PropertyValue.dart';
|
||||||
import '../../Data/Structure.dart';
|
|
||||||
import '../../Data/Codec.dart';
|
import '../../Data/Codec.dart';
|
||||||
import './DistributedConnection.dart';
|
import './DistributedConnection.dart';
|
||||||
import '../Packets/IIPPacketAction.dart';
|
import '../Packets/IIPPacketAction.dart';
|
||||||
@ -196,7 +197,7 @@ class DistributedResource extends IResource {
|
|||||||
|
|
||||||
EventTemplate? et = event is EventTemplate
|
EventTemplate? et = event is EventTemplate
|
||||||
? event
|
? event
|
||||||
: instance?.template.getEventTemplateByName(event);
|
: instance?.template.getEventTemplateByName(event.toString());
|
||||||
|
|
||||||
if (et == null)
|
if (et == null)
|
||||||
return AsyncReply<dynamic>().triggerError(new AsyncException(
|
return AsyncReply<dynamic>().triggerError(new AsyncException(
|
||||||
@ -216,7 +217,7 @@ class DistributedResource extends IResource {
|
|||||||
|
|
||||||
EventTemplate? et = event is EventTemplate
|
EventTemplate? et = event is EventTemplate
|
||||||
? event
|
? event
|
||||||
: instance?.template.getEventTemplateByName(event);
|
: instance?.template.getEventTemplateByName(event.toString());
|
||||||
|
|
||||||
if (et == null)
|
if (et == null)
|
||||||
return AsyncReply().triggerError(new AsyncException(
|
return AsyncReply().triggerError(new AsyncException(
|
||||||
@ -237,28 +238,11 @@ class DistributedResource extends IResource {
|
|||||||
var et = instance?.template.getEventTemplateByIndex(index);
|
var et = instance?.template.getEventTemplateByIndex(index);
|
||||||
if (et != null) {
|
if (et != null) {
|
||||||
emitArgs(et.name, [args]);
|
emitArgs(et.name, [args]);
|
||||||
instance?.emitResourceEvent(null, null, et.name, args);
|
instance?.emitResourceEvent(null, null, et, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncReply<dynamic> internal_invokeByNamedArguments(
|
AsyncReply<dynamic> internal_invoke(int index, Map<UInt8, dynamic> args) {
|
||||||
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) {
|
|
||||||
if (_destroyed) throw new Exception("Trying to access destroyed object");
|
if (_destroyed) throw new Exception("Trying to access destroyed object");
|
||||||
|
|
||||||
if (_suspended) throw new Exception("Trying to access suspended 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)
|
if (index >= ins.template.functions.length)
|
||||||
throw new Exception("Function index is incorrect");
|
throw new Exception("Function index is incorrect");
|
||||||
|
|
||||||
return _connection?.sendInvokeByArrayArguments(
|
return _connection?.sendInvoke(_instanceId as int, index, args)
|
||||||
_instanceId as int, index, args) as AsyncReply;
|
as AsyncReply;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator [](String index) {
|
operator [](String index) {
|
||||||
@ -299,16 +283,24 @@ class DistributedResource extends IResource {
|
|||||||
var ft = instance?.template.getFunctionTemplateByName(memberName);
|
var ft = instance?.template.getFunctionTemplateByName(memberName);
|
||||||
|
|
||||||
if (_attached && ft != null) {
|
if (_attached && ft != null) {
|
||||||
if (invocation.namedArguments.length > 0) {
|
var args = Map<UInt8, dynamic>();
|
||||||
var namedArgs = new Structure();
|
|
||||||
for (var p in invocation.namedArguments.keys)
|
|
||||||
namedArgs[_getMemberName(p)] = invocation.namedArguments[p];
|
|
||||||
|
|
||||||
return internal_invokeByNamedArguments(ft.index, namedArgs);
|
for (var i = 0;
|
||||||
} else {
|
i < invocation.positionalArguments.length &&
|
||||||
return internal_invokeByArrayArguments(
|
i < ft.arguments.length;
|
||||||
ft.index, invocation.positionalArguments);
|
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) {
|
} else if (invocation.isSetter) {
|
||||||
var pt = instance?.template.getPropertyTemplateByName(memberName);
|
var pt = instance?.template.getPropertyTemplateByName(memberName);
|
||||||
@ -381,4 +373,9 @@ class DistributedResource extends IResource {
|
|||||||
|
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return "DR<${instance?.template.className ?? ''}>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,5 +31,4 @@ class DistributedServer extends IResource {
|
|||||||
@override
|
@override
|
||||||
TemplateDescriber get template =>
|
TemplateDescriber get template =>
|
||||||
TemplateDescriber("Esiur.Net.IIP.DistributedServer");
|
TemplateDescriber("Esiur.Net.IIP.DistributedServer");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
import '../../Data/TransmissionType.dart';
|
||||||
|
|
||||||
import '../../Data/DC.dart';
|
import '../../Data/DC.dart';
|
||||||
import '../../Data/Guid.dart';
|
import '../../Data/Guid.dart';
|
||||||
|
|
||||||
@ -29,7 +31,6 @@ import 'IIPPacketCommand.dart';
|
|||||||
import 'IIPPacketEvent.dart';
|
import 'IIPPacketEvent.dart';
|
||||||
import 'IIPPacketReport.dart';
|
import 'IIPPacketReport.dart';
|
||||||
import '../../Data/Codec.dart';
|
import '../../Data/Codec.dart';
|
||||||
import '../../Data/DataType.dart';
|
|
||||||
|
|
||||||
class IIPPacket {
|
class IIPPacket {
|
||||||
int report = 0;
|
int report = 0;
|
||||||
@ -53,7 +54,7 @@ class IIPPacket {
|
|||||||
int storeId = 0;
|
int storeId = 0;
|
||||||
|
|
||||||
int resourceAge = 0;
|
int resourceAge = 0;
|
||||||
DC content = DC(0);
|
//DC content = DC(0);
|
||||||
int errorCode = 0;
|
int errorCode = 0;
|
||||||
String errorMessage = "";
|
String errorMessage = "";
|
||||||
String className = "";
|
String className = "";
|
||||||
@ -68,6 +69,9 @@ class IIPPacket {
|
|||||||
DateTime toDate = DateTime(2000);
|
DateTime toDate = DateTime(2000);
|
||||||
int fromAge = 0;
|
int fromAge = 0;
|
||||||
int toAge = 0;
|
int toAge = 0;
|
||||||
|
String resourceName = "";
|
||||||
|
|
||||||
|
TransmissionType? dataType;
|
||||||
|
|
||||||
int _dataLengthNeeded = 0;
|
int _dataLengthNeeded = 0;
|
||||||
int _originalOffset = 0;
|
int _originalOffset = 0;
|
||||||
@ -137,7 +141,7 @@ class IIPPacket {
|
|||||||
|
|
||||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||||
|
|
||||||
content = data.clip(offset, cl);
|
resourceName = data.getString(offset, cl);
|
||||||
|
|
||||||
offset += cl;
|
offset += cl;
|
||||||
} else if (event == IIPPacketEvent.PropertyUpdated ||
|
} else if (event == IIPPacketEvent.PropertyUpdated ||
|
||||||
@ -146,25 +150,12 @@ class IIPPacket {
|
|||||||
|
|
||||||
methodIndex = data[offset++];
|
methodIndex = data[offset++];
|
||||||
|
|
||||||
var dt = data[offset++];
|
var parsed = TransmissionType.parse(data, offset, ends);
|
||||||
var size = DataType.size(dt);
|
|
||||||
|
|
||||||
if (size < 0) {
|
if (parsed.type == null) return -parsed.size;
|
||||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
|
||||||
|
|
||||||
var cl = data.getUint32(offset);
|
dataType = parsed.type;
|
||||||
offset += 4;
|
offset += parsed.size;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// else if (event == IIPPacketEvent.EventOccurred)
|
// else if (event == IIPPacketEvent.EventOccurred)
|
||||||
// {
|
// {
|
||||||
@ -192,7 +183,8 @@ class IIPPacket {
|
|||||||
|
|
||||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||||
|
|
||||||
content = data.clip(offset, cl);
|
//@TODO: fix this
|
||||||
|
//content = data.clip(offset, cl);
|
||||||
|
|
||||||
offset += cl;
|
offset += cl;
|
||||||
}
|
}
|
||||||
@ -228,7 +220,8 @@ class IIPPacket {
|
|||||||
|
|
||||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
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) {
|
} else if (action == IIPPacketAction.DeleteResource) {
|
||||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
||||||
|
|
||||||
@ -252,7 +245,7 @@ class IIPPacket {
|
|||||||
|
|
||||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||||
|
|
||||||
content = data.clip(offset, cl);
|
resourceName = data.getString(offset, cl);
|
||||||
offset += cl;
|
offset += cl;
|
||||||
} else if (action == IIPPacketAction.TemplateFromClassName) {
|
} else if (action == IIPPacketAction.TemplateFromClassName) {
|
||||||
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
||||||
@ -301,22 +294,20 @@ class IIPPacket {
|
|||||||
|
|
||||||
toDate = data.getDateTime(offset);
|
toDate = data.getDateTime(offset);
|
||||||
offset += 8;
|
offset += 8;
|
||||||
} else if (action == IIPPacketAction.InvokeFunctionArrayArguments ||
|
} else if (action == IIPPacketAction.InvokeFunction) {
|
||||||
action == IIPPacketAction.InvokeFunctionNamedArguments) {
|
if (_notEnough(offset, ends, 6)) return -_dataLengthNeeded;
|
||||||
if (_notEnough(offset, ends, 9)) return -_dataLengthNeeded;
|
|
||||||
|
|
||||||
resourceId = data.getUint32(offset);
|
resourceId = data.getUint32(offset);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
|
|
||||||
methodIndex = data[offset++];
|
methodIndex = data[offset++];
|
||||||
|
|
||||||
var cl = data.getUint32(offset);
|
var parsed = TransmissionType.parse(data, offset, ends);
|
||||||
offset += 4;
|
|
||||||
|
|
||||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
if (parsed.type == null) return -parsed.size;
|
||||||
|
|
||||||
content = data.clip(offset, cl);
|
dataType = parsed.type;
|
||||||
offset += cl;
|
offset += parsed.size;
|
||||||
} else if (action == IIPPacketAction.Listen ||
|
} else if (action == IIPPacketAction.Listen ||
|
||||||
action == IIPPacketAction.Unlisten) {
|
action == IIPPacketAction.Unlisten) {
|
||||||
if (_notEnough(offset, ends, 5)) return -_dataLengthNeeded;
|
if (_notEnough(offset, ends, 5)) return -_dataLengthNeeded;
|
||||||
@ -358,26 +349,12 @@ class IIPPacket {
|
|||||||
offset += 4;
|
offset += 4;
|
||||||
|
|
||||||
methodIndex = data[offset++];
|
methodIndex = data[offset++];
|
||||||
|
var parsed = TransmissionType.parse(data, offset, ends);
|
||||||
|
|
||||||
var dt = data[offset++];
|
if (parsed.type == null) return -parsed.size;
|
||||||
var size = DataType.size(dt);
|
|
||||||
|
|
||||||
if (size < 0) {
|
dataType = parsed.type;
|
||||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
offset += 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Attributes
|
// Attributes
|
||||||
else if (action == IIPPacketAction.UpdateAllAttributes ||
|
else if (action == IIPPacketAction.UpdateAllAttributes ||
|
||||||
@ -393,7 +370,8 @@ class IIPPacket {
|
|||||||
|
|
||||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
||||||
|
|
||||||
content = data.clip(offset, cl);
|
//@TODO: fix this
|
||||||
|
//content = data.clip(offset, cl);
|
||||||
offset += cl;
|
offset += cl;
|
||||||
}
|
}
|
||||||
} else if (command == IIPPacketCommand.Reply) {
|
} else if (command == IIPPacketCommand.Reply) {
|
||||||
@ -415,15 +393,12 @@ class IIPPacket {
|
|||||||
resourceLink = data.getString(offset, cl);
|
resourceLink = data.getString(offset, cl);
|
||||||
offset += cl;
|
offset += cl;
|
||||||
|
|
||||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
var parsed = TransmissionType.parse(data, offset, ends);
|
||||||
|
|
||||||
cl = data.getUint32(offset);
|
if (parsed.type == null) return -parsed.size;
|
||||||
offset += 4;
|
|
||||||
|
|
||||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
dataType = parsed.type;
|
||||||
|
offset += parsed.size;
|
||||||
content = data.clip(offset, cl);
|
|
||||||
offset += cl;
|
|
||||||
} else if (action == IIPPacketAction.DetachResource) {
|
} else if (action == IIPPacketAction.DetachResource) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
} else if (action == IIPPacketAction.CreateResource) {
|
} else if (action == IIPPacketAction.CreateResource) {
|
||||||
@ -450,41 +425,26 @@ class IIPPacket {
|
|||||||
||
|
||
|
||||||
action == IIPPacketAction.GetAllAttributes ||
|
action == IIPPacketAction.GetAllAttributes ||
|
||||||
action == IIPPacketAction.GetAttributes) {
|
action == IIPPacketAction.GetAttributes) {
|
||||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
||||||
|
|
||||||
var cl = data.getUint32(offset);
|
var parsed = TransmissionType.parse(data, offset, ends);
|
||||||
offset += 4;
|
|
||||||
|
|
||||||
if (_notEnough(offset, ends, cl)) return -_dataLengthNeeded;
|
if (parsed.type == null) return -parsed.size;
|
||||||
|
|
||||||
content = data.clip(offset, cl);
|
dataType = parsed.type;
|
||||||
offset += cl;
|
offset += parsed.size;
|
||||||
} else if (action == IIPPacketAction.InvokeFunctionArrayArguments ||
|
} else if (action == IIPPacketAction.InvokeFunction)
|
||||||
action == IIPPacketAction.InvokeFunctionNamedArguments)
|
|
||||||
//|| action == IIPPacketAction.GetProperty
|
//|| action == IIPPacketAction.GetProperty
|
||||||
//|| action == IIPPacketAction.GetPropertyIfModified)
|
//|| action == IIPPacketAction.GetPropertyIfModified)
|
||||||
{
|
{
|
||||||
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
||||||
|
|
||||||
var dt = data[offset++];
|
var parsed = TransmissionType.parse(data, offset, ends);
|
||||||
var size = DataType.size(dt);
|
|
||||||
|
|
||||||
if (size < 0) {
|
if (parsed.type == null) return -parsed.size;
|
||||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
|
||||||
|
|
||||||
var cl = data.getUint32(offset);
|
dataType = parsed.type;
|
||||||
offset += 4;
|
offset += parsed.size;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
} else if (action == IIPPacketAction.SetProperty ||
|
} else if (action == IIPPacketAction.SetProperty ||
|
||||||
action == IIPPacketAction.Listen ||
|
action == IIPPacketAction.Listen ||
|
||||||
action == IIPPacketAction.Unlisten) {
|
action == IIPPacketAction.Unlisten) {
|
||||||
@ -521,25 +481,12 @@ class IIPPacket {
|
|||||||
} else if (report == IIPPacketReport.ChunkStream) {
|
} else if (report == IIPPacketReport.ChunkStream) {
|
||||||
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
if (_notEnough(offset, ends, 1)) return -_dataLengthNeeded;
|
||||||
|
|
||||||
var dt = data[offset++];
|
var parsed = TransmissionType.parse(data, offset, ends);
|
||||||
var size = DataType.size(dt);
|
|
||||||
|
|
||||||
if (size < 0) {
|
if (parsed.type == null) return -parsed.size;
|
||||||
if (_notEnough(offset, ends, 4)) return -_dataLengthNeeded;
|
|
||||||
|
|
||||||
var cl = data.getUint32(offset);
|
dataType = parsed.type;
|
||||||
offset += 4;
|
offset += parsed.size;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ class IIPPacketAction {
|
|||||||
static const int LinkTemplates = 0xF;
|
static const int LinkTemplates = 0xF;
|
||||||
|
|
||||||
// Request Invoke
|
// Request Invoke
|
||||||
static const int InvokeFunctionArrayArguments = 0x10;
|
static const int InvokeFunction = 0x10;
|
||||||
static const int InvokeFunctionNamedArguments = 0x11;
|
static const int Reserved = 0x11;
|
||||||
static const int Listen = 0x12;
|
static const int Listen = 0x12;
|
||||||
static const int Unlisten = 0x13;
|
static const int Unlisten = 0x13;
|
||||||
static const int SetProperty = 0x14;
|
static const int SetProperty = 0x14;
|
||||||
|
@ -71,7 +71,7 @@ class WSocket extends ISocket {
|
|||||||
if (_state == SocketState.Closed || _state == SocketState.Terminated)
|
if (_state == SocketState.Closed || _state == SocketState.Terminated)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var dc = new DC.fromList(data);
|
var dc = new DC.fromList(data as List<int>);
|
||||||
receiveNetworkBuffer.write(dc, 0, dc.length);
|
receiveNetworkBuffer.write(dc, 0, dc.length);
|
||||||
receiver?.networkReceive(this, receiveNetworkBuffer);
|
receiver?.networkReceive(this, receiveNetworkBuffer);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import '../Data/DataType.dart';
|
import '../Data/RepresentationType.dart';
|
||||||
|
|
||||||
import '../Net/IIP/DistributedConnection.dart';
|
import '../Net/IIP/DistributedConnection.dart';
|
||||||
import '../Resource/Template/TemplateType.dart';
|
import '../Resource/Template/TemplateType.dart';
|
||||||
import '../Resource/Warehouse.dart';
|
import '../Resource/Warehouse.dart';
|
||||||
|
|
||||||
import '../Resource/Template/TemplateDataType.dart';
|
|
||||||
|
|
||||||
import '../Resource/Template/TypeTemplate.dart';
|
import '../Resource/Template/TypeTemplate.dart';
|
||||||
|
|
||||||
class TemplateGenerator {
|
class TemplateGenerator {
|
||||||
@ -18,10 +17,22 @@ class TemplateGenerator {
|
|||||||
var className = template.className.split('.').last;
|
var className = template.className.split('.').last;
|
||||||
var rt = StringBuffer();
|
var rt = StringBuffer();
|
||||||
|
|
||||||
rt.writeln("class ${className} extends IRecord {");
|
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) {
|
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("${ptTypeName}? ${p.name};");
|
||||||
rt.writeln();
|
rt.writeln();
|
||||||
});
|
});
|
||||||
@ -50,16 +61,17 @@ class TemplateGenerator {
|
|||||||
rt.writeln("}");
|
rt.writeln("}");
|
||||||
|
|
||||||
// add template
|
// add template
|
||||||
var descProps = template.properties.map((p) {
|
var descProps = template.properties //.where((p) => !p.inherited)
|
||||||
var isArray = p.valueType.type & 0x80 == 0x80;
|
.map((p) {
|
||||||
var ptType = p.valueType.type & 0x7F;
|
var ptTypeName = getTypeName(template, p.valueType, templates);
|
||||||
var ptTypeName = getTypeName(template,
|
return "Prop('${p.name}', getTypeOf<${ptTypeName}>(), ${_escape(p.readExpansion)}, ${_escape(p.writeExpansion)})";
|
||||||
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)})";
|
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
rt.writeln("""@override
|
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}]);""");
|
TemplateDescriber get template => TemplateDescriber('${template.className}', properties: [${descProps}]);""");
|
||||||
|
|
||||||
rt.writeln("\r\n}");
|
rt.writeln("\r\n}");
|
||||||
@ -67,144 +79,140 @@ class TemplateGenerator {
|
|||||||
return rt.toString();
|
return rt.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
static String _translateClassName(String className, bool nullable) {
|
static String _translateClassName(String className) {
|
||||||
var cls = className.split('.');
|
var cls = className.split('.');
|
||||||
var nameSpace = cls.take(cls.length - 1).join('_').toLowerCase();
|
var nameSpace = cls.take(cls.length - 1).join('_').toLowerCase();
|
||||||
return "$nameSpace.${cls.last}${nullable ? '?' : ''}";
|
return "$nameSpace.${cls.last}";
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getTypeName(
|
static String getTypeName(TypeTemplate forTemplate,
|
||||||
TypeTemplate forTemplate,
|
RepresentationType representationType, List<TypeTemplate> templates) {
|
||||||
TemplateDataType templateDataType,
|
String name;
|
||||||
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 &&
|
|
||||||
(x.type == TemplateType.Resource ||
|
|
||||||
x.type == TemplateType.Wrapper));
|
|
||||||
|
|
||||||
if (tmp == null) return "dynamic"; // something went wrong
|
if (representationType.identifier ==
|
||||||
|
RepresentationTypeIdentifier.TypedResource) {
|
||||||
return _translateClassName(tmp.className, nullable);
|
if (representationType.guid == forTemplate.classId)
|
||||||
}
|
name = forTemplate.className.split('.').last;
|
||||||
} else if (templateDataType.type == DataType.ResourceArray) {
|
else
|
||||||
if (templateDataType.typeGuid == forTemplate.classId)
|
name = _translateClassName(templates
|
||||||
return "List<${forTemplate.className.split('.').last + (nullable ? '?' : '')}>";
|
.singleWhere((x) =>
|
||||||
else {
|
x.classId == representationType.guid &&
|
||||||
var tmp = templates.firstWhere((x) =>
|
(x.type == TemplateType.Resource ||
|
||||||
x.classId == templateDataType.typeGuid &&
|
x.type == TemplateType.Wrapper))
|
||||||
(x.type == TemplateType.Resource ||
|
.className);
|
||||||
x.type == TemplateType.Wrapper));
|
} else if (representationType.identifier ==
|
||||||
|
RepresentationTypeIdentifier.TypedRecord) {
|
||||||
if (tmp == null) return "dynamic"; // something went wrong
|
if (representationType.guid == forTemplate.classId)
|
||||||
|
name = forTemplate.className.split('.').last;
|
||||||
return "List<${_translateClassName(tmp.className, nullable)}>";
|
else
|
||||||
}
|
name = _translateClassName(templates
|
||||||
} else if (templateDataType.type == DataType.Record) {
|
.singleWhere((x) =>
|
||||||
if (templateDataType.typeGuid == forTemplate.classId)
|
x.classId == representationType.guid &&
|
||||||
return forTemplate.className.split('.').last + (nullable ? '?' : '');
|
x.type == TemplateType.Record)
|
||||||
else {
|
.className);
|
||||||
var tmp = templates.firstWhere((x) =>
|
} else if (representationType.identifier ==
|
||||||
x.classId == templateDataType.typeGuid &&
|
RepresentationTypeIdentifier
|
||||||
x.type == TemplateType.Record);
|
.Enum) if (representationType.guid == forTemplate.classId)
|
||||||
if (tmp == null) return "dynamic"; // something went wrong
|
name = forTemplate.className.split('.').last;
|
||||||
return _translateClassName(tmp.className, nullable);
|
else
|
||||||
}
|
name = _translateClassName(templates
|
||||||
} else if (templateDataType.type == DataType.RecordArray) {
|
.singleWhere((x) =>
|
||||||
if (templateDataType.typeGuid == forTemplate.classId)
|
x.classId == representationType.guid &&
|
||||||
return "List<${forTemplate.className.split('.').last + (nullable ? '?' : '')}?>";
|
x.type == TemplateType.Enum)
|
||||||
else {
|
.className);
|
||||||
var tmp = templates.firstWhere((x) =>
|
else if (representationType.identifier ==
|
||||||
x.classId == templateDataType.typeGuid &&
|
RepresentationTypeIdentifier.TypedList)
|
||||||
x.type == TemplateType.Record);
|
name = "List<" +
|
||||||
if (tmp == null) return "dynamic"; // something went wrong
|
getTypeName(forTemplate, representationType.subTypes![0], templates) +
|
||||||
return "List<${_translateClassName(tmp.className, nullable)}>";
|
">";
|
||||||
|
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 {
|
||||||
|
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:
|
||||||
|
name = "dynamic";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = ((x) {
|
return (representationType.nullable) ? name + "?" : name;
|
||||||
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";
|
|
||||||
default:
|
|
||||||
return "dynamic";
|
|
||||||
}
|
|
||||||
})(templateDataType.type);
|
|
||||||
|
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static isNullOrEmpty(v) {
|
static bool isNullOrEmpty(v) {
|
||||||
return v == null || v == "";
|
return v == null || v == "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,8 +230,8 @@ class TemplateGenerator {
|
|||||||
var path = _urlRegex.allMatches(url).first;
|
var path = _urlRegex.allMatches(url).first;
|
||||||
var con = await Warehouse.get<DistributedConnection>(
|
var con = await Warehouse.get<DistributedConnection>(
|
||||||
(path[1] as String) + "://" + (path[2] as String),
|
(path[1] as String) + "://" + (path[2] as String),
|
||||||
!isNullOrEmpty(username) && !isNullOrEmpty(password)
|
username != null
|
||||||
? {"username": username, "password": password}
|
? {"username": username, "password": password ?? ""}
|
||||||
: null);
|
: null);
|
||||||
|
|
||||||
if (con == null) throw Exception("Can't connect to server");
|
if (con == null) throw Exception("Can't connect to server");
|
||||||
@ -273,20 +281,33 @@ class TemplateGenerator {
|
|||||||
generateClass(tmp, templates, getx: getx, namedArgs: namedArgs);
|
generateClass(tmp, templates, getx: getx, namedArgs: namedArgs);
|
||||||
} else if (tmp.type == TemplateType.Record) {
|
} else if (tmp.type == TemplateType.Record) {
|
||||||
source = makeImports(tmp) + generateRecord(tmp, templates);
|
source = makeImports(tmp) + generateRecord(tmp, templates);
|
||||||
|
} else if (tmp.type == TemplateType.Enum) {
|
||||||
|
source = makeImports(tmp) + generateEnum(tmp, templates);
|
||||||
}
|
}
|
||||||
f.writeAsStringSync(source);
|
f.writeAsStringSync(source);
|
||||||
});
|
});
|
||||||
|
|
||||||
// generate info class
|
// generate info class
|
||||||
|
// Warehouse.defineType<test.MyService>(
|
||||||
|
// () => test.MyService(),
|
||||||
|
// RepresentationType(RepresentationTypeIdentifier.TypedResource, false,
|
||||||
|
// Guid(DC.fromList([1, 2, 3]))));
|
||||||
|
|
||||||
var defineCreators = templates.map((tmp) {
|
var defineCreators = templates.map((tmp) {
|
||||||
// creator
|
// creator
|
||||||
var className = _translateClassName(tmp.className, false);
|
var className = _translateClassName(tmp.className);
|
||||||
return "Warehouse.defineCreator(${className}, () => ${className}(), () => <${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");
|
}).join("\r\n");
|
||||||
|
|
||||||
var putTemplates = templates.map((tmp) {
|
var putTemplates = templates.map((tmp) {
|
||||||
var className = _translateClassName(tmp.className, false);
|
var className = _translateClassName(tmp.className);
|
||||||
return "Warehouse.putTemplate(TypeTemplate.fromType(${className}));";
|
return "Warehouse.putTemplate(TypeTemplate.fromType(${className}));";
|
||||||
}).join("\r\n");
|
}).join("\r\n");
|
||||||
|
|
||||||
@ -311,6 +332,38 @@ class TemplateGenerator {
|
|||||||
return "r'$str'";
|
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(
|
static String generateClass(
|
||||||
TypeTemplate template,
|
TypeTemplate template,
|
||||||
List<TypeTemplate> templates, {
|
List<TypeTemplate> templates, {
|
||||||
@ -319,14 +372,25 @@ class TemplateGenerator {
|
|||||||
}) {
|
}) {
|
||||||
var className = template.className.split('.').last;
|
var className = template.className.split('.').last;
|
||||||
|
|
||||||
|
String? parentName;
|
||||||
|
|
||||||
var rt = StringBuffer();
|
var rt = StringBuffer();
|
||||||
rt.writeln("class $className extends DistributedResource {");
|
|
||||||
|
|
||||||
rt.writeln(
|
if (template.parentId != null) {
|
||||||
// "$className(DistributedConnection connection, int instanceId, int age, String link) : super(connection, instanceId, age, link) {");
|
parentName = _translateClassName(templates
|
||||||
"$className() {");
|
.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));");
|
rt.writeln("on('${e.name}', (x) => _${e.name}Controller.add(x));");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -349,42 +413,50 @@ class TemplateGenerator {
|
|||||||
}""");
|
}""");
|
||||||
}
|
}
|
||||||
|
|
||||||
template.functions.forEach((f) {
|
template.functions.where((f) => !f.inherited).forEach((f) {
|
||||||
var rtTypeName = getTypeName(template, f.returnType, templates, true);
|
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}(");
|
rt.write("AsyncReply<$rtTypeName> ${f.name}(");
|
||||||
if (f.arguments.isNotEmpty && namedArgs) {
|
|
||||||
rt.write("{");
|
if (positionalArgs.length > 0)
|
||||||
}
|
rt.write(
|
||||||
rt.write(f.arguments.map((x) {
|
"${positionalArgs.map((a) => getTypeName(template, a.type, templates) + " " + a.name).join(',')}");
|
||||||
final typeName = getTypeName(template, x.type, templates, true);
|
|
||||||
return typeName +
|
if (optionalArgs.length > 0) {
|
||||||
(namedArgs && !typeName.endsWith("?") ? "?" : "") +
|
if (positionalArgs.length > 0) rt.write(",");
|
||||||
" " +
|
rt.write(
|
||||||
x.name;
|
"[${optionalArgs.map((a) => getTypeName(template, a.type.toNullable(), templates) + " " + a.name).join(',')}]");
|
||||||
}).join(","));
|
|
||||||
if (f.arguments.isNotEmpty && namedArgs) {
|
|
||||||
rt.write("}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rt.writeln(") {");
|
rt.writeln(") {");
|
||||||
rt.writeln("var rt = AsyncReply<$rtTypeName>();");
|
|
||||||
rt.writeln(
|
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(".then<dynamic>((x) => rt.trigger(x))");
|
||||||
rt.writeln(".error((x) => rt.triggerError(x))");
|
rt.writeln(".error((x) => rt.triggerError(x))");
|
||||||
rt.writeln(".chunk((x) => rt.triggerChunk(x));");
|
rt.writeln(".chunk((x) => rt.triggerChunk(x));");
|
||||||
rt.writeln("return rt; }");
|
rt.writeln("return rt; }");
|
||||||
});
|
});
|
||||||
|
|
||||||
template.properties.forEach((p) {
|
template.properties.where((p) => !p.inherited).forEach((p) {
|
||||||
var ptTypeName = getTypeName(template, p.valueType, templates, true);
|
var ptTypeName = getTypeName(template, p.valueType, templates);
|
||||||
rt.writeln("${ptTypeName} get ${p.name} { return get(${p.index}); }");
|
rt.writeln("${ptTypeName} get ${p.name} { return get(${p.index}); }");
|
||||||
rt.writeln(
|
rt.writeln(
|
||||||
"set ${p.name}(${ptTypeName} value) { set(${p.index}, value); }");
|
"set ${p.name}(${ptTypeName} value) { set(${p.index}, value); }");
|
||||||
});
|
});
|
||||||
|
|
||||||
template.events.forEach((e) {
|
template.events.where((e) => !e.inherited).forEach((e) {
|
||||||
var etTypeName = getTypeName(template, e.argumentType, templates, true);
|
var etTypeName = getTypeName(template, e.argumentType, templates);
|
||||||
|
|
||||||
rt.writeln(
|
rt.writeln(
|
||||||
"final _${e.name}Controller = StreamController<$etTypeName>();");
|
"final _${e.name}Controller = StreamController<$etTypeName>();");
|
||||||
@ -394,41 +466,37 @@ class TemplateGenerator {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// add template
|
// add template
|
||||||
var descProps = template.properties.map((p) {
|
var descProps = template.properties //.where((p) => !p.inherited)
|
||||||
var isArray = p.valueType.type & 0x80 == 0x80;
|
.map((p) {
|
||||||
var ptType = p.valueType.type & 0x7F;
|
var ptTypeName = getTypeName(template, p.valueType, templates);
|
||||||
var ptTypeName = getTypeName(template,
|
return "Prop('${p.name}', getTypeOf<${ptTypeName}>(), ${_escape(p.readExpansion)}, ${_escape(p.writeExpansion)})";
|
||||||
TemplateDataType(ptType, p.valueType.typeGuid), templates, false);
|
|
||||||
return "Prop('${p.name}', ${ptTypeName}, ${isArray}, ${_escape(p.readExpansion)}, ${_escape(p.writeExpansion)})";
|
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
var descFuncs = template.functions.map((f) {
|
var descFuncs = template.functions //.where((f) => !f.inherited)
|
||||||
var isArray = f.returnType.type & 0x80 == 0x80;
|
.map((f) {
|
||||||
var ftType = f.returnType.type & 0x7F;
|
var ftTypeName = getTypeName(template, f.returnType, templates);
|
||||||
var ftTypeName = getTypeName(template,
|
|
||||||
TemplateDataType(ftType, f.returnType.typeGuid), templates, false);
|
|
||||||
|
|
||||||
var args = f.arguments.map((a) {
|
var args = f.arguments.map((a) {
|
||||||
var isArray = a.type.type & 0x80 == 0x80;
|
var atTypeName = getTypeName(template, a.type, templates);
|
||||||
var atType = a.type.type & 0x7F;
|
return "Arg('${a.name}', getTypeOf<${atTypeName}>(), ${a.optional})";
|
||||||
var atTypeName = getTypeName(template,
|
|
||||||
TemplateDataType(atType, a.type.typeGuid), templates, false);
|
|
||||||
return "Arg('${a.name}', ${atTypeName}, ${isArray})";
|
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
return "Func('${f.name}', ${ftTypeName}, ${isArray}, [${args}], ${_escape(f.expansion)})";
|
return "Func('${f.name}', getTypeOf<${ftTypeName}>(), [${args}], ${_escape(f.expansion)})";
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
var descEvents = template.events.map((e) {
|
var descEvents = template.events
|
||||||
var isArray = e.argumentType.type & 0x80 == 0x80;
|
//.where((e) => !e.inherited)
|
||||||
var etType = e.argumentType.type & 0x7F;
|
.map((e) {
|
||||||
var etTypeName = getTypeName(template,
|
var etTypeName = getTypeName(template, e.argumentType, templates);
|
||||||
TemplateDataType(etType, e.argumentType.typeGuid), templates, false);
|
return "Evt('${e.name}', getTypeOf<${etTypeName}>(), ${e.listenable}, ${_escape(e.expansion)})";
|
||||||
return "Evt('${e.name}', ${etTypeName}, ${isArray}, ${e.listenable}, ${_escape(e.expansion)})";
|
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
rt.writeln(
|
if (parentName != null)
|
||||||
"TemplateDescriber get template => TemplateDescriber('${template.className}', properties: [${descProps}], functions: [${descFuncs}], events: [$descEvents]);");
|
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]);");
|
||||||
|
|
||||||
rt.writeln("\r\n}");
|
rt.writeln("\r\n}");
|
||||||
|
|
||||||
|
18
lib/src/Resource/EventOccurredInfo.dart
Normal file
18
lib/src/Resource/EventOccurredInfo.dart
Normal 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) {}
|
||||||
|
}
|
@ -1,7 +1,33 @@
|
|||||||
class FactoryEntry {
|
import '../Data/RepresentationType.dart';
|
||||||
final Type type;
|
|
||||||
final Function instanceCreator;
|
|
||||||
final Function arrayCreator;
|
|
||||||
|
|
||||||
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>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,10 +36,10 @@ abstract class IStore implements IResource {
|
|||||||
AsyncReply<IResource?> retrieve(int iid);
|
AsyncReply<IResource?> retrieve(int iid);
|
||||||
AsyncReply<bool> put(IResource resource);
|
AsyncReply<bool> put(IResource resource);
|
||||||
String? link(IResource resource);
|
String? link(IResource resource);
|
||||||
bool record(IResource resource, String propertyName, dynamic value, int age,
|
bool record(IResource resource, String propertyName, dynamic value, int? age,
|
||||||
DateTime dateTime);
|
DateTime? dateTime);
|
||||||
bool modify(IResource resource, String propertyName, dynamic value, int age,
|
bool modify(IResource resource, String propertyName, dynamic value, int? age,
|
||||||
DateTime dateTime);
|
DateTime? dateTime);
|
||||||
bool remove(IResource resource);
|
bool remove(IResource resource);
|
||||||
|
|
||||||
AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>?> getRecord(
|
AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>?> getRecord(
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import 'dart:core';
|
import 'dart:core';
|
||||||
|
|
||||||
import '../Data/DC.dart';
|
import '../Data/DC.dart';
|
||||||
import '../Data/Structure.dart';
|
|
||||||
import '../Data/AutoList.dart';
|
import '../Data/AutoList.dart';
|
||||||
import './IStore.dart';
|
import './IStore.dart';
|
||||||
import './IResource.dart';
|
import './IResource.dart';
|
||||||
@ -12,6 +11,7 @@ import '../Core/IEventHandler.dart';
|
|||||||
import '../Security/Permissions/Ruling.dart';
|
import '../Security/Permissions/Ruling.dart';
|
||||||
import '../Security/Permissions/IPermissionsManager.dart';
|
import '../Security/Permissions/IPermissionsManager.dart';
|
||||||
import '../Security/Permissions/ActionType.dart';
|
import '../Security/Permissions/ActionType.dart';
|
||||||
|
import 'EventOccurredInfo.dart';
|
||||||
import 'Template/TypeTemplate.dart';
|
import 'Template/TypeTemplate.dart';
|
||||||
import './Template/PropertyTemplate.dart';
|
import './Template/PropertyTemplate.dart';
|
||||||
import './Template/FunctionTemplate.dart';
|
import './Template/FunctionTemplate.dart';
|
||||||
@ -24,7 +24,6 @@ import 'Warehouse.dart';
|
|||||||
|
|
||||||
import '../Core/PropertyModificationInfo.dart';
|
import '../Core/PropertyModificationInfo.dart';
|
||||||
|
|
||||||
|
|
||||||
class Instance extends IEventHandler {
|
class Instance extends IEventHandler {
|
||||||
String _name;
|
String _name;
|
||||||
|
|
||||||
@ -64,8 +63,8 @@ class Instance extends IEventHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Structure getAttributes([List<String>? attributes = null]) {
|
Map<String, dynamic> getAttributes([List<String>? attributes = null]) {
|
||||||
var st = new Structure();
|
var st = Map<String, dynamic>();
|
||||||
|
|
||||||
if (attributes == null) {
|
if (attributes == null) {
|
||||||
var clone = this.attributes.keys.toList();
|
var clone = this.attributes.keys.toList();
|
||||||
@ -77,10 +76,10 @@ class Instance extends IEventHandler {
|
|||||||
if (attr == "name")
|
if (attr == "name")
|
||||||
st["name"] = _name;
|
st["name"] = _name;
|
||||||
else if (attr == "managers") {
|
else if (attr == "managers") {
|
||||||
var mngrs = <Structure>[];
|
var mngrs = <Map<String, dynamic>>[];
|
||||||
|
|
||||||
for (var i = 0; i < _managers.length; i++) {
|
for (var i = 0; i < _managers.length; i++) {
|
||||||
var mst = new Structure();
|
var mst = Map<String, dynamic>();
|
||||||
mst["type"] = _managers[i].runtimeType;
|
mst["type"] = _managers[i].runtimeType;
|
||||||
mst["settings"] = _managers[i].settings;
|
mst["settings"] = _managers[i].settings;
|
||||||
|
|
||||||
@ -103,7 +102,8 @@ class Instance extends IEventHandler {
|
|||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool setAttributes(Structure attributes, [bool clearAttributes = false]) {
|
bool setAttributes(Map<String, dynamic> attributes,
|
||||||
|
[bool clearAttributes = false]) {
|
||||||
try {
|
try {
|
||||||
if (clearAttributes) _attributes.clear();
|
if (clearAttributes) _attributes.clear();
|
||||||
|
|
||||||
@ -256,7 +256,7 @@ class Instance extends IEventHandler {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
int get age => _instanceAge;
|
int get age => _instanceAge;
|
||||||
// this must be internal
|
// this must be internal
|
||||||
set age(value) => _instanceAge = value;
|
set age(int value) => _instanceAge = value;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Last modification date.
|
/// Last modification date.
|
||||||
@ -381,18 +381,19 @@ class Instance extends IEventHandler {
|
|||||||
_ages[pt.index] = _instanceAge;
|
_ages[pt.index] = _instanceAge;
|
||||||
_modificationDates[pt.index] = now;
|
_modificationDates[pt.index] = now;
|
||||||
|
|
||||||
if (pt.storage == StorageMode.NonVolatile) {
|
if (pt.recordable) {
|
||||||
_store?.modify(_resource, pt.name, value, _ages[pt.index], now);
|
|
||||||
} else if (pt.storage == StorageMode.Recordable) {
|
|
||||||
_store?.record(_resource, pt.name, value, _ages[pt.index], now);
|
_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("modified", [pt.name, value]);
|
||||||
_resource.emitArgs(":${pt.name}", [value]);
|
_resource.emitArgs(":${pt.name}", [value]);
|
||||||
|
|
||||||
_resource.emitProperty(
|
_resource.emitProperty(pmInfo);
|
||||||
PropertyModificationInfo(_resource, pt, value, _instanceAge));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -409,10 +410,11 @@ class Instance extends IEventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emitResourceEvent(
|
emitResourceEvent(issuer, bool Function(Session)? receivers,
|
||||||
issuer, List<Session>? receivers, String name, dynamic args) {
|
EventTemplate eventTemplate, dynamic value) {
|
||||||
emitArgs(
|
emitArgs("EventOccurred", [
|
||||||
"resourceEventOccurred", [_resource, issuer, receivers, name, args]);
|
EventOccurredInfo(_resource, eventTemplate, value, issuer, receivers)
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
14
lib/src/Resource/PropertyModificationInfo.dart
Normal file
14
lib/src/Resource/PropertyModificationInfo.dart
Normal 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) {}
|
||||||
|
}
|
@ -1,29 +1,34 @@
|
|||||||
|
import '../../Data/RepresentationType.dart';
|
||||||
|
|
||||||
import '../../Data/DC.dart';
|
import '../../Data/DC.dart';
|
||||||
import '../../Data/BinaryList.dart';
|
import '../../Data/BinaryList.dart';
|
||||||
import "../../Data/ParseResult.dart";
|
import "../../Data/ParseResult.dart";
|
||||||
import './TemplateDataType.dart';
|
|
||||||
|
|
||||||
class ArgumentTemplate {
|
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 cs = data[offset++];
|
||||||
var name = data.getString(offset, cs);
|
var name = data.getString(offset, cs);
|
||||||
offset += cs;
|
offset += cs;
|
||||||
var tdr = TemplateDataType.parse(data, offset);
|
var tdr = RepresentationType.parse(data, offset);
|
||||||
|
|
||||||
return ParseResult<ArgumentTemplate>(
|
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() {
|
DC compose() {
|
||||||
var name = DC.stringToBytes(this.name);
|
var name = DC.stringToBytes(this.name);
|
||||||
|
|
||||||
return (BinaryList()
|
return (BinaryList()
|
||||||
|
..addUint8(optional ? 1 : 0)
|
||||||
..addUint8(name.length)
|
..addUint8(name.length)
|
||||||
..addDC(name)
|
..addDC(name)
|
||||||
..addDC(type.compose()))
|
..addDC(type.compose()))
|
||||||
|
46
lib/src/Resource/Template/ConstantTemplate.dart
Normal file
46
lib/src/Resource/Template/ConstantTemplate.dart
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,20 +3,25 @@ import '../../Data/DC.dart';
|
|||||||
import '../../Data/BinaryList.dart';
|
import '../../Data/BinaryList.dart';
|
||||||
import 'TypeTemplate.dart';
|
import 'TypeTemplate.dart';
|
||||||
import 'MemberType.dart';
|
import 'MemberType.dart';
|
||||||
import 'TemplateDataType.dart';
|
import '../../Data/RepresentationType.dart';
|
||||||
|
|
||||||
class EventTemplate extends MemberTemplate {
|
class EventTemplate extends MemberTemplate {
|
||||||
String? expansion;
|
final String? expansion;
|
||||||
bool listenable;
|
final bool listenable;
|
||||||
TemplateDataType argumentType;
|
final RepresentationType argumentType;
|
||||||
|
|
||||||
DC compose() {
|
DC compose() {
|
||||||
var name = super.compose();
|
var name = super.compose();
|
||||||
|
|
||||||
|
var hdr = inherited ? 0x80 : 0;
|
||||||
|
|
||||||
|
if (listenable) hdr |= 0x8;
|
||||||
|
|
||||||
if (expansion != null) {
|
if (expansion != null) {
|
||||||
var exp = DC.stringToBytes(expansion as String);
|
var exp = DC.stringToBytes(expansion as String);
|
||||||
|
hdr |= 0x50;
|
||||||
return (BinaryList()
|
return (BinaryList()
|
||||||
..addUint8(listenable ? 0x58 : 0x50)
|
..addUint8(hdr)
|
||||||
..addUint8(name.length)
|
..addUint8(name.length)
|
||||||
..addDC(name)
|
..addDC(name)
|
||||||
..addDC(argumentType.compose())
|
..addDC(argumentType.compose())
|
||||||
@ -24,8 +29,9 @@ class EventTemplate extends MemberTemplate {
|
|||||||
..addDC(exp))
|
..addDC(exp))
|
||||||
.toDC();
|
.toDC();
|
||||||
} else {
|
} else {
|
||||||
|
hdr |= 0x40;
|
||||||
return (BinaryList()
|
return (BinaryList()
|
||||||
..addUint8(listenable ? 0x48 : 0x40)
|
..addUint8(hdr)
|
||||||
..addUint8(name.length)
|
..addUint8(name.length)
|
||||||
..addDC(name)
|
..addDC(name)
|
||||||
..addDC(argumentType.compose()))
|
..addDC(argumentType.compose()))
|
||||||
@ -33,7 +39,8 @@ class EventTemplate extends MemberTemplate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EventTemplate(TypeTemplate template, int index, String name,
|
EventTemplate(TypeTemplate template, int index, String name, bool inherited,
|
||||||
this.argumentType, this.expansion, this.listenable)
|
this.argumentType,
|
||||||
: super(template, MemberType.Property, index, name) {}
|
[this.expansion = null, this.listenable = false])
|
||||||
|
: super(template, index, name, inherited) {}
|
||||||
}
|
}
|
||||||
|
@ -4,46 +4,40 @@ import '../../Data/BinaryList.dart';
|
|||||||
import 'TypeTemplate.dart';
|
import 'TypeTemplate.dart';
|
||||||
import 'MemberType.dart';
|
import 'MemberType.dart';
|
||||||
import 'ArgumentTemplate.dart';
|
import 'ArgumentTemplate.dart';
|
||||||
import 'TemplateDataType.dart';
|
import '../../Data/RepresentationType.dart';
|
||||||
|
|
||||||
class FunctionTemplate extends MemberTemplate {
|
class FunctionTemplate extends MemberTemplate {
|
||||||
String? expansion;
|
String? expansion;
|
||||||
// bool isVoid;
|
// bool isVoid;
|
||||||
|
|
||||||
TemplateDataType returnType;
|
|
||||||
List<ArgumentTemplate> arguments;
|
List<ArgumentTemplate> arguments;
|
||||||
|
RepresentationType returnType;
|
||||||
|
|
||||||
DC compose() {
|
DC compose() {
|
||||||
|
var name = super.compose();
|
||||||
|
|
||||||
var name = super.compose();
|
var bl = new BinaryList()
|
||||||
|
..addUint8(name.length)
|
||||||
|
..addDC(name)
|
||||||
|
..addDC(returnType.compose())
|
||||||
|
..addUint8(arguments.length);
|
||||||
|
|
||||||
var bl = new BinaryList()
|
for (var i = 0; i < arguments.length; i++) bl.addDC(arguments[i].compose());
|
||||||
..addUint8(name.length)
|
|
||||||
..addDC(name)
|
|
||||||
..addDC(returnType.compose())
|
|
||||||
..addUint8(arguments.length);
|
|
||||||
|
|
||||||
for (var i = 0; i < arguments.length; i++)
|
if (expansion != null) {
|
||||||
bl.addDC(arguments[i].compose());
|
var exp = DC.stringToBytes(expansion as String);
|
||||||
|
bl
|
||||||
|
..addInt32(exp.length)
|
||||||
|
..addDC(exp);
|
||||||
|
bl.insertUint8(0, inherited ? 0x90 : 0x10);
|
||||||
|
} else
|
||||||
|
bl.insertUint8(0, inherited ? 0x80 : 0x0);
|
||||||
|
|
||||||
|
return bl.toDC();
|
||||||
if (expansion != null)
|
|
||||||
{
|
|
||||||
var exp = DC.stringToBytes(expansion as String);
|
|
||||||
bl..addInt32(exp.length)
|
|
||||||
..addDC(exp);
|
|
||||||
bl.insertUint8(0, 0x10);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
bl.insertUint8(0, 0x0);
|
|
||||||
|
|
||||||
return bl.toDC();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionTemplate(TypeTemplate template, int index, String name,
|
FunctionTemplate(TypeTemplate template, int index, String name,
|
||||||
this.arguments, this.returnType, this.expansion)
|
bool inherited, this.arguments, this.returnType,
|
||||||
: super(template, MemberType.Property, index, name) {
|
[this.expansion = null])
|
||||||
|
: super(template, index, name, inherited) {}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,18 @@
|
|||||||
|
|
||||||
import 'MemberType.dart';
|
import 'MemberType.dart';
|
||||||
import '../../Data/DC.dart';
|
import '../../Data/DC.dart';
|
||||||
import 'TypeTemplate.dart';
|
import 'TypeTemplate.dart';
|
||||||
|
|
||||||
class MemberTemplate
|
class MemberTemplate {
|
||||||
{
|
final TypeTemplate template;
|
||||||
|
final String name;
|
||||||
|
final int index;
|
||||||
|
final bool inherited;
|
||||||
|
|
||||||
int get index => _index;
|
MemberTemplate(this.template, this.index, this.name, this.inherited) {}
|
||||||
String get name => _name;
|
|
||||||
MemberType get type => _type;
|
|
||||||
|
|
||||||
TypeTemplate _template;
|
String get fullname => template.className + "." + name;
|
||||||
String _name;
|
|
||||||
MemberType _type;
|
|
||||||
int _index;
|
|
||||||
|
|
||||||
TypeTemplate get template => _template;
|
DC compose() {
|
||||||
|
return DC.stringToBytes(name);
|
||||||
MemberTemplate(this._template, this._type, this._index, this._name)
|
}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
String get fullname => _template.className + "." + _name;
|
|
||||||
|
|
||||||
DC compose()
|
|
||||||
{
|
|
||||||
return DC.stringToBytes(_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
import 'TemplateDataType.dart';
|
|
||||||
|
|
||||||
import 'MemberTemplate.dart';
|
import 'MemberTemplate.dart';
|
||||||
import '../../Data/DC.dart';
|
import '../../Data/DC.dart';
|
||||||
import '../../Data/BinaryList.dart';
|
import '../../Data/BinaryList.dart';
|
||||||
import 'TypeTemplate.dart';
|
import 'TypeTemplate.dart';
|
||||||
import 'MemberType.dart';
|
import 'MemberType.dart';
|
||||||
import '../StorageMode.dart';
|
import '../StorageMode.dart';
|
||||||
|
import '../../Data/RepresentationType.dart';
|
||||||
|
|
||||||
class PropertyTemplate extends MemberTemplate {
|
class PropertyTemplate extends MemberTemplate {
|
||||||
TemplateDataType valueType;
|
RepresentationType valueType;
|
||||||
|
|
||||||
int permission = 0;
|
int permission = 0;
|
||||||
|
|
||||||
int storage;
|
bool recordable;
|
||||||
|
|
||||||
String? readExpansion;
|
String? readExpansion;
|
||||||
|
|
||||||
@ -20,7 +19,9 @@ class PropertyTemplate extends MemberTemplate {
|
|||||||
|
|
||||||
DC compose() {
|
DC compose() {
|
||||||
var name = super.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) {
|
if (writeExpansion != null && readExpansion != null) {
|
||||||
var rexp = DC.stringToBytes(readExpansion as String);
|
var rexp = DC.stringToBytes(readExpansion as String);
|
||||||
@ -65,8 +66,9 @@ class PropertyTemplate extends MemberTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PropertyTemplate(TypeTemplate template, int index, String name,
|
PropertyTemplate(TypeTemplate template, int index, String name,
|
||||||
this.valueType, this.readExpansion, this.writeExpansion, this.storage)
|
bool inherited, this.valueType,
|
||||||
: super(template, MemberType.Property, index, name) {
|
[this.readExpansion = null,
|
||||||
//this.Recordable = recordable;
|
this.writeExpansion = null,
|
||||||
}
|
this.recordable = false])
|
||||||
|
: super(template, index, name, inherited) {}
|
||||||
}
|
}
|
||||||
|
@ -1,125 +1,124 @@
|
|||||||
//import 'dart:ffi';
|
|
||||||
|
|
||||||
import '../../Data/IRecord.dart';
|
// import '../../Data/IRecord.dart';
|
||||||
import '../../Resource/IResource.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/DataType.dart';
|
||||||
import '../../Data/Guid.dart';
|
// import '../../Data/Guid.dart';
|
||||||
import '../../Data/DC.dart';
|
// import '../../Data/DC.dart';
|
||||||
import '../../Data/BinaryList.dart';
|
// import '../../Data/BinaryList.dart';
|
||||||
import 'TypeTemplate.dart';
|
// import 'TypeTemplate.dart';
|
||||||
import '../../Resource/Warehouse.dart';
|
// import '../../Resource/Warehouse.dart';
|
||||||
import 'TemplateType.dart';
|
// import 'TemplateType.dart';
|
||||||
|
|
||||||
class TemplateDataType {
|
// class TemplateDataType {
|
||||||
late int type;
|
// late int type;
|
||||||
TypeTemplate? get typeTemplate => typeGuid == null
|
// TypeTemplate? get typeTemplate => typeGuid == null
|
||||||
? null
|
// ? null
|
||||||
: Warehouse.getTemplateByClassId(typeGuid as Guid);
|
// : Warehouse.getTemplateByClassId(typeGuid as Guid);
|
||||||
|
|
||||||
Guid? typeGuid;
|
// Guid? typeGuid;
|
||||||
|
|
||||||
// @TODO: implement fromType
|
// // @TODO: implement fromType
|
||||||
TemplateDataType.fromType(type, bool isArray) {
|
// TemplateDataType.fromType(type, bool isArray) {
|
||||||
int dt;
|
// int dt;
|
||||||
|
|
||||||
if (type == null || type == dynamic) {
|
// if (type == null || type == dynamic) {
|
||||||
dt = DataType.Void;
|
// dt = DataType.Void;
|
||||||
}
|
// }
|
||||||
// else if (type is int) {
|
// // else if (type is int) {
|
||||||
// dt = type;
|
// // dt = type;
|
||||||
else if (type == bool)
|
// else if (type == bool)
|
||||||
dt = DataType.Bool;
|
// dt = DataType.Bool;
|
||||||
// else if (type == Uint8)
|
// // else if (type == Uint8)
|
||||||
// dt = DataType.UInt8;
|
// // dt = DataType.UInt8;
|
||||||
// else if (type == Int8)
|
// // else if (type == Int8)
|
||||||
// dt = DataType.Int8;
|
// // dt = DataType.Int8;
|
||||||
// else if (type == Uint16)
|
// // else if (type == Uint16)
|
||||||
// dt = DataType.UInt16;
|
// // dt = DataType.UInt16;
|
||||||
// else if (type == Int16)
|
// // else if (type == Int16)
|
||||||
// dt = DataType.Int16;
|
// // dt = DataType.Int16;
|
||||||
// else if (type == Uint32)
|
// // else if (type == Uint32)
|
||||||
// dt = DataType.UInt32;
|
// // dt = DataType.UInt32;
|
||||||
// else if (type == Int32)
|
// // else if (type == Int32)
|
||||||
// dt = DataType.Int32;
|
// // dt = DataType.Int32;
|
||||||
// else if (type == Uint64)
|
// // else if (type == Uint64)
|
||||||
// dt = DataType.UInt64;
|
// // dt = DataType.UInt64;
|
||||||
else if (/* type == Int64 || */ type == int)
|
// else if (/* type == Int64 || */ type == int)
|
||||||
dt = DataType.Int64;
|
// dt = DataType.Int64;
|
||||||
// else if (type == Float)
|
// // else if (type == Float)
|
||||||
// dt = DataType.Float32;
|
// // dt = DataType.Float32;
|
||||||
else if (/* type == Double || */ type == double)
|
// else if (/* type == Double || */ type == double)
|
||||||
dt = DataType.Float64;
|
// dt = DataType.Float64;
|
||||||
else if (type == String)
|
// else if (type == String)
|
||||||
dt = DataType.String;
|
// dt = DataType.String;
|
||||||
else if (type == DateTime)
|
// else if (type == DateTime)
|
||||||
dt = DataType.DateTime;
|
// dt = DataType.DateTime;
|
||||||
else if (type == Structure)
|
// else if (type == Structure)
|
||||||
dt = DataType.Structure;
|
// dt = DataType.Structure;
|
||||||
else if (type == IResource) // Dynamic resource (unspecified type)
|
// else if (type == IResource) // Dynamic resource (unspecified type)
|
||||||
dt = DataType.Void;
|
// dt = DataType.Void;
|
||||||
else if (type == IRecord) // Dynamic record (unspecified type)
|
// else if (type == IRecord) // Dynamic record (unspecified type)
|
||||||
dt = DataType.Void;
|
// dt = DataType.Void;
|
||||||
else {
|
// else {
|
||||||
var template = Warehouse.getTemplateByType(type);
|
// var template = Warehouse.getTemplateByType(type);
|
||||||
|
|
||||||
if (template != null) {
|
// if (template != null) {
|
||||||
typeGuid = template.classId;
|
// typeGuid = template.classId;
|
||||||
dt = template.type == TemplateType.Resource
|
// dt = template.type == TemplateType.Resource
|
||||||
? DataType.Resource
|
// ? DataType.Resource
|
||||||
: DataType.Record;
|
// : DataType.Record;
|
||||||
} else
|
// } else
|
||||||
dt = DataType.Void;
|
// dt = DataType.Void;
|
||||||
|
|
||||||
// if (template)
|
// // if (template)
|
||||||
// try {
|
// // try {
|
||||||
// var ins = Warehouse.createInstance(type);
|
// // var ins = Warehouse.createInstance(type);
|
||||||
// if (ins is IResource) {
|
// // if (ins is IResource) {
|
||||||
// typeGuid = TypeTemplate.getTypeGuid(ins.template.nameSpace);
|
// // typeGuid = TypeTemplate.getTypeGuid(ins.template.nameSpace);
|
||||||
// } else if (ins is IRecord) {
|
// // } else if (ins is IRecord) {
|
||||||
// typeGuid = TypeTemplate.getTypeGuid(ins.template.nameSpace);
|
// // typeGuid = TypeTemplate.getTypeGuid(ins.template.nameSpace);
|
||||||
// } else {
|
// // } else {
|
||||||
// dt = DataType.Void;
|
// // dt = DataType.Void;
|
||||||
// }
|
// // }
|
||||||
// } catch (ex) {
|
// // } catch (ex) {
|
||||||
// dt = DataType.Void;
|
// // dt = DataType.Void;
|
||||||
// }
|
// // }
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (isArray) dt = dt | 0x80;
|
// if (isArray) dt = dt | 0x80;
|
||||||
|
|
||||||
this.type = dt;
|
// this.type = dt;
|
||||||
}
|
// }
|
||||||
|
|
||||||
DC compose() {
|
// DC compose() {
|
||||||
if (type == DataType.Resource ||
|
// if (type == DataType.Resource ||
|
||||||
type == DataType.ResourceArray ||
|
// type == DataType.ResourceArray ||
|
||||||
type == DataType.Record ||
|
// type == DataType.Record ||
|
||||||
type == DataType.RecordArray) {
|
// type == DataType.RecordArray) {
|
||||||
return (BinaryList()
|
// return (BinaryList()
|
||||||
..addUint8(type)
|
// ..addUint8(type)
|
||||||
..addDC((typeGuid as Guid).value))
|
// ..addDC((typeGuid as Guid).value))
|
||||||
.toDC();
|
// .toDC();
|
||||||
} else
|
// } else
|
||||||
return DC.fromList([type]);
|
// return DC.fromList([type]);
|
||||||
}
|
// }
|
||||||
|
|
||||||
TemplateDataType(this.type, this.typeGuid);
|
// TemplateDataType(this.type, this.typeGuid);
|
||||||
|
|
||||||
static ParseResult<TemplateDataType> parse(DC data, int offset) {
|
// static ParseResult<TemplateDataType> parse(DC data, int offset) {
|
||||||
var type = data[offset++];
|
// var type = data[offset++];
|
||||||
if (type == DataType.Resource ||
|
// if (type == DataType.Resource ||
|
||||||
type == DataType.ResourceArray ||
|
// type == DataType.ResourceArray ||
|
||||||
type == DataType.Record ||
|
// type == DataType.Record ||
|
||||||
type == DataType.RecordArray) {
|
// type == DataType.RecordArray) {
|
||||||
var guid = data.getGuid(offset);
|
// var guid = data.getGuid(offset);
|
||||||
return ParseResult<TemplateDataType>(
|
// return ParseResult<TemplateDataType>(
|
||||||
17, new TemplateDataType(type, guid));
|
// 17, new TemplateDataType(type, guid));
|
||||||
} else
|
// } else
|
||||||
return ParseResult<TemplateDataType>(1, new TemplateDataType(type, null));
|
// return ParseResult<TemplateDataType>(1, new TemplateDataType(type, null));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
@ -1,14 +1,21 @@
|
|||||||
import '../../Data/DataType.dart';
|
|
||||||
|
|
||||||
class TemplateDescriber {
|
class TemplateDescriber {
|
||||||
final List<Prop>? properties;
|
final List<Prop>? properties;
|
||||||
final List<Evt>? events;
|
final List<Evt>? events;
|
||||||
final List<Func>? functions;
|
final List<Func>? functions;
|
||||||
|
final List<Const>? constants;
|
||||||
|
|
||||||
final String nameSpace;
|
final String nameSpace;
|
||||||
final int version;
|
final int version;
|
||||||
|
final Type? parent;
|
||||||
|
|
||||||
TemplateDescriber(this.nameSpace,
|
const TemplateDescriber(this.nameSpace,
|
||||||
{this.properties, this.functions, this.events, this.version = 0});
|
{this.parent,
|
||||||
|
this.properties,
|
||||||
|
this.functions,
|
||||||
|
this.events,
|
||||||
|
this.constants,
|
||||||
|
this.version = 0});
|
||||||
}
|
}
|
||||||
|
|
||||||
// class Property<T> {
|
// class Property<T> {
|
||||||
@ -46,10 +53,10 @@ class TemplateDescriber {
|
|||||||
class Prop {
|
class Prop {
|
||||||
final String name;
|
final String name;
|
||||||
final Type type;
|
final Type type;
|
||||||
final bool isArray;
|
//final bool isNullable;
|
||||||
final String? readAnnotation;
|
final String? readAnnotation;
|
||||||
final String? writeAnnotation;
|
final String? writeAnnotation;
|
||||||
Prop(this.name, this.type, this.isArray,
|
const Prop(this.name, this.type,
|
||||||
[this.readAnnotation = null, this.writeAnnotation = null]);
|
[this.readAnnotation = null, this.writeAnnotation = null]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,28 +64,36 @@ class Evt {
|
|||||||
final String name;
|
final String name;
|
||||||
final bool listenable;
|
final bool listenable;
|
||||||
final Type type;
|
final Type type;
|
||||||
final bool isArray;
|
//final bool isNullable;
|
||||||
final String? annotation;
|
final String? annotation;
|
||||||
|
const Evt(this.name, this.type, [this.listenable = false, this.annotation]);
|
||||||
|
}
|
||||||
|
|
||||||
Evt(this.name, this.type, this.isArray,
|
class Const {
|
||||||
[this.listenable = false, this.annotation]);
|
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 {
|
class Func {
|
||||||
final String name;
|
final String name;
|
||||||
final Type returnType;
|
final Type returnType;
|
||||||
final List<Arg> argsType;
|
final List<Arg> argsType;
|
||||||
final bool isArray;
|
//final bool isNullable;
|
||||||
final String? annotation;
|
final String? annotation;
|
||||||
|
|
||||||
Func(this.name, this.returnType, this.isArray, this.argsType,
|
const Func(this.name, this.returnType, this.argsType,
|
||||||
[this.annotation = null]);
|
[this.annotation = null]);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Arg {
|
class Arg {
|
||||||
final String name;
|
final String name;
|
||||||
final Type type;
|
final Type type;
|
||||||
final bool isArray;
|
//final bool isNullable;
|
||||||
|
final bool optional;
|
||||||
Arg(this.name, this.type, this.isArray);
|
const Arg(this.name, this.type, this.optional);
|
||||||
}
|
}
|
||||||
|
@ -3,4 +3,5 @@ enum TemplateType {
|
|||||||
Resource,
|
Resource,
|
||||||
Record,
|
Record,
|
||||||
Wrapper,
|
Wrapper,
|
||||||
|
Enum
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
//import 'dart:ffi';
|
import '../../Data/Codec.dart';
|
||||||
|
import '../../Data/IEnum.dart';
|
||||||
|
import '../../Data/RepresentationType.dart';
|
||||||
|
|
||||||
import '../../Net/IIP/DistributedResource.dart';
|
import '../../Net/IIP/DistributedResource.dart';
|
||||||
|
|
||||||
@ -16,18 +18,21 @@ import '../../Data/DC.dart';
|
|||||||
import './EventTemplate.dart';
|
import './EventTemplate.dart';
|
||||||
import './PropertyTemplate.dart';
|
import './PropertyTemplate.dart';
|
||||||
import './FunctionTemplate.dart';
|
import './FunctionTemplate.dart';
|
||||||
import '../StorageMode.dart';
|
|
||||||
import 'ArgumentTemplate.dart';
|
import 'ArgumentTemplate.dart';
|
||||||
import 'TemplateDataType.dart';
|
import 'ConstantTemplate.dart';
|
||||||
import 'TemplateType.dart';
|
import 'TemplateType.dart';
|
||||||
|
|
||||||
class TypeTemplate {
|
class TypeTemplate {
|
||||||
late Guid _classId;
|
late Guid _classId;
|
||||||
|
Guid? _parentId = null;
|
||||||
|
|
||||||
late String _className;
|
late String _className;
|
||||||
List<MemberTemplate> _members = [];
|
List<MemberTemplate> _members = [];
|
||||||
List<FunctionTemplate> _functions = [];
|
List<FunctionTemplate> _functions = [];
|
||||||
List<EventTemplate> _events = [];
|
List<EventTemplate> _events = [];
|
||||||
List<PropertyTemplate> _properties = [];
|
List<PropertyTemplate> _properties = [];
|
||||||
|
List<ConstantTemplate> _constants = [];
|
||||||
|
|
||||||
late int _version;
|
late int _version;
|
||||||
//bool isReady;
|
//bool isReady;
|
||||||
|
|
||||||
@ -39,22 +44,14 @@ class TypeTemplate {
|
|||||||
|
|
||||||
TemplateType get type => _templateType;
|
TemplateType get type => _templateType;
|
||||||
|
|
||||||
|
Guid? get parentId => _parentId;
|
||||||
|
|
||||||
Type? _definedType;
|
Type? _definedType;
|
||||||
|
|
||||||
Type? get definedType => _definedType;
|
Type? get definedType => _definedType;
|
||||||
/*
|
|
||||||
MemberTemplate getMemberTemplate(MemberInfo member)
|
Type? get parentDefinedType => _parentDefinedType;
|
||||||
{
|
Type? _parentDefinedType;
|
||||||
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;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//@TODO: implement
|
//@TODO: implement
|
||||||
static List<TypeTemplate> getDependencies(TypeTemplate template) => [];
|
static List<TypeTemplate> getDependencies(TypeTemplate template) => [];
|
||||||
@ -89,6 +86,16 @@ class TypeTemplate {
|
|||||||
return null;
|
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) {
|
static Guid getTypeGuid(String typeName) {
|
||||||
var tn = DC.stringToBytes(typeName);
|
var tn = DC.stringToBytes(typeName);
|
||||||
var hash = SHA256.compute(tn).clip(0, 16);
|
var hash = SHA256.compute(tn).clip(0, 16);
|
||||||
@ -107,20 +114,30 @@ class TypeTemplate {
|
|||||||
|
|
||||||
List<PropertyTemplate> get properties => _properties;
|
List<PropertyTemplate> get properties => _properties;
|
||||||
|
|
||||||
|
List<ConstantTemplate> get constants => _constants;
|
||||||
|
|
||||||
TypeTemplate.fromType(Type type, [bool addToWarehouse = false]) {
|
TypeTemplate.fromType(Type type, [bool addToWarehouse = false]) {
|
||||||
// debugging print("FromType ${type.toString()}");
|
// debugging print("FromType ${type.toString()}");
|
||||||
|
|
||||||
var instance = Warehouse.createInstance(type);
|
var instance = Warehouse.createInstance(type);
|
||||||
|
|
||||||
if (instance is DistributedResource)
|
TemplateDescriber describer;
|
||||||
|
|
||||||
|
if (instance is DistributedResource) {
|
||||||
_templateType = TemplateType.Wrapper;
|
_templateType = TemplateType.Wrapper;
|
||||||
else if (instance is IResource)
|
describer = instance.template;
|
||||||
|
} else if (instance is IResource) {
|
||||||
_templateType = TemplateType.Resource;
|
_templateType = TemplateType.Resource;
|
||||||
else if (instance is IRecord)
|
describer = instance.template;
|
||||||
|
} else if (instance is IRecord) {
|
||||||
_templateType = TemplateType.Record;
|
_templateType = TemplateType.Record;
|
||||||
else
|
describer = instance.template;
|
||||||
|
} else if (instance is IEnum) {
|
||||||
|
_templateType = TemplateType.Enum;
|
||||||
|
describer = instance.template;
|
||||||
|
} else
|
||||||
throw new Exception(
|
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)
|
// if (instance is IRecord)
|
||||||
// _templateType = TemplateType.Record;
|
// _templateType = TemplateType.Record;
|
||||||
@ -129,8 +146,6 @@ class TypeTemplate {
|
|||||||
// else
|
// else
|
||||||
// throw new Exception("Type is neither a resource nor a record.");
|
// throw new Exception("Type is neither a resource nor a record.");
|
||||||
|
|
||||||
TemplateDescriber describer = instance.template;
|
|
||||||
|
|
||||||
_definedType = type;
|
_definedType = type;
|
||||||
|
|
||||||
_className = describer.nameSpace;
|
_className = describer.nameSpace;
|
||||||
@ -143,6 +158,23 @@ class TypeTemplate {
|
|||||||
if (addToWarehouse) Warehouse.putTemplate(this);
|
if (addToWarehouse) Warehouse.putTemplate(this);
|
||||||
// _templates.add(template.classId, template);
|
// _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) {
|
if (describer.properties != null) {
|
||||||
var props = describer.properties as List<Prop>;
|
var props = describer.properties as List<Prop>;
|
||||||
|
|
||||||
@ -152,10 +184,11 @@ class TypeTemplate {
|
|||||||
this,
|
this,
|
||||||
i,
|
i,
|
||||||
pi.name,
|
pi.name,
|
||||||
TemplateDataType.fromType(pi.type, pi.isArray),
|
false,
|
||||||
|
RepresentationType.fromType(pi.type) ?? RepresentationType.Dynamic,
|
||||||
pi.readAnnotation,
|
pi.readAnnotation,
|
||||||
pi.writeAnnotation,
|
pi.writeAnnotation,
|
||||||
0);
|
false);
|
||||||
properties.add(pt);
|
properties.add(pt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,16 +200,24 @@ class TypeTemplate {
|
|||||||
var fi = funcs[i];
|
var fi = funcs[i];
|
||||||
|
|
||||||
List<ArgumentTemplate> args = fi.argsType
|
List<ArgumentTemplate> args = fi.argsType
|
||||||
|
.asMap()
|
||||||
|
.entries
|
||||||
.map((arg) => ArgumentTemplate(
|
.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();
|
.toList();
|
||||||
|
|
||||||
var ft = FunctionTemplate(
|
var ft = FunctionTemplate(
|
||||||
this,
|
this,
|
||||||
i,
|
i,
|
||||||
fi.name,
|
fi.name,
|
||||||
|
false,
|
||||||
args,
|
args,
|
||||||
TemplateDataType.fromType(fi.returnType, fi.isArray),
|
RepresentationType.fromType(fi.returnType) ??
|
||||||
|
RepresentationType.Void,
|
||||||
fi.annotation);
|
fi.annotation);
|
||||||
|
|
||||||
functions.add(ft);
|
functions.add(ft);
|
||||||
@ -192,7 +233,8 @@ class TypeTemplate {
|
|||||||
this,
|
this,
|
||||||
i,
|
i,
|
||||||
ei.name,
|
ei.name,
|
||||||
TemplateDataType.fromType(ei.type, ei.isArray),
|
false,
|
||||||
|
RepresentationType.fromType(ei.type) ?? RepresentationType.Dynamic,
|
||||||
ei.annotation,
|
ei.annotation,
|
||||||
ei.listenable);
|
ei.listenable);
|
||||||
|
|
||||||
@ -204,8 +246,10 @@ class TypeTemplate {
|
|||||||
events.forEach(_members.add);
|
events.forEach(_members.add);
|
||||||
// append slots
|
// append slots
|
||||||
functions.forEach(_members.add);
|
functions.forEach(_members.add);
|
||||||
// append properties
|
// append properties
|
||||||
properties.forEach(_members.add);
|
properties.forEach(_members.add);
|
||||||
|
// append constants
|
||||||
|
constants.forEach(_members.add);
|
||||||
|
|
||||||
// bake it binarily
|
// bake it binarily
|
||||||
var b = BinaryList()
|
var b = BinaryList()
|
||||||
@ -440,22 +484,29 @@ class TypeTemplate {
|
|||||||
// cool Dart feature
|
// cool Dart feature
|
||||||
contentLength ??= data.length;
|
contentLength ??= data.length;
|
||||||
|
|
||||||
int ends = offset + contentLength;
|
//int ends = offset + contentLength;
|
||||||
|
|
||||||
int oOffset = offset;
|
//int oOffset = offset;
|
||||||
|
|
||||||
// start parsing...
|
// start parsing...
|
||||||
|
|
||||||
//var od = new TypeTemplate();
|
//var od = new TypeTemplate();
|
||||||
_content = data.clip(offset, contentLength);
|
_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);
|
_classId = data.getGuid(offset);
|
||||||
offset += 16;
|
offset += 16;
|
||||||
_className = data.getString(offset + 1, data[offset]);
|
_className = data.getString(offset + 1, data[offset]);
|
||||||
offset += data[offset] + 1;
|
offset += data[offset] + 1;
|
||||||
|
|
||||||
|
if (hasParent) {
|
||||||
|
_parentId = data.getGuid(offset);
|
||||||
|
offset += 16;
|
||||||
|
}
|
||||||
|
|
||||||
_version = data.getInt32(offset);
|
_version = data.getInt32(offset);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
|
|
||||||
@ -465,9 +516,11 @@ class TypeTemplate {
|
|||||||
var functionIndex = 0;
|
var functionIndex = 0;
|
||||||
var propertyIndex = 0;
|
var propertyIndex = 0;
|
||||||
var eventIndex = 0;
|
var eventIndex = 0;
|
||||||
|
var constantIndex = 0;
|
||||||
|
|
||||||
for (int i = 0; i < methodsCount; i++) {
|
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
|
if (type == 0) // function
|
||||||
{
|
{
|
||||||
@ -477,7 +530,7 @@ class TypeTemplate {
|
|||||||
var name = data.getString(offset + 1, data[offset]);
|
var name = data.getString(offset + 1, data[offset]);
|
||||||
offset += data[offset] + 1;
|
offset += data[offset] + 1;
|
||||||
|
|
||||||
var dt = TemplateDataType.parse(data, offset);
|
var dt = RepresentationType.parse(data, offset);
|
||||||
offset += dt.size;
|
offset += dt.size;
|
||||||
|
|
||||||
// arguments count
|
// arguments count
|
||||||
@ -485,7 +538,7 @@ class TypeTemplate {
|
|||||||
List<ArgumentTemplate> arguments = [];
|
List<ArgumentTemplate> arguments = [];
|
||||||
|
|
||||||
for (var a = 0; a < argsCount; a++) {
|
for (var a = 0; a < argsCount; a++) {
|
||||||
var art = ArgumentTemplate.parse(data, offset);
|
var art = ArgumentTemplate.parse(data, offset, a);
|
||||||
arguments.add(art.value);
|
arguments.add(art.value);
|
||||||
offset += art.size;
|
offset += art.size;
|
||||||
}
|
}
|
||||||
@ -498,8 +551,8 @@ class TypeTemplate {
|
|||||||
offset += cs;
|
offset += cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ft = new FunctionTemplate(
|
var ft = new FunctionTemplate(this, functionIndex++, name, inherited,
|
||||||
this, functionIndex++, name, arguments, dt.value, expansion);
|
arguments, dt.type, expansion);
|
||||||
|
|
||||||
_functions.add(ft);
|
_functions.add(ft);
|
||||||
} else if (type == 1) // property
|
} else if (type == 1) // property
|
||||||
@ -514,7 +567,7 @@ class TypeTemplate {
|
|||||||
|
|
||||||
offset += data[offset] + 1;
|
offset += data[offset] + 1;
|
||||||
|
|
||||||
var dt = TemplateDataType.parse(data, offset);
|
var dt = RepresentationType.parse(data, offset);
|
||||||
|
|
||||||
offset += dt.size;
|
offset += dt.size;
|
||||||
|
|
||||||
@ -534,14 +587,8 @@ class TypeTemplate {
|
|||||||
offset += cs;
|
offset += cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pt = new PropertyTemplate(
|
var pt = new PropertyTemplate(this, propertyIndex++, name, inherited,
|
||||||
this,
|
dt.type, readExpansion, writeExpansion, recordable);
|
||||||
propertyIndex++,
|
|
||||||
name,
|
|
||||||
dt.value,
|
|
||||||
readExpansion,
|
|
||||||
writeExpansion,
|
|
||||||
recordable ? StorageMode.Recordable : StorageMode.Volatile);
|
|
||||||
|
|
||||||
_properties.add(pt);
|
_properties.add(pt);
|
||||||
} else if (type == 2) // Event
|
} else if (type == 2) // Event
|
||||||
@ -553,7 +600,7 @@ class TypeTemplate {
|
|||||||
var name = data.getString(offset + 1, data[offset]);
|
var name = data.getString(offset + 1, data[offset]);
|
||||||
offset += data[offset] + 1;
|
offset += data[offset] + 1;
|
||||||
|
|
||||||
var dt = TemplateDataType.parse(data, offset);
|
var dt = RepresentationType.parse(data, offset);
|
||||||
|
|
||||||
offset += dt.size;
|
offset += dt.size;
|
||||||
|
|
||||||
@ -565,10 +612,37 @@ class TypeTemplate {
|
|||||||
offset += cs;
|
offset += cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
var et = new EventTemplate(
|
var et = new EventTemplate(this, eventIndex++, name, inherited, dt.type,
|
||||||
this, eventIndex++, name, dt.value, expansion, listenable);
|
expansion, listenable);
|
||||||
|
|
||||||
_events.add(et);
|
_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]);
|
for (int i = 0; i < _functions.length; i++) _members.add(_functions[i]);
|
||||||
// append properties
|
// append properties
|
||||||
for (int i = 0; i < _properties.length; i++) _members.add(_properties[i]);
|
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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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/AsyncException.dart';
|
||||||
import '../Core/ErrorType.dart';
|
import '../Core/ErrorType.dart';
|
||||||
import '../Core/ExceptionCode.dart';
|
import '../Core/ExceptionCode.dart';
|
||||||
@ -32,7 +42,6 @@ import 'Template/TemplateType.dart';
|
|||||||
import 'Template/TypeTemplate.dart';
|
import 'Template/TypeTemplate.dart';
|
||||||
import '../Data/Guid.dart';
|
import '../Data/Guid.dart';
|
||||||
import '../Data/KeyList.dart';
|
import '../Data/KeyList.dart';
|
||||||
import '../Data/Structure.dart';
|
|
||||||
import '../Security/Permissions/IPermissionsManager.dart';
|
import '../Security/Permissions/IPermissionsManager.dart';
|
||||||
import 'IResource.dart';
|
import 'IResource.dart';
|
||||||
import 'Instance.dart';
|
import 'Instance.dart';
|
||||||
@ -52,7 +61,7 @@ class Warehouse {
|
|||||||
static KeyList<TemplateType, KeyList<Guid, TypeTemplate>> _templates =
|
static KeyList<TemplateType, KeyList<Guid, TypeTemplate>> _templates =
|
||||||
_initTemplates(); //
|
_initTemplates(); //
|
||||||
|
|
||||||
static _initTemplates() {
|
static KeyList<TemplateType, KeyList<Guid, TypeTemplate>> _initTemplates() {
|
||||||
var rt = new KeyList<TemplateType, KeyList<Guid, TypeTemplate>>();
|
var rt = new KeyList<TemplateType, KeyList<Guid, TypeTemplate>>();
|
||||||
|
|
||||||
rt.add(TemplateType.Unspecified, new KeyList<Guid, TypeTemplate>());
|
rt.add(TemplateType.Unspecified, new KeyList<Guid, TypeTemplate>());
|
||||||
@ -427,8 +436,7 @@ class Warehouse {
|
|||||||
resource.instance = new Instance(
|
resource.instance = new Instance(
|
||||||
resourceCounter++, name, resource, store, customTemplate, age);
|
resourceCounter++, name, resource, store, customTemplate, age);
|
||||||
|
|
||||||
if (attributes != null)
|
if (attributes != null) resource.instance?.setAttributes(attributes);
|
||||||
resource.instance?.setAttributes(Structure.fromMap(attributes));
|
|
||||||
|
|
||||||
if (manager != null) resource.instance?.managers.add(manager);
|
if (manager != null) resource.instance?.managers.add(manager);
|
||||||
|
|
||||||
@ -482,12 +490,14 @@ class Warehouse {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static KeyList<Type, FactoryEntry> get typesFactory => _factory;
|
||||||
|
|
||||||
static T createInstance<T>(Type type) {
|
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) {
|
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,
|
static AsyncReply<T> newResource<T extends IResource>(String name,
|
||||||
@ -495,17 +505,17 @@ class Warehouse {
|
|||||||
IResource? parent = null,
|
IResource? parent = null,
|
||||||
IPermissionsManager? manager = null,
|
IPermissionsManager? manager = null,
|
||||||
Map<String, dynamic>? attributes = null,
|
Map<String, dynamic>? attributes = null,
|
||||||
properties = null]) {
|
Map<String, dynamic>? properties = null]) {
|
||||||
if (_factory[T] == null)
|
if (_factory[T] == null)
|
||||||
throw Exception("No Instance Creator was found for type ${T}");
|
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) {
|
if (properties != null) {
|
||||||
dynamic d = resource;
|
dynamic d = resource;
|
||||||
|
|
||||||
for (var i = 0; i < properties.length; i++)
|
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));
|
//setProperty(resource, properties.keys.elementAt(i), properties.at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -669,17 +679,112 @@ class Warehouse {
|
|||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static defineCreator(
|
static List<FactoryEntry> _getTypeEntries<T>(
|
||||||
Type type, Function instanceCreator, Function arrayCreator) {
|
Function instanceCreator, RepresentationType representationType) {
|
||||||
_factory.add(type, FactoryEntry(type, instanceCreator, arrayCreator));
|
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() {
|
static KeyList<Type, FactoryEntry> _getBuiltInTypes() {
|
||||||
var rt = KeyList<Type, FactoryEntry>();
|
var rt = KeyList<Type, FactoryEntry>();
|
||||||
rt.add(
|
|
||||||
DistributedConnection,
|
var types = <FactoryEntry>[
|
||||||
FactoryEntry(DistributedConnection, () => DistributedConnection(),
|
FactoryEntry<DistributedConnection>(
|
||||||
() => 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;
|
return rt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ class SHA256 {
|
|||||||
var data = (BinaryList()
|
var data = (BinaryList()
|
||||||
..addDC(msg)
|
..addDC(msg)
|
||||||
..addDC(paddingBytes)
|
..addDC(paddingBytes)
|
||||||
..addUint64(L))
|
..addUint64(L, Endian.big))
|
||||||
.toDC();
|
.toDC();
|
||||||
|
|
||||||
// append L as a 64-bit big-endian integer, making the total post-processed length a multiple of 512 bits
|
// 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
|
// copy chunk into first 16 words w[0..15] of the message schedule array
|
||||||
|
|
||||||
var w = new Uint32List(64); // new Uint64List(64); // uint[64];
|
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++)
|
//for(var i = 16; i < 64; i++)
|
||||||
// w[i] = 0;
|
// 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
|
//digest := hash := h0 append h1 append h2 append h3 append h4 append h5 append h6 append h7
|
||||||
|
|
||||||
var results = new BinaryList();
|
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();
|
return results.toDC();
|
||||||
}
|
}
|
||||||
|
@ -24,13 +24,11 @@ SOFTWARE.
|
|||||||
|
|
||||||
import 'Ruling.dart';
|
import 'Ruling.dart';
|
||||||
import 'ActionType.dart';
|
import 'ActionType.dart';
|
||||||
import '../../Data/Structure.dart';
|
|
||||||
import '../../Resource/IResource.dart';
|
import '../../Resource/IResource.dart';
|
||||||
import '../Authority/Session.dart';
|
import '../Authority/Session.dart';
|
||||||
import '../../Resource/Template/MemberTemplate.dart';
|
import '../../Resource/Template/MemberTemplate.dart';
|
||||||
|
|
||||||
abstract class IPermissionsManager
|
abstract class IPermissionsManager {
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check for permission.
|
/// Check for permission.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -40,9 +38,11 @@ abstract class IPermissionsManager
|
|||||||
/// <param name="member">Function, property or event to check for permission.</param>
|
/// <param name="member">Function, property or event to check for permission.</param>
|
||||||
/// <param name="inquirer">Permission inquirer object.</param>
|
/// <param name="inquirer">Permission inquirer object.</param>
|
||||||
/// <returns>Allowed or denined.</returns>
|
/// <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;
|
||||||
}
|
}
|
||||||
|
142
pubspec.lock
142
pubspec.lock
@ -15,6 +15,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.0"
|
version: "2.0.0"
|
||||||
|
archive:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: archive
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "3.2.1"
|
||||||
args:
|
args:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -29,6 +36,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.8.1"
|
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:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -36,6 +50,76 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0"
|
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:
|
charcode:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -57,6 +141,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.3.3"
|
version: "0.3.3"
|
||||||
|
code_builder:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: code_builder
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "4.1.0"
|
||||||
collection:
|
collection:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -85,6 +176,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.1"
|
version: "3.0.1"
|
||||||
|
dart_style:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: dart_style
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.0"
|
||||||
file:
|
file:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -92,6 +190,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "6.1.2"
|
version: "6.1.2"
|
||||||
|
fixnum:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: fixnum
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.0"
|
||||||
frontend_server_client:
|
frontend_server_client:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -106,6 +211,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.1"
|
version: "2.0.1"
|
||||||
|
graphs:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: graphs
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.0"
|
||||||
http_multi_server:
|
http_multi_server:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -204,6 +316,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.5.0"
|
version: "1.5.0"
|
||||||
|
protobuf:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: protobuf
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.1"
|
||||||
pub_semver:
|
pub_semver:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -218,6 +337,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0"
|
version: "1.2.0"
|
||||||
|
scratch_space:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: scratch_space
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.1"
|
||||||
shelf:
|
shelf:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -281,6 +407,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0"
|
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:
|
string_scanner:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -316,6 +449,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.4.0"
|
version: "0.4.0"
|
||||||
|
timing:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: timing
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.0"
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -359,4 +499,4 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.0"
|
version: "3.1.0"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.14.0 <3.0.0"
|
dart: ">=2.15.0 <3.0.0"
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
name: esiur
|
name: esiur
|
||||||
description: Distributed Object Framework.
|
description: Distributed Object Framework.
|
||||||
version: 1.4.5
|
version: 2.0.0
|
||||||
#author: Ahmed Zamil <ahmed@esiur.com>
|
#author: Ahmed Zamil <ahmed@esiur.com>
|
||||||
homepage: https://github.com/esiur/esiur-dart
|
homepage: https://github.com/esiur/esiur-dart
|
||||||
|
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.14.0 <3.0.0"
|
sdk: ">=2.15.0 <3.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
# source_gen: ^1.0.5
|
# source_gen: ^1.0.5
|
||||||
@ -16,7 +16,8 @@ dependencies:
|
|||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
test:
|
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
|
# For information on the generic Dart part of this file, see the
|
||||||
# following page: https://www.dartlang.org/tools/pub/pubspec
|
# following page: https://www.dartlang.org/tools/pub/pubspec
|
||||||
|
|
||||||
|
@ -1,9 +1,18 @@
|
|||||||
import 'package:esiur/esiur.dart';
|
|
||||||
import 'TestResource.dart';
|
import 'TestResource.dart';
|
||||||
|
|
||||||
main() async {
|
void main() async {
|
||||||
try {
|
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) {
|
} catch (ex) {
|
||||||
print("Error occured");
|
print("Error occured");
|
||||||
print(ex);
|
print(ex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user