Changeset 307


Ignore:
Timestamp:
Jan 3, 2012, 10:36:55 AM (13 years ago)
Author:
chronos
Message:
  • Modified: Assign methods of TStreamHelper, TVarBlockSerializer and TVarBlockIndexed.
Location:
CoolStreaming
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • CoolStreaming/UStreamHelper.pas

    r291 r307  
    2323    procedure SetItem(Index: Integer; const AValue: Byte);
    2424  public
     25    procedure Assign(Source: TStreamHelper);
    2526    procedure WriteByte(Data: Byte);
    2627    procedure WriteWord(Data: Word);
     
    281282end;
    282283
     284procedure TStreamHelper.Assign(Source: TStreamHelper);
     285var
     286  OldPosition: Integer;
     287begin
     288  OldPosition := Source.Position;
     289  Clear;
     290  WriteStream(Source, Source.Size);
     291  Source.Position := OldPosition;
     292  Position := OldPosition;
     293end;
     294
    283295procedure TStreamHelper.WriteAnsiString(Data: string);
    284296var
  • CoolStreaming/UVarBlockSerializer.pas

    r303 r307  
    5656    procedure BlockEnclose;
    5757    procedure BlockUnclose;
     58    procedure Assign(Source: TVarBlockSerializer);
    5859    constructor Create;
    5960    destructor Destroy; override;
    60     procedure Assign(Source: TVarBlockSerializer);
    6161    property Stream: TStream read FStream write SetStream;
    6262  end;
     
    7070    Enclose: Boolean;
    7171    procedure CheckItem(Index: Integer);
     72    procedure Assign(Source: TVarBlockIndexed);
    7273
    7374    // Base
     
    101102    constructor Create;
    102103    destructor Destroy; override;
    103     procedure Assign(Source: TVarBlockIndexed);
    104104  end;
    105105
     
    568568end;
    569569
     570procedure TVarBlockSerializer.Assign(Source: TVarBlockSerializer);
     571var
     572  OldPos: Integer;
     573begin
     574  OwnsStream := Source.OwnsStream;
     575  FStream.Size := 0;
     576  OldPos := Source.FStream.Position;
     577  FStream.CopyFrom(Source.FStream, Source.FStream.Size);
     578  Source.FStream.Position := OldPos;
     579  FStream.Position := OldPos;
     580end;
     581
    570582constructor TVarBlockSerializer.Create;
    571583begin
     
    582594  end;
    583595  inherited Destroy;
    584 end;
    585 
    586 procedure TVarBlockSerializer.Assign(Source: TVarBlockSerializer);
    587 var
    588   Helper: TStreamHelper;
    589   LastPos: Integer;
    590 begin
    591   OwnsStream := Source.OwnsStream;
    592   FStream.Size := 0;
    593   try
    594     Helper := TStreamHelper.Create(Source.FStream);
    595     LastPos := Source.FStream.Position;
    596     Source.FStream.Position := 0;
    597     Helper.ReadStream(FStream, Source.FStream.Size);
    598     Source.FStream.Position := LastPos;
    599   finally
    600     Helper.Free;
    601   end;
    602   FStream.Position := Source.FStream.Position;
    603596end;
    604597
     
    617610end;
    618611
     612procedure TVarBlockIndexed.Assign(Source: TVarBlockIndexed);
     613var
     614  I: Integer;
     615begin
     616  Enclose := Source.Enclose;
     617  Items.Count := 0;
     618  Items.Count := Source.Items.Count;
     619  for I := 0 to Items.Count - 1 do begin
     620    Items[I] := TVarBlockSerializer.Create;
     621    TVarBlockSerializer(Items[I]).Assign(TVarBlockSerializer(Source.Items[I]));
     622  end;
     623end;
     624
    619625procedure TVarBlockIndexed.WriteVarUInt(Index:Integer;Value:QWord);
    620626begin
     
    798804  if (Index >= 0) and (Index < Items.Count) then
    799805    Result := Assigned(Items[Index])
    800     else Result := False;
     806    else Result := False
    801807end;
    802808
     
    885891end;
    886892
    887 procedure TVarBlockIndexed.Assign(Source: TVarBlockIndexed);
    888 var
    889   I: Integer;
    890 begin
    891   Enclose := Source.Enclose;
    892   Items.Count := Source.Items.Count;
    893   for I := 0 to Items.Count - 1 do begin
    894     CheckItem(I);
    895     TVarBlockSerializer(Items[I]).Assign(TVarBlockSerializer(Source.Items[I]));
    896   end;
    897 end;
    898 
    899893end.
Note: See TracChangeset for help on using the changeset viewer.