source: branches/php/Base/MemoryStream.php@ 30

Last change on this file since 30 was 16, checked in by george, 15 years ago
  • Změna základního systému generování stránek. Přidány sady obecných knihoven.
File size: 1.5 KB
Line 
1<?php
2
3class MemoryStream
4{
5 var $Data;
6 var $Position;
7
8 function SetSize($Size)
9 {
10 if(strlen($this->Data) > $Size)
11 {
12 $this->Data = substr($this->Data, 0, $Size);
13 if($this->Position > strlen($this->Data))
14 $this->Position = strlen($this->Data);
15 } else
16 if(strlen($this->Data) < $Size)
17 {
18 $this->Data .= str_repeat(' ', $Size - strlen($this->Data));
19 }
20 }
21
22 function Assign($Stream)
23 {
24 $this->Data = $Stream->Data;
25 $this->Position = $Stream->Position;
26 }
27
28 function GetSize()
29 {
30 return(strlen($this->Data));
31 }
32
33 function WriteBlock($Data)
34 {
35 if($this->Position == strlen($this->Data)) $this->Data .= $Data;
36 else
37 for($I = 0; $I < strlen($Data); $I++)
38 {
39 $this->Data[$this->Position] = $Data[$I];
40 $this->Position++;
41 }
42 }
43
44 function WriteUInt8($Data)
45 {
46 $this->Data[$this->Position] = pack('C', $Data);
47 $this->Position++;
48 }
49
50 function ReadUInt8()
51 {
52 $Result = ord($this->Data[$this->Position]);
53 $this->Position++;
54 }
55
56 function WriteUInt16($Data)
57 {
58 $this->WriteUInt8($Data);
59 $this->WriteUInt8($Data >> 8);
60 }
61
62 function ReadUInt16()
63 {
64 return($this->ReadUInt8 + $this->ReadUInt8 << 8);
65 }
66
67 function WriteUInt32($Data)
68 {
69 $this->WriteUInt8($Data);
70 $this->WriteUInt8($Data >> 8);
71 $this->WriteUInt8($Data >> 16);
72 $this->WriteUInt8($Data >> 24);
73 }
74
75 function ReadUInt32()
76 {
77 return($this->ReadUInt8 | ($this->ReadUInt8 << 8) |
78 ($this->ReadUInt8 << 16) | ($this->ReadUInt8 << 24));
79 }
80
81}
82
83
84?>
Note: See TracBrowser for help on using the repository browser.