Ignore:
Timestamp:
Jan 16, 2011, 4:31:02 PM (14 years ago)
Author:
george
Message:
  • Fixed: Bad QWord shifting.
  • Fixed: Reading dynamic value from bit stream.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • CoolStreaming/UDynNumber.pas

    r127 r128  
    1414  TDynamicNumber = class
    1515    Stream: TBitStream;
    16     procedure Write(Value: QWord);
    17     function Read: QWord;
     16    procedure WriteNumber(Value: QWord);
     17    function ReadNumber: QWord;
    1818    constructor Create;
    1919    destructor Destroy; override;
     20  private
     21    function ReadNumber2: QWord;
    2022  end;
    2123
     
    2426{ TDynamicNumber }
    2527
    26 procedure TDynamicNumber.Write(Value: QWord);
     28procedure TDynamicNumber.WriteNumber(Value: QWord);
    2729var
    28   Bit: Byte;
    2930  Length: Integer;
    3031begin
     
    3233  if Length > 1 then begin
    3334    Stream.WriteNumber(1, 1);
    34     Write(Length - 2);
     35    WriteNumber(Length - 2);
    3536  end else Stream.WriteNumber(0, 1);
    3637  if Length > 1 then Length := Length - 1;
     
    3839end;
    3940
    40 function TDynamicNumber.Read: QWord;
     41function TDynamicNumber.ReadNumber: QWord;
    4142var
    4243  Bit: Byte;
    4344  Length: Integer;
    4445begin
     46  Length := 0;
    4547  Bit := Stream.ReadNumber(1);
    4648  if Bit = 0 then Length := 1
    47     else Length := Read + 2;
    48   Result := Stream.ReadNumber(Length);
    49   if Length > 0 then Result := Result or (1 shl Length);
     49    else Length := ReadNumber2 + 2;
     50  if Length > 1 then Result := Stream.ReadNumber(Length - 1)
     51    else Result := Stream.ReadNumber(Length);
     52  if Length > 1 then Result := Result or (QWord(1) shl (Length - 1));
     53end;
     54
     55function TDynamicNumber.ReadNumber2: QWord;
     56var
     57  Bit: Byte;
     58  Length: Integer;
     59begin
     60  Length := 0;
     61  Bit := Stream.ReadNumber(1);
     62  if Bit = 0 then Length := 1
     63    else Length := ReadNumber + 2;
     64  if Length > 1 then Result := Stream.ReadNumber(Length - 1)
     65    else Result := Stream.ReadNumber(Length);
     66  if Length > 1 then Result := Result or (QWord(1) shl (Length - 1));
    5067end;
    5168
Note: See TracChangeset for help on using the changeset viewer.