Changeset 457 for CoolStreaming/UStreamHelper.pas
- Timestamp:
- Nov 28, 2012, 7:49:20 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
CoolStreaming/UStreamHelper.pas
r360 r457 6 6 7 7 uses 8 Classes, DateUtils, syncobjs,SysUtils;8 Classes, DateUtils, SysUtils; 9 9 10 10 type … … 22 22 procedure SetEndianness(const AValue: TEndianness); 23 23 procedure SetItem(Index: Integer; const AValue: Byte); 24 procedure SetStream(AValue: TStream); 24 25 public 25 26 procedure Assign(Source: TStreamHelper); … … 62 63 function Write(const Buffer; Count: Longint): Longint; override; 63 64 property Endianness: TEndianness read FEndianness write SetEndianness; 64 property Stream: TStream read FStream write FStream;65 property Stream: TStream read FStream write SetStream; 65 66 property Items[Index: Integer]: Byte read GetItem write SetItem; default; 67 property OwnStream: Boolean read FOwnStream write FOwnStream; 66 68 end; 67 69 … … 74 76 StringLength: Longint; 75 77 begin 78 StringLength := 0; 76 79 FStream.ReadBuffer(StringLength, SizeOf(StringLength)); 77 80 Result := ReadString(StringLength); … … 103 106 function TStreamHelper.ReadByte: Byte; 104 107 begin 108 Result := 0; 105 109 FStream.ReadBuffer(Result, SizeOf(Byte)); 106 110 end; … … 108 112 function TStreamHelper.ReadCardinal: Cardinal; 109 113 begin 114 Result := 0; 110 115 FStream.ReadBuffer(Result, SizeOf(Cardinal)); 111 116 if SwapData then Result := Swap(Result); … … 114 119 function TStreamHelper.ReadInt64: Int64; 115 120 begin 121 Result := 0; 116 122 FStream.ReadBuffer(Result, SizeOf(Int64)); 117 123 if SwapData then Result := Swap(Result); … … 130 136 Count: Byte; 131 137 begin 138 Count := 0; 132 139 FStream.ReadBuffer(Count, 1); 133 140 Result := ReadString(Count); … … 135 142 136 143 procedure TStreamHelper.ReadStream(AStream: TStream; Count: Integer); 137 var 138 Buffer: array of Byte; 139 begin 140 if Count > 0 then begin 144 //var 145 // Buffer: array of Byte; 146 begin 147 AStream.Position := 0; 148 AStream.CopyFrom(Self, Count); 149 (*if Count > 0 then begin 141 150 SetLength(Buffer, Count); 142 151 FStream.ReadBuffer(Buffer[0], Count); … … 144 153 AStream.Position := 0; 145 154 AStream.Write(Buffer[0], Count); 146 end; 155 end;*) 147 156 end; 148 157 … … 259 268 function TStreamHelper.ReadDouble: Double; 260 269 begin 270 Result := 0; 261 271 FStream.ReadBuffer(Result, SizeOf(Double)); 262 272 end; … … 264 274 function TStreamHelper.ReadSingle: Single; 265 275 begin 276 Result := 0; 266 277 FStream.ReadBuffer(Result, SizeOf(Single)); 267 278 end; … … 285 296 function TStreamHelper.ReadWord: Word; 286 297 begin 298 Result := 0; 287 299 FStream.ReadBuffer(Result, SizeOf(Word)); 288 300 if SwapData then Result := Swap(Result); … … 311 323 end; 312 324 325 procedure TStreamHelper.SetStream(AValue: TStream); 326 begin 327 if FStream = AValue then Exit; 328 if FOwnStream and Assigned(FStream) then FStream.Free; 329 FStream := AValue; 330 FOwnStream := False; 331 end; 332 313 333 procedure TStreamHelper.Assign(Source: TStreamHelper); 314 334 var … … 361 381 362 382 procedure TStreamHelper.WriteStream(AStream: TStream; Count: Integer); 363 var 364 Buffer: array of Byte; 365 begin 366 if Count > AStream.Size then Count := AStream.Size; // Limit max. stream size 383 //var 384 // Buffer: array of Byte; 385 begin 386 AStream.Position := 0; 387 CopyFrom(AStream, Count); 388 (*if Count > AStream.Size then Count := AStream.Size; // Limit max. stream size 367 389 AStream.Position := 0; 368 390 if Count > 0 then begin … … 370 392 AStream.Read(Buffer[0], Count); 371 393 FStream.Write(Buffer[0], Count); 372 end; 394 end;*) 373 395 end; 374 396
Note:
See TracChangeset
for help on using the changeset viewer.