Changeset 9 for branches/ByteArray/Devices/Storage.pas
- Timestamp:
- Aug 6, 2024, 10:31:16 PM (2 months ago)
- Location:
- branches/ByteArray
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ByteArray
-
Property svn:ignore
set to
lib
heaptrclog.trc
ByteArray
ByteArray.dbg
ByteArray.lps
ByteArray.res
-
Property svn:ignore
set to
-
branches/ByteArray/Devices/Storage.pas
r5 r9 4 4 5 5 uses 6 Classes, SysUtils, Device, Channel, BigInt;6 Classes, SysUtils, Device, Channel, Int; 7 7 8 8 type … … 19 19 FFile: TFileStream; 20 20 Position: Integer; 21 function ReadByte(Address: TBigInt): Byte; 22 function Read(Address: TBigInt; Size: TBigIntSize): TBigInt; 23 procedure Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt); 24 function GetAddressCount: Integer; override; 25 procedure SetChannel(Channel: TChannel); override; 21 function ReadByte(Address: TInt): Byte; 22 function ReadData(Size: TIntSize): TInt; 23 function ReadPosition(Size: TIntSize): TInt; 24 function ReadSize(Size: TIntSize): TInt; 25 procedure WriteData(Size: TIntSize; Value: TInt); 26 procedure WritePosition(Size: TIntSize; Value: TInt); 27 procedure WriteSize(Size: TIntSize; Value: TInt); 28 function GetHandlers: THandlers; override; 26 29 constructor Create; 27 30 destructor Destroy; override; … … 56 59 end; 57 60 58 function TStorage.ReadByte(Address: T BigInt): Byte;61 function TStorage.ReadByte(Address: TInt): Byte; 59 62 begin 60 63 Result := 0; … … 63 66 end; 64 67 65 function TStorage.Read(Address: TBigInt; Size: TBigIntSize): TBigInt; 66 var 67 Buffer: array of Byte; 68 function TStorage.ReadData(Size: TIntSize): TInt; 68 69 begin 69 case Integer(Address) of 70 0: begin 71 SetLength(Buffer, Size); 72 FFile.Position := Position; 73 FFile.Read(Buffer[0], Size); 74 Result.SetByteArray(Buffer, Size); 75 Inc(Position, Size); 76 end; 77 1: Result := Position; 78 2: Result := FFile.Size; 79 end; 70 FFile.Position := Position; 71 FFile.Read(Result, Size); 72 Inc(Position, Size); 80 73 end; 81 74 82 procedure TStorage.Write(Address: TBigInt; Size: TBigIntSize; Value: TBigInt); 83 var 84 Buffer: array of Byte; 75 function TStorage.ReadPosition(Size: TIntSize): TInt; 85 76 begin 86 case Integer(Address) of 87 0: begin 88 SetLength(Buffer, Size); 89 Value.GetByteArray(Buffer, Size); 90 FFile.Position := Position; 91 FFile.Write(Buffer[1], Size); 92 Inc(Position, Size); 93 end; 94 1: Position := Value; 95 2: FFile.Size := Value; 96 end; 77 Result := Position; 97 78 end; 98 79 99 function TStorage. GetAddressCount: Integer;80 function TStorage.ReadSize(Size: TIntSize): TInt; 100 81 begin 101 Result := 3;82 Result := FFile.Size; 102 83 end; 103 84 104 procedure TStorage. SetChannel(Channel: TChannel);85 procedure TStorage.WriteData(Size: TIntSize; Value: TInt); 105 86 begin 106 Channel.Read := Read; 107 Channel.Write := Write; 87 FFile.Position := Position; 88 FFile.Write(Value, Size); 89 Inc(Position, Size); 90 end; 91 92 procedure TStorage.WritePosition(Size: TIntSize; Value: TInt); 93 begin 94 Position := Value; 95 end; 96 97 procedure TStorage.WriteSize(Size: TIntSize; Value: TInt); 98 begin 99 FFile.Size := Value; 100 end; 101 function TStorage.GetHandlers: THandlers; 102 begin 103 Result := THandlers.Create; 104 Result.ReadHandlers.Add(ReadData); 105 Result.ReadHandlers.Add(ReadPosition); 106 Result.ReadHandlers.Add(ReadSize); 107 Result.WriteHandlers.Add(WriteData); 108 Result.WriteHandlers.Add(WritePosition); 109 Result.WriteHandlers.Add(WriteSize); 108 110 end; 109 111
Note:
See TracChangeset
for help on using the changeset viewer.