-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathUAbstractStorage.pas
More file actions
620 lines (554 loc) · 20.1 KB
/
Copy pathUAbstractStorage.pas
File metadata and controls
620 lines (554 loc) · 20.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
unit UAbstractStorage;
{
This file is part of AbstractMem framework
Copyright (C) 2023 Albert Molina - bpascalblockchain@gmail.com
https://github.com/PascalCoinDev/
*** BEGIN LICENSE BLOCK *****
The contents of this files are subject to the Mozilla Public License Version
2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License.
The Initial Developer of the Original Code is Albert Molina.
See ConfigAbstractMem.inc file for more info
***** END LICENSE BLOCK *****
}
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
interface
uses
Classes, SysUtils,
SyncObjs,
UAbstractMem,
UFileMem,
UAbstractMemTList,
UAbstractMemBTree;
{$I ./ConfigAbstractMem.inc }
type
EAbstractStorage = Class(Exception);
TStorageStructType = (
ss_Unknown,
ss_Buffer,
ss_TAbstractMemBTree,
ss_TAbstractMemBTreeData,
ss_TAbstractMemBTreeDataIndex,
ss_TAbstractMemTList,
ss_TAbstractMemTListT,
ss_TAbstractMemOrderedTListT
);
TStorageStructInfo = record
Name : String;
AMPosition : TAbstractMemPosition;
StructType : TStorageStructType;
ClassName : String;
procedure Clear;
function GetInformation(const AAbstractMem : TAbstractMem; out ACount : Integer; out AInfo : String) : Boolean;
end;
TAbstractStorage = Class
public
type
TIsStorage = (is_not_initialized, is_empty, is_initialized, is_not);
TOnInitalizeStorage = procedure(ASender : TAbstractStorage; const ACurrentName, ANewName : String; ACurrentVersion, AUpdateToVersion : Integer) of object;
TStorageStructInformation = Class(TAbstractMemBTreeData<TStorageStructInfo>)
protected
function LoadData(const APosition : TAbstractMemPosition) : TStorageStructInfo; override;
function SaveData(const AData : TStorageStructInfo) : TAMZone; override;
public
procedure AddStorageStruct(const AName : String; AAMPosition : TAbstractMemPosition; AStructType : TStorageStructType; AObject : TObject);
function GetStorageStruct(const AName : String) : TStorageStructInfo;
function GetStorageStructAMZone(const AName : String) : TAMZone;
function HasStorageStruct(const AName : String; out AStorageStruct : TStorageStructInfo) : Boolean;
End;
private
FAbstractMem : TAbstractMem;
FStorageVersion: Integer;
FStorageName: String;
FStorageStructPosition : TAbstractMemPosition;
FStorageStructInformation : TStorageStructInformation;
FIsStorage : TIsStorage;
FIsMyAbstractMem : Boolean;
protected
procedure DoInitialize(AClearContent : Boolean; const ANewStorageName : String; ANewStorageVersion : Integer; AIs64Bits : Boolean; AMemUnitsSize : Integer; AOnInitalizeStorage : TOnInitalizeStorage);
public
Constructor Create(const AFileName : String; AReadOnly : Boolean; const AStorageName : String; const AStorageVersion : Integer; AOnInitalizeStorage : TOnInitalizeStorage); overload;
Constructor Create(const AAbstractMem : TAbstractMem; const AStorageName : String; const AStorageVersion : Integer; AOnInitalizeStorage : TOnInitalizeStorage); overload;
Destructor Destroy; override;
property AbstractMem : TAbstractMem read FAbstractMem;
property StorageName : String read FStorageName;
property StorageVersion : Integer read FStorageVersion;
procedure Init(const AStorageName : String; AStorageVersion : Integer; AIs64Bits : Boolean; AMemUnitsSize : Integer; AOnInitalizeStorage : TOnInitalizeStorage);
property StorageStructInformation : TStorageStructInformation read FStorageStructInformation;
procedure Analize(const AInfo : TStrings);
function IsValidAbstractStorage : Boolean;
End;
TBytesStorage = Class
private
FBytes: TBytes;
FPosition : Integer;
procedure CheckRead(ASize : Integer);
function CanRead(ASize : Integer) : Boolean;
procedure NeedWrite(AAmount : Integer);
public
Constructor Create(ALength : Integer); overload;
Constructor Create(ABytes : TBytes); overload;
Class Function Load(const AAbstractMem : TAbstractMem; const APosition : TAbstractMemPosition) : TBytesStorage;
Class Function ReadFirstData(const AAbstractMem : TAbstractMem) : TBytesStorage;
property Bytes : TBytes read FBytes;
property Position : Integer read FPosition write FPosition;
function Size : Integer;
//
function ReadString : String;
function ReadByte : Byte;
function ReadUInt16 : UInt16;
function ReadUInt32 : UInt32;
function ReadUInt64 : UInt64;
function ReadStringDef(const ADefault : String) : String;
function ReadIntDef(ABytesCount : Integer; ADefault : Int64) : Int64;
function ReadUIntDef(ABytesCount : Integer; ADefault : UInt64) : UInt64;
//
function WriteString(const AValue : String) : TBytesStorage;
function WriteByte(const AValue : Byte) : TBytesStorage;
function WriteUInt16(const AValue : UInt16) : TBytesStorage;
function WriteUInt32(const AValue : UInt32) : TBytesStorage;
function WriteUInt64(const AValue : UInt64) : TBytesStorage;
function Save(const AAbstractMem : TAbstractMem) : TAMZone;
End;
implementation
function TStorageStructInformation_Comparer(const ALeft, ARight: TStorageStructInfo): Integer;
begin
Result := AnsiCompareText(ALeft.Name.Trim,ARight.Name.Trim);
end;
{ TAbstractStorage }
procedure TAbstractStorage.Analize(const AInfo: TStrings);
var s : string;
i : Integer;
ss, ssOld : TStorageStructInfo;
begin
AInfo.BeginUpdate;
try
case FIsStorage of
is_not_initialized: AInfo.Add(Format('(Not initialized)',[]));
is_empty: AInfo.Add(Format('Empty Abstract Storage',[]));
is_initialized: AInfo.Add(Format('Abstract Storage',[]));
is_not: AInfo.Add(Format('Not an AbstractStorage',[]));
end;
if (FIsStorage in [is_not_initialized,is_not]) then exit;
AInfo.Add(Format('%s name:"%s" version:%d',[ClassName,Self.StorageName,Self.StorageVersion]));
if AbstractMem.Is64Bits then s:='64bits' else s:='32bits';
AInfo.Add(Format('AbstractMem %s %d bytes per unit total size %d',[s,AbstractMem.MemUnitsSize,AbstractMem.NextAvailablePos]));
AInfo.Add(Format('StorageStructs: %d',[StorageStructInformation.Count]));
if StorageStructInformation.FindDataLowest(ss) then begin
repeat
if ss.GetInformation(AbstractMem,i,s) then begin
AInfo.Add(Format('StorageStruct: %s class %s count %d %s',[ss.Name,ss.ClassName,i,s]));
end;
ssOld := ss;
until not StorageStructInformation.FindDataSuccessor(ssOld,ss);
end;
finally
AInfo.EndUpdate;
end;
end;
constructor TAbstractStorage.Create(const AFileName : String; AReadOnly : Boolean;
const AStorageName : String; const AStorageVersion : Integer; AOnInitalizeStorage : TOnInitalizeStorage);
begin
FIsMyAbstractMem := True;
FIsStorage := is_not_initialized;
FAbstractMem := Nil;
FStorageVersion := 0;
FStorageName := '';
FStorageStructPosition := 0;
FStorageStructInformation := Nil;
if (AFileName<>'') then begin
FAbstractMem := TFileMem.Create(AFileName,AReadOnly);
end else FAbstractMem := TMem.Create(0,AReadOnly);
DoInitialize(False,AStorageName,AStorageVersion,False,0,AOnInitalizeStorage);
end;
constructor TAbstractStorage.Create(const AAbstractMem: TAbstractMem; const AStorageName : String; const AStorageVersion : Integer; AOnInitalizeStorage : TOnInitalizeStorage);
begin
FIsMyAbstractMem := False;
FIsStorage := is_not_initialized;
FAbstractMem := AAbstractMem;
FStorageVersion := 0;
FStorageName := '';
FStorageStructPosition := 0;
FStorageStructInformation := Nil;
DoInitialize(False,AStorageName,AStorageVersion,False,0,AOnInitalizeStorage);
end;
destructor TAbstractStorage.Destroy;
begin
FStorageStructInformation.Free;
if FIsMyAbstractMem then FAbstractMem.Free;
inherited;
end;
procedure TAbstractStorage.DoInitialize(AClearContent : Boolean; const ANewStorageName : String; ANewStorageVersion : Integer;
AIs64Bits : Boolean; AMemUnitsSize : Integer; AOnInitalizeStorage : TOnInitalizeStorage);
const
CT_HEADER = 'TAbstractStorage';
CT_VERSION = 1;
procedure DoClearContent;
var LfdZone, LssZone : TAMZone;
LBytesStorage : TBytesStorage;
begin
FreeAndNil(FStorageStructInformation);
AbstractMem.ClearContent(AIs64Bits,AMemUnitsSize);
//
LfdZone := AbstractMem.New(Length(CT_HEADER)+Length(ANewStorageName)+50);
LssZone := AbstractMem.New(TStorageStructInformation.MinAbstractMemInitialPositionSize(AbstractMem));
FStorageStructPosition := LssZone.position;
LBytesStorage := TBytesStorage.Create(LfdZone.size);
try
LBytesStorage.WriteString(CT_HEADER).WriteUInt32(CT_VERSION).WriteUInt64(FStorageStructPosition).
WriteString(ANewStorageName).WriteUInt32(ANewStorageVersion);
AbstractMem.Write(LfdZone.position,LBytesStorage.Bytes[0],LBytesStorage.Size);
finally
LBytesStorage.Free;
end;
FStorageStructInformation := TStorageStructInformation.Create(AbstractMem,LssZone,False,7,TStorageStructInformation_Comparer);
FStorageStructInformation.AddStorageStruct(FStorageStructInformation.ClassName,FStorageStructPosition,ss_TAbstractMemBTreeData,FStorageStructInformation);
if Assigned(AOnInitalizeStorage) then begin
AOnInitalizeStorage(Self,'',ANewStorageName,0,ANewStorageVersion);
end;
end;
var LfdZone : TAMZone;
i : Integer;
LBytesStorage : TBytesStorage;
s : String;
begin
if AClearContent then begin
DoClearContent;
end;
//
FreeAndNil(FStorageStructInformation);
//
FIsStorage := is_not_initialized;
LBytesStorage := TBytesStorage.ReadFirstData(AbstractMem);
Try
if LBytesStorage.Size>0 then begin
FIsStorage := is_not;
s := LBytesStorage.ReadStringDef('');
i := LBytesStorage.ReadIntDef(4,0);
FIsStorage := is_not;
if (s=CT_HEADER) and (i = CT_VERSION) then begin
FStorageStructPosition := LBytesStorage.ReadUInt64;
if FAbstractMem.GetUsedZoneInfo(FStorageStructPosition,True,LfdZone) then begin
FStorageName := LBytesStorage.ReadString;
FStorageVersion := LBytesStorage.ReadUInt32;
FStorageStructInformation := TStorageStructInformation.Create(FAbstractMem,LfdZone,False,7,
TStorageStructInformation_Comparer);
FIsStorage := is_initialized;
if Assigned(AOnInitalizeStorage) and (Not AbstractMem.ReadOnly) and (FStorageName=ANewStorageName) and (FStorageVersion<ANewStorageVersion) then begin
AOnInitalizeStorage(Self,FStorageName,ANewStorageName,FStorageVersion,ANewStorageVersion);
end;
end else FStorageStructPosition := 0;
end;
end else begin
FIsStorage := is_empty;
if (Not FAbstractMem.ReadOnly) and (Assigned(AOnInitalizeStorage)) then begin
DoClearContent;
FIsStorage := is_initialized;
end;
end;
Finally
LBytesStorage.Free;
End;
end;
procedure TAbstractStorage.Init(const AStorageName: String;
AStorageVersion: Integer; AIs64Bits : Boolean; AMemUnitsSize : Integer; AOnInitalizeStorage : TOnInitalizeStorage);
begin
DoInitialize(True,AStorageName,AStorageVersion,AIs64Bits,AMemUnitsSize,AOnInitalizeStorage);
end;
function TAbstractStorage.IsValidAbstractStorage: Boolean;
begin
Result := FIsStorage in [is_empty,is_initialized];
end;
{ TAbstractStorage.TStorageStructInformation }
procedure TAbstractStorage.TStorageStructInformation.AddStorageStruct(
const AName: String; AAMPosition: TAbstractMemPosition;
AStructType: TStorageStructType; AObject : TObject);
var ss : TStorageStructInfo;
begin
ss.Clear;
ss.Name := AName;
ss.AMPosition := AAMPosition;
ss.StructType := AStructType;
if Assigned(AObject) then ss.ClassName := AObject.ClassName;
if not Self.AddData(ss) then raise EAbstractStorage.Create(Format('Cannot add StorageStruct "%s"',[AName]));
end;
function TAbstractStorage.TStorageStructInformation.GetStorageStruct(
const AName: String): TStorageStructInfo;
begin
if not HasStorageStruct(AName,Result) then raise EAbstractStorage.Create(Format('Cannot find storage struct "%s"',[AName]));
end;
function TAbstractStorage.TStorageStructInformation.GetStorageStructAMZone(
const AName: String): TAMZone;
var ss : TStorageStructInfo;
begin
ss := GetStorageStruct(AName);
if not Self.AbstractMem.GetUsedZoneInfo(ss.AMPosition,True,Result) then raise EAbstractStorage.Create(Format('Cannot find AMZone for %s',[AName]));
end;
function TAbstractStorage.TStorageStructInformation.HasStorageStruct(
const AName: String; out AStorageStruct: TStorageStructInfo): Boolean;
var ss : TStorageStructInfo;
begin
ss.Clear;
ss.Name := AName;
Result := FindData(ss,AStorageStruct);
end;
function TAbstractStorage.TStorageStructInformation.LoadData(
const APosition: TAbstractMemPosition): TStorageStructInfo;
var LBytesStorage : TBytesStorage;
begin
Result.Clear;
LBytesStorage := TBytesStorage.Load(AbstractMem,APosition);
Try
Result.Name := LBytesStorage.ReadString;
Result.AMPosition := LBytesStorage.ReadUInt64;
Result.StructType := TStorageStructType(LBytesStorage.ReadByte);
Result.ClassName := LBytesStorage.ReadString;
Finally
LBytesStorage.Free;
End;
end;
function TAbstractStorage.TStorageStructInformation.SaveData(
const AData: TStorageStructInfo): TAMZone;
var LBytesStorage : TBytesStorage;
begin
LBytesStorage := TBytesStorage.Create(0);
try
LBytesStorage.WriteString(AData.Name);
LBytesStorage.WriteUInt64(AData.AMPosition);
LBytesStorage.WriteByte(Byte(AData.StructType));
LBytesStorage.WriteString(AData.ClassName);
Result := LBytesStorage.Save(AbstractMem);
finally
LBytesStorage.Free;
end;
end;
{ TStorageStructInfo }
procedure TStorageStructInfo.Clear;
begin
Self.Name := '';
Self.AMPosition := 0;
Self.StructType := ss_Unknown;
Self.ClassName := '';
end;
function TStorageStructInfo.GetInformation(const AAbstractMem: TAbstractMem;
out ACount: Integer; out AInfo : String): Boolean;
var amz : TAMZone;
obj : TObject;
allowduplicates : boolean;
order : Integer;
begin
Result := False;
ACount := 0;
AInfo := '';
if not AAbstractMem.GetUsedZoneInfo(self.AMPosition,true,amz) then Exit;
case Self.StructType of
ss_Buffer: begin
ACount := amz.size;
Result := True;
end;
ss_TAbstractMemBTree, ss_TAbstractMemBTreeData, ss_TAbstractMemBTreeDataIndex : begin
if TAbstractMemBTree.GetInfo(AAbstractMem,amz,allowduplicates,order,ACount) then begin
AInfo := Format('Order %d',[order]);
if allowduplicates then AInfo := AInfo + ' with duplicates' else AInfo := AInfo + ' without duplicates';
Result := True;
end;
end;
ss_TAbstractMemTList: begin
obj := TAbstractMemTList.Create(AAbstractMem,amz,3,false);
try
ACount := TAbstractMemTList(obj).Count;
Result := True;
finally
obj.Free;
end;
end;
ss_TAbstractMemTListT, ss_TAbstractMemOrderedTListT: begin
obj := TAbstractMemTListBaseAbstract<Integer>.Create(AAbstractMem,amz,3,false);
try
ACount := TAbstractMemTListBaseAbstract<Integer>(obj).Count;
Result := True;
finally
obj.Free;
end;
end
end;
end;
{ TBytesStorage }
function TBytesStorage.CanRead(ASize: Integer): Boolean;
begin
Result := (ASize>=0) and ((FPosition + ASize)<Length(FBytes));
end;
procedure TBytesStorage.CheckRead(ASize: Integer);
begin
if (ASize<=0) or ((FPosition + ASize)>Length(FBytes)) then raise EAbstractStorage.Create(Format('Canot %s.Read %d bytes (pos %d/%d)',[Self.ClassName,ASize,FPosition,Length(FBytes)]));
end;
constructor TBytesStorage.Create(ABytes: TBytes);
begin
SetLength(FBytes,Length(ABytes));
FPosition := 0;
Move(ABytes[0],FBytes[0],Length(ABytes));
end;
constructor TBytesStorage.Create(ALength : Integer);
begin
if ALength<0 then ALength := 0;
SetLength(FBytes,ALength);
FPosition := 0;
end;
class function TBytesStorage.Load(const AAbstractMem: TAbstractMem;
const APosition: TAbstractMemPosition): TBytesStorage;
var LZone : TAMZone;
begin
if Not AAbstractMem.GetUsedZoneInfo( APosition, False, LZone) then
raise EAbstractStorage.Create(Format('%s.Load Inconsistency error used zone info not found at pos %d',[Self.ClassName,APosition]));
Result := TBytesStorage.Create(LZone.size);
Try
if AAbstractMem.Read(LZone.position, Result.FBytes[0], LZone.size )<>LZone.size then
raise EAbstractStorage.Create(Format('%s.Load Inconsistency error cannot read %d bytes at pos %d',[Self.ClassName,LZone.size,APosition]));
Except
Result.Free;
Raise;
End;
end;
procedure TBytesStorage.NeedWrite(AAmount: Integer);
begin
if FPosition+AAmount > Length(FBytes) then begin
SetLength(FBytes,FPosition+AAmount);
end;
end;
function TBytesStorage.ReadByte: Byte;
begin
Result := 0;
CheckRead(1);
Move(FBytes[FPosition],Result,1);
inc(FPosition,1);
end;
class function TBytesStorage.ReadFirstData(
const AAbstractMem: TAbstractMem): TBytesStorage;
var LfdZone : TAMZone;
begin
Result := TBytesStorage.Create(0);
if not AAbstractMem.ReadFirstData(LfdZone,Result.FBytes) then Exit;
end;
function TBytesStorage.ReadIntDef(ABytesCount: Integer;
ADefault: Int64): Int64;
begin
if CanRead(ABytesCount) then begin
Result := 0;
Move(FBytes[FPosition],Result,ABytesCount);
inc(FPosition,ABytesCount);
end else Result := ADefault;
end;
function TBytesStorage.ReadString: String;
var LPos : Integer;
l : Integer;
begin
LPos := FPosition;
try
l := ReadUInt16;
if (l<0) then raise EAbstractStorage.Create(Format('%s.ReadString Invalid Length %d for String',[Self.ClassName, l]));
if (l>0) then begin
CheckRead(l);
Result := TEncoding.ANSI.GetString(FBytes,FPosition,l);
inc(FPosition,l);
end;
Except
FPosition := LPos;
Raise;
end;
end;
function TBytesStorage.ReadStringDef(const ADefault: String): String;
var LPos : Integer;
l : Int64;
begin
LPos := FPosition;
l := Integer(ReadIntDef(2,-1));
if (l<0) or (Not CanRead(l)) then begin
Result := ADefault;
FPosition := LPos;
end else begin
Result := TEncoding.ANSI.GetString(FBytes,FPosition,Integer(l));
inc(FPosition,Integer(l));
end;
end;
function TBytesStorage.ReadUInt16: UInt16;
begin
Result := 0;
CheckRead(2);
Move(FBytes[FPosition],Result,2);
inc(FPosition,2);
end;
function TBytesStorage.ReadUInt32: UInt32;
begin
Result := 0;
CheckRead(4);
Move(FBytes[FPosition],Result,4);
inc(FPosition,4);
end;
function TBytesStorage.Save(const AAbstractMem: TAbstractMem): TAMZone;
begin
Result := AAbstractMem.New(Self.Size);
AAbstractMem.Write(Result.position,Self.FBytes[0],Self.Size);
end;
function TBytesStorage.Size: Integer;
begin
Result := Length(FBytes);
end;
function TBytesStorage.ReadUInt64: UInt64;
begin
Result := 0;
CheckRead(8);
Move(FBytes[FPosition],Result,8);
inc(FPosition,8);
end;
function TBytesStorage.ReadUIntDef(ABytesCount: Integer;
ADefault: UInt64): UInt64;
begin
Result := ReadIntDef(ABytesCount,ADefault);
end;
function TBytesStorage.WriteByte(const AValue: Byte) : TBytesStorage;
begin
NeedWrite(1);
Move(AValue,FBytes[FPosition],1);
inc(FPosition,1);
Result := Self;
end;
function TBytesStorage.WriteString(const AValue: String) : TBytesStorage;
var Lb : TBytes;
begin
WriteUInt16(AValue.Length);
if Length(AValue)>0 then begin
NeedWrite(Length(AValue));
Lb := TEncoding.ANSI.GetBytes(AValue);
Move(Lb[0],FBytes[FPosition],Length(AValue));
inc(FPosition,Length(AValue));
end;
Result := Self;
end;
function TBytesStorage.WriteUInt16(const AValue: UInt16) : TBytesStorage;
begin
NeedWrite(2);
Move(AValue,FBytes[FPosition],2);
inc(FPosition,2);
Result := Self;
end;
function TBytesStorage.WriteUInt32(const AValue: UInt32) : TBytesStorage;
begin
NeedWrite(4);
Move(AValue,FBytes[FPosition],4);
inc(FPosition,4);
Result := Self;
end;
function TBytesStorage.WriteUInt64(const AValue: UInt64) : TBytesStorage;
begin
NeedWrite(8);
Move(AValue,FBytes[FPosition],8);
inc(FPosition,8);
Result := Self;
end;
end.