2
0
mirror of https://github.com/esiur/esiur-dart.git synced 2026-04-03 17:58:21 +00:00
This commit is contained in:
2024-06-22 03:50:54 +03:00
parent 8a30c92e19
commit 26794f08e7
32 changed files with 1508 additions and 595 deletions

View File

@@ -214,6 +214,7 @@ class Codec {
UInt8: DataSerializer.uInt8Composer,
Int16: DataSerializer.int16Composer,
UInt16: DataSerializer.uInt16Composer,
Float32: DataSerializer.float128Composer,
int: DataSerializer.int64Composer,
//[typeof(long?)] = DataSerializer.Int64Composer,
//[typeof(ulong)] = DataSerializer.UIn64Composer,

View File

@@ -45,13 +45,13 @@ class DataDeserializer {
static AsyncReply byteParser(DC data, int offset, int length,
DistributedConnection? connection, List<int>? requestSequence) {
return new AsyncReply<int>.ready(data[offset]);
return new AsyncReply<UInt8>.ready(data[offset].cast());
}
static AsyncReply sByteParser(DC data, int offset, int length,
DistributedConnection? connection, List<int>? requestSequence) {
return new AsyncReply<int>.ready(
data[offset] > 127 ? data[offset] - 256 : data[offset]);
return new AsyncReply<Int8>.ready(
data[offset] > 127 ? (data[offset] - 256).cast() : data[offset].cast());
}
static AsyncReply char16Parser(DC data, int offset, int length,
@@ -66,27 +66,27 @@ class DataDeserializer {
static AsyncReply int16Parser(DC data, int offset, int length,
DistributedConnection? connection, List<int>? requestSequence) {
return AsyncReply<int>.ready(data.getInt16(offset));
return AsyncReply<Int16>.ready(data.getInt16(offset).cast());
}
static AsyncReply uInt16Parser(DC data, int offset, int length,
DistributedConnection? connection, List<int>? requestSequence) {
return AsyncReply<int>.ready(data.getUint16(offset));
return AsyncReply<UInt16>.ready(data.getUint16(offset).cast());
}
static AsyncReply int32Parser(DC data, int offset, int length,
DistributedConnection? connection, List<int>? requestSequence) {
return AsyncReply<int>.ready(data.getInt32(offset));
return AsyncReply<Int32>.ready(data.getInt32(offset).cast());
}
static AsyncReply uInt32Parser(DC data, int offset, int length,
DistributedConnection? connection, List<int>? requestSequence) {
return AsyncReply<int>.ready(data.getUint32(offset));
return AsyncReply<UInt32>.ready(data.getUint32(offset).cast());
}
static AsyncReply float32Parser(DC data, int offset, int length,
DistributedConnection? connection, List<int>? requestSequence) {
return AsyncReply<double>.ready(data.getFloat32(offset));
return AsyncReply<Float32>.ready(data.getFloat32(offset).cast());
}
static AsyncReply float64Parser(DC data, int offset, int length,
@@ -322,7 +322,10 @@ class DataDeserializer {
offset += valueRep.size;
length -= valueRep.size;
var map = Map();
var keyRuntimeType = keyRep.type.getRuntimeType();
var map = keyRuntimeType == null ? Map() : Warehouse.createMap(keyRuntimeType);
var rt = new AsyncReply();
var results = new AsyncBag();

View File

@@ -35,35 +35,35 @@ class DataSerializer {
static DataSerializerComposeResults int32Composer(
value, DistributedConnection? connection) {
var rt = new DC(4);
rt.setInt32(0, (value as Int32).toInt());
rt.setInt32(0, (value as Int32).toNum());
return DataSerializerComposeResults(TransmissionTypeIdentifier.Int32, rt);
}
static DataSerializerComposeResults uInt32Composer(
value, DistributedConnection? connection) {
var rt = new DC(4);
rt.setUint32(0, (value as UInt32).toInt());
rt.setUint32(0, (value as UInt32).toNum());
return DataSerializerComposeResults(TransmissionTypeIdentifier.UInt32, rt);
}
static DataSerializerComposeResults int16Composer(
value, DistributedConnection? connection) {
var rt = new DC(2);
rt.setInt16(0, (value as Int16).toInt());
rt.setInt16(0, (value as Int16).toNum());
return DataSerializerComposeResults(TransmissionTypeIdentifier.Int16, rt);
}
static DataSerializerComposeResults uInt16Composer(
value, DistributedConnection? connection) {
var rt = new DC(2);
rt.setUint16(0, (value as UInt16).toInt());
rt.setUint16(0, (value as UInt16).toNum());
return DataSerializerComposeResults(TransmissionTypeIdentifier.UInt16, rt);
}
static DataSerializerComposeResults float32Composer(
value, DistributedConnection? connection) {
var rt = new DC(4);
rt.setFloat32(0, value as double);
rt.setFloat32(0, (value as Float32).toNum());
return DataSerializerComposeResults(TransmissionTypeIdentifier.Float32, rt);
}
@@ -140,14 +140,14 @@ class DataSerializer {
static DataSerializerComposeResults uInt8Composer(
value, DistributedConnection? connection) {
var rt = new DC(1);
rt[0] = (value as UInt8).toInt();
rt[0] = (value as UInt8).toNum();
return DataSerializerComposeResults(TransmissionTypeIdentifier.UInt8, rt);
}
static DataSerializerComposeResults int8Composer(
value, DistributedConnection? connection) {
var rt = new DC(1);
rt[0] = (value as Int8).toInt();
rt[0] = (value as Int8).toNum();
return DataSerializerComposeResults(TransmissionTypeIdentifier.Int8, rt);
}

View File

@@ -1,5 +1,5 @@
class IntType {
int _value = 0;
class IntType<T extends num> {
T _value;
bool operator ==(Object other) {
if (other is IntType)
@@ -27,15 +27,44 @@ class IntType {
return this._value <= other._value;
}
operator +(IntType other) {
this._value += other._value;
IntType<T> operator +(IntType<T> other) {
if (this is Int8)
return new Int8(this._value + other._value as int) as IntType<T>;
else if (this is UInt8)
return new UInt8(this._value + other._value as int) as IntType<T>;
else if (this is Int16)
return new Int16(this._value + other._value as int) as IntType<T>;
else if (this is UInt16)
return new UInt16(this._value + other._value as int) as IntType<T>;
else if (this is Int32)
return new Int32(this._value + other._value as int) as IntType<T>;
else if (this is UInt32)
return new UInt32(this._value + other._value as int) as IntType<T>;
return new IntType(this._value + other._value as int) as IntType<T>;
}
operator -(IntType other) {
this._value -= other._value;
IntType<T> operator -(IntType<T> other) {
if (this is Int8)
return new Int8(this._value - other._value as int) as IntType<T>;
else if (this is UInt8)
return new UInt8(this._value - other._value as int) as IntType<T>;
else if (this is Int16)
return new Int16(this._value - other._value as int) as IntType<T>;
else if (this is UInt16)
return new UInt16(this._value - other._value as int) as IntType<T>;
else if (this is Int32)
return new Int32(this._value - other._value as int) as IntType<T>;
else if (this is UInt32)
return new UInt32(this._value - other._value as int) as IntType<T>;
return new IntType(this._value - other._value as int) as IntType<T>;
}
int toInt() => _value;
T toNum() => _value;
@override
String toString() => _value.toString();
@@ -44,26 +73,55 @@ class IntType {
int get hashCode => _value.hashCode;
}
class Int32 extends IntType {
class Int32 extends IntType<int> {
Int32(int value) : super(value);
}
class Int16 extends IntType {
class Int16 extends IntType<int> {
Int16(int value) : super(value);
}
class Int8 extends IntType {
class Int8 extends IntType<int> {
Int8(int value) : super(value);
}
class UInt32 extends IntType {
class UInt32 extends IntType<int> {
UInt32(int value) : super(value);
}
class UInt16 extends IntType {
class UInt16 extends IntType<int> {
UInt16(int value) : super(value);
}
class UInt8 extends IntType {
class UInt8 extends IntType<int> {
UInt8(int value) : super(value);
}
class Float32 extends IntType<double> {
Float32(double value) : super(value);
}
extension IntTypeCasting on int {
T cast<T>() {
switch(T){
case Int8: return Int8(this) as T;
case UInt8: return UInt8(this) as T;
case Int16: return Int16(this) as T;
case UInt16: return UInt16(this) as T;
case Int32: return Int32(this) as T;
case UInt32: return UInt32(this) as T;
}
return IntType(this) as T;
}
}
extension Float32Casting on double {
T cast<T>() {
if (T == Float32)
return Float32(this) as T;
return IntType(this) as T;
}
}

View File

@@ -1,3 +1,5 @@
import 'package:esiur/src/Data/IntType.dart';
import 'IEnum.dart';
import '../Resource/Template/TemplateType.dart';
import 'IRecord.dart';
@@ -135,15 +137,15 @@ class RepresentationType {
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.UInt8: [UInt8, getNullableType<UInt8>()],
RepresentationTypeIdentifier.Int8: [Int8, getNullableType<Int8>()],
RepresentationTypeIdentifier.Int16: [Int16, getNullableType<Int16>()],
RepresentationTypeIdentifier.UInt16: [UInt16, getNullableType<UInt16>()],
RepresentationTypeIdentifier.Int32: [Int32, getNullableType<Int32>()],
RepresentationTypeIdentifier.UInt32: [UInt32, getNullableType<UInt32>()],
RepresentationTypeIdentifier.Int64: [int, getNullableType<int>()],
RepresentationTypeIdentifier.UInt64: [int, getNullableType<int>()],
RepresentationTypeIdentifier.Float32: [double, getNullableType<double>()],
RepresentationTypeIdentifier.Float32: [Float32, getNullableType<Float32>()],
RepresentationTypeIdentifier.Float64: [double, getNullableType<double>()],
RepresentationTypeIdentifier.Decimal: [double, getNullableType<double>()],
RepresentationTypeIdentifier.String: [String, getNullableType<String>()],