Ignore:
Timestamp:
Jun 24, 2010, 4:18:03 PM (14 years ago)
Author:
george
Message:
  • Opravy a rozšíření funkčností některých tříd
File:
1 edited

Legend:

Unmodified
Added
Removed
  • VarIntSerializer/UVarIntSerializer.pas

    r26 r31  
    1111
    1212uses
    13   Classes, DateUtils, UMemoryStreamEx, Math, Dialogs, SysUtils;
     13  Classes, DateUtils, UMemoryStreamEx, Math, Dialogs, SysUtils, USubStream;
    1414
    1515const
     
    4242
    4343    // Misc methods
    44     function TestMask(Mask, BitIndex: Integer): Boolean;
     44    function TestMask(Mask: QWord; BitIndex: Byte): Boolean;
    4545    procedure ReadItemByMaskIndex(Index: Integer; Data: TVarIntSerializer);
     46    procedure ReadItemRefByMaskIndex(Index: Integer; Data: TSubStream);
    4647    procedure BlockEnclose;
    4748    procedure BlockUnclose;
     
    310311end;
    311312
    312 function TVarIntSerializer.TestMask(Mask, BitIndex: Integer): Boolean;
     313function TVarIntSerializer.TestMask(Mask: QWord; BitIndex: Byte): Boolean;
    313314begin
    314315  Result := ((Mask shr BitIndex) and 1) = 1;
     
    322323begin
    323324  Position := 0;
     325  Data.Size := 0;
    324326  Mask := ReadVarUInt;
    325327  I := 0;
     
    330332  if TestMask(Mask, Index) then
    331333    ReadStream(TStream(Data), GetVarSize);
     334  Data.Position := 0;
     335end;
     336
     337procedure TVarIntSerializer.ReadItemRefByMaskIndex(Index:Integer;Data:TSubStream
     338  );
     339var
     340  Mask: Integer;
     341  I: Integer;
     342begin
     343  Position := 0;
     344  Data.Size := 0;
     345  Mask := ReadVarUInt;
     346  I := 0;
     347  while (Position < Size) and (I < Index) do begin
     348    if TestMask(Mask, I) then Position := Position + GetVarSize;
     349    Inc(I);
     350  end;
     351  if TestMask(Mask, Index) then begin
     352    if TStream(Self) is TSubStream then begin
     353      // Recalculate substream
     354      Data.Source := TSubStream(Self).Source;
     355      Data.SourcePosition := TSubStream(Self).SourcePosition + Position;
     356    end else begin
     357      Data.Source := Self;
     358      Data.SourcePosition := Position;
     359    end;
     360    Data.Size := GetVarSize;
     361  end;
     362  Data.Position := 0;
    332363end;
    333364
Note: See TracChangeset for help on using the changeset viewer.