Changeset 384 for CoolStreaming


Ignore:
Timestamp:
Jul 9, 2012, 3:58:43 PM (12 years ago)
Author:
chronos
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • CoolStreaming/UVarBlockSerializer.pas

    r341 r384  
    4040    function GetVarSize: Integer;
    4141    function GetVarCount: Integer;
     42    function TryVarBlock: Boolean;
    4243
    4344    // Advanced data types
     
    450451end;
    451452
     453function TVarBlockSerializer.TryVarBlock: Boolean;
     454var
     455  Data: Byte;
     456  StoredPosition: Integer;
     457  Count: Integer;
     458begin
     459  if Stream.Position < Stream.Size then
     460  try
     461    StoredPosition := Stream.Position;
     462    Data := Stream.ReadByte;
     463    if Data = $ff then begin
     464      if TryVarBlock then begin
     465        Count := ReadVarUInt;
     466        Result := Count <= Stream.Size - Stream.Position;
     467      end else Result := False;
     468    end else begin
     469      Count := DecodeUnaryLength(Data) - 1;
     470      Result := Count <= Stream.Size - Stream.Position;
     471    end;
     472    Stream.Position := StoredPosition;
     473  except
     474    raise Exception.Create(SErrorGetVarSize);
     475  end else Result := False;
     476end;
     477
    452478procedure TVarBlockSerializer.WriteVarSInt(Value: Int64);
    453479begin
Note: See TracChangeset for help on using the changeset viewer.