mirror of
https://github.com/esiur/esiur-dart.git
synced 2026-04-04 02:08:21 +00:00
Guid to UUID
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
// import '../../Data/ParseResult.dart';
|
||||
|
||||
// import '../../Data/DataType.dart';
|
||||
// import '../../Data/Guid.dart';
|
||||
// import '../../Data/UUID.dart';
|
||||
// import '../../Data/DC.dart';
|
||||
// import '../../Data/BinaryList.dart';
|
||||
// import 'TypeTemplate.dart';
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
// class TemplateDataType {
|
||||
// late int type;
|
||||
// TypeTemplate? get typeTemplate => typeGuid == null
|
||||
// TypeTemplate? get typeTemplate => typeUUID == null
|
||||
// ? null
|
||||
// : Warehouse.getTemplateByClassId(typeGuid as Guid);
|
||||
// : Warehouse.getTemplateByClassId(typeUUID as UUID);
|
||||
|
||||
// Guid? typeGuid;
|
||||
// UUID? typeUUID;
|
||||
|
||||
// // @TODO: implement fromType
|
||||
// TemplateDataType.fromType(type, bool isArray) {
|
||||
@@ -67,7 +67,7 @@
|
||||
// var template = Warehouse.getTemplateByType(type);
|
||||
|
||||
// if (template != null) {
|
||||
// typeGuid = template.classId;
|
||||
// typeUUID = template.classId;
|
||||
// dt = template.type == TemplateType.Resource
|
||||
// ? DataType.Resource
|
||||
// : DataType.Record;
|
||||
@@ -78,9 +78,9 @@
|
||||
// // try {
|
||||
// // var ins = Warehouse.createInstance(type);
|
||||
// // if (ins is IResource) {
|
||||
// // typeGuid = TypeTemplate.getTypeGuid(ins.template.nameSpace);
|
||||
// // typeUUID = TypeTemplate.getTypeUUID(ins.template.nameSpace);
|
||||
// // } else if (ins is IRecord) {
|
||||
// // typeGuid = TypeTemplate.getTypeGuid(ins.template.nameSpace);
|
||||
// // typeUUID = TypeTemplate.getTypeUUID(ins.template.nameSpace);
|
||||
// // } else {
|
||||
// // dt = DataType.Void;
|
||||
// // }
|
||||
@@ -101,13 +101,13 @@
|
||||
// type == DataType.RecordArray) {
|
||||
// return (BinaryList()
|
||||
// ..addUint8(type)
|
||||
// ..addDC((typeGuid as Guid).value))
|
||||
// ..addDC((typeUUID as UUID).value))
|
||||
// .toDC();
|
||||
// } else
|
||||
// return DC.fromList([type]);
|
||||
// }
|
||||
|
||||
// TemplateDataType(this.type, this.typeGuid);
|
||||
// TemplateDataType(this.type, this.typeUUID);
|
||||
|
||||
// static ParseResult<TemplateDataType> parse(DC data, int offset) {
|
||||
// var type = data[offset++];
|
||||
@@ -115,9 +115,9 @@
|
||||
// type == DataType.ResourceArray ||
|
||||
// type == DataType.Record ||
|
||||
// type == DataType.RecordArray) {
|
||||
// var guid = data.getGuid(offset);
|
||||
// var uuid = data.getUUID(offset);
|
||||
// return ParseResult<TemplateDataType>(
|
||||
// 17, new TemplateDataType(type, guid));
|
||||
// 17, new TemplateDataType(type, uuid));
|
||||
// } else
|
||||
// return ParseResult<TemplateDataType>(1, new TemplateDataType(type, null));
|
||||
// }
|
||||
|
||||
@@ -13,7 +13,7 @@ import '../Warehouse.dart';
|
||||
import './TemplateDescriber.dart';
|
||||
|
||||
import './MemberTemplate.dart';
|
||||
import '../../Data/Guid.dart';
|
||||
import '../../Data/UUID.dart';
|
||||
import '../../Data/DC.dart';
|
||||
import './EventTemplate.dart';
|
||||
import './PropertyTemplate.dart';
|
||||
@@ -27,8 +27,8 @@ class TypeTemplate {
|
||||
|
||||
bool get isWrapper => _isWrapper;
|
||||
|
||||
late Guid _classId;
|
||||
Guid? _parentId = null;
|
||||
late UUID _classId;
|
||||
UUID? _parentId = null;
|
||||
|
||||
String? _annotation;
|
||||
|
||||
@@ -52,7 +52,7 @@ class TypeTemplate {
|
||||
|
||||
TemplateType get type => _templateType;
|
||||
|
||||
Guid? get parentId => _parentId;
|
||||
UUID? get parentId => _parentId;
|
||||
|
||||
Type? _definedType;
|
||||
|
||||
@@ -104,13 +104,15 @@ class TypeTemplate {
|
||||
return null;
|
||||
}
|
||||
|
||||
static Guid getTypeGuid(String typeName) {
|
||||
static UUID getTypeUUID(String typeName) {
|
||||
var tn = DC.stringToBytes(typeName);
|
||||
var hash = SHA256.compute(tn).clip(0, 16);
|
||||
return new Guid(hash);
|
||||
hash.setUint8(6, (hash.getUint8(6) & 0xF) | 0x80);
|
||||
hash.setUint8(8, (hash.getUint8(8) & 0xF) | 0x80);
|
||||
return new UUID(hash);
|
||||
}
|
||||
|
||||
Guid get classId => _classId;
|
||||
UUID get classId => _classId;
|
||||
|
||||
String get className => _className;
|
||||
|
||||
@@ -154,8 +156,8 @@ class TypeTemplate {
|
||||
|
||||
_className = describer.nameSpace;
|
||||
|
||||
// set guid
|
||||
_classId = getTypeGuid(_className);
|
||||
// set UUID
|
||||
_classId = getTypeUUID(_className);
|
||||
|
||||
_version = describer.version;
|
||||
|
||||
@@ -264,7 +266,7 @@ class TypeTemplate {
|
||||
// bake it binarily
|
||||
var b = BinaryList()
|
||||
..addUint8((_annotation != null ? 0x40 : 0x0) | _templateType.index)
|
||||
..addGuid(classId)
|
||||
..addUUID(classId)
|
||||
..addUint8(className.length)
|
||||
..addString(className);
|
||||
|
||||
@@ -304,13 +306,13 @@ class TypeTemplate {
|
||||
|
||||
_templateType = TemplateType.values[data.getUint8(offset++) & 0xF];
|
||||
|
||||
_classId = data.getGuid(offset);
|
||||
_classId = data.getUUID(offset);
|
||||
offset += 16;
|
||||
_className = data.getString(offset + 1, data[offset]);
|
||||
offset += data[offset] + 1;
|
||||
|
||||
if (hasParent) {
|
||||
_parentId = data.getGuid(offset);
|
||||
_parentId = data.getUUID(offset);
|
||||
offset += 16;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import '../Data/AutoList.dart';
|
||||
import 'FactoryEntry.dart';
|
||||
import 'Template/TemplateType.dart';
|
||||
import 'Template/TypeTemplate.dart';
|
||||
import '../Data/Guid.dart';
|
||||
import '../Data/UUID.dart';
|
||||
import '../Data/KeyList.dart';
|
||||
import '../Security/Permissions/IPermissionsManager.dart';
|
||||
import 'IResource.dart';
|
||||
@@ -59,15 +59,15 @@ class Warehouse {
|
||||
new Map<int, WeakReference<IResource>>();
|
||||
static int resourceCounter = 0;
|
||||
|
||||
static KeyList<TemplateType, KeyList<Guid, TypeTemplate>> _templates =
|
||||
static KeyList<TemplateType, KeyList<UUID, TypeTemplate>> _templates =
|
||||
_initTemplates(); //
|
||||
|
||||
static KeyList<TemplateType, KeyList<Guid, TypeTemplate>> _initTemplates() {
|
||||
var rt = new KeyList<TemplateType, KeyList<Guid, TypeTemplate>>();
|
||||
static KeyList<TemplateType, KeyList<UUID, TypeTemplate>> _initTemplates() {
|
||||
var rt = new KeyList<TemplateType, KeyList<UUID, TypeTemplate>>();
|
||||
|
||||
rt.add(TemplateType.Resource, new KeyList<Guid, TypeTemplate>());
|
||||
rt.add(TemplateType.Record, new KeyList<Guid, TypeTemplate>());
|
||||
rt.add(TemplateType.Enum, new KeyList<Guid, TypeTemplate>());
|
||||
rt.add(TemplateType.Resource, new KeyList<UUID, TypeTemplate>());
|
||||
rt.add(TemplateType.Record, new KeyList<UUID, TypeTemplate>());
|
||||
rt.add(TemplateType.Enum, new KeyList<UUID, TypeTemplate>());
|
||||
|
||||
return rt;
|
||||
}
|
||||
@@ -593,7 +593,7 @@ class Warehouse {
|
||||
/// </summary>
|
||||
/// <param name="classId">Class Id.</param>
|
||||
/// <returns>Resource template.</returns>
|
||||
static TypeTemplate? getTemplateByClassId(Guid classId,
|
||||
static TypeTemplate? getTemplateByClassId(UUID classId,
|
||||
[TemplateType? templateType = null]) {
|
||||
if (templateType == null) {
|
||||
// look into resources
|
||||
|
||||
Reference in New Issue
Block a user