2
0
mirror of https://github.com/esiur/esiur-dart.git synced 2025-05-06 12:02:57 +00:00
This commit is contained in:
Esiur Project 2022-08-08 21:20:46 +03:00
parent 69f16dae18
commit c9ead2dabd
3 changed files with 25 additions and 19 deletions

View File

@ -70,11 +70,19 @@ class DC with IterableMixin<int> {
} }
DC.fromHex(String hex, [String separator = ' ']) { DC.fromHex(String hex, [String separator = ' ']) {
if (separator == '') {
var list = <int>[];
for (var i = 0; i < hex.length; i += 2)
list.add(int.parse(hex.substring(i, i + 2), radix: 16));
_data = Uint8List.fromList(list);
_dv = ByteData.view(_data.buffer);
} else {
var list = var list =
hex.split(separator).map((e) => int.parse(e, radix: 16)).toList(); hex.split(separator).map((e) => int.parse(e, radix: 16)).toList();
_data = Uint8List.fromList(list); _data = Uint8List.fromList(list);
_dv = ByteData.view(_data.buffer); _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;
@ -83,11 +91,7 @@ class DC with IterableMixin<int> {
Iterator<int> get iterator => _data.iterator; Iterator<int> get iterator => _data.iterator;
static DC hexToBytes(String value) { static DC hexToBytes(String value) {
// convert hex to Uint8Array return DC.fromHex(value, '');
var rt = new DC(value.length ~/ 2);
for (var i = 0; i < rt.length; i++)
rt[i] = int.parse(value.substring(i * 2, 2), radix: 16);
return rt;
} }
static DC boolToBytes(bool value) { static DC boolToBytes(bool value) {
@ -234,9 +238,11 @@ class DC with IterableMixin<int> {
return rt; return rt;
} }
static DC dateTimeArrayToBytes(List<DateTime> value, [Endian endian = Endian.little]) { 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], endian); for (var i = 0; i < value.length; i++)
rt.setDateTime(i * 8, value[i], endian);
return rt; return rt;
} }
@ -596,7 +602,8 @@ class DC with IterableMixin<int> {
} }
} }
void setDateTime(int offset, DateTime value, [Endian endian = Endian.little]) { void setDateTime(int offset, DateTime value,
[Endian endian = Endian.little]) {
// Unix Epoch // Unix Epoch
var ticks = UNIX_EPOCH + (value.millisecondsSinceEpoch * 10000); var ticks = UNIX_EPOCH + (value.millisecondsSinceEpoch * 10000);
this.setUint64(offset, ticks, endian); this.setUint64(offset, ticks, endian);

View File

@ -5,7 +5,7 @@ class Guid {
Guid(this._data) {} Guid(this._data) {}
Guid.fromString(String data) { Guid.parse(String data) {
_data = DC.fromHex(data, ''); _data = DC.fromHex(data, '');
} }

View File

@ -348,11 +348,11 @@ class TemplateGenerator {
var className = _translateClassName(tmp.className); var className = _translateClassName(tmp.className);
if (tmp.type == TemplateType.Resource || if (tmp.type == TemplateType.Resource ||
tmp.type == TemplateType.Wrapper) { tmp.type == TemplateType.Wrapper) {
return "Warehouse.defineType<${className}>(() => ${className}(), RepresentationType(RepresentationTypeIdentifier.TypedResource, false, Guid.fromString('${tmp.classId.toString()}')));\r\n"; return "Warehouse.defineType<${className}>(() => ${className}(), RepresentationType(RepresentationTypeIdentifier.TypedResource, false, Guid.parse('${tmp.classId.toString()}')));\r\n";
} else if (tmp.type == TemplateType.Record) { } else if (tmp.type == TemplateType.Record) {
return "Warehouse.defineType<${className}>(() => ${className}(), RepresentationType(RepresentationTypeIdentifier.TypedRecord, false, Guid.fromString('${tmp.classId.toString()}')));\r\n"; return "Warehouse.defineType<${className}>(() => ${className}(), RepresentationType(RepresentationTypeIdentifier.TypedRecord, false, Guid.parse('${tmp.classId.toString()}')));\r\n";
} else if (tmp.type == TemplateType.Enum) { } else if (tmp.type == TemplateType.Enum) {
return "Warehouse.defineType<${className}>(() => ${className}(), RepresentationType(RepresentationTypeIdentifier.Enum, false, Guid.fromString('${tmp.classId.toString()}')));\r\n"; return "Warehouse.defineType<${className}>(() => ${className}(), RepresentationType(RepresentationTypeIdentifier.Enum, false, Guid.parse('${tmp.classId.toString()}')));\r\n";
} }
}).join("\r\n"); }).join("\r\n");
@ -470,7 +470,7 @@ class TemplateGenerator {
if (f.isStatic) { if (f.isStatic) {
rt.write( rt.write(
"AsyncReply<$rtTypeName> ${f.name}(DistributedConnection connection"); "static AsyncReply<$rtTypeName> ${f.name}(DistributedConnection connection");
if (positionalArgs.length > 0) if (positionalArgs.length > 0)
rt.write( rt.write(
@ -515,7 +515,6 @@ class TemplateGenerator {
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.where((p) => !p.inherited).forEach((p) { template.properties.where((p) => !p.inherited).forEach((p) {