@@ -49,21 +49,20 @@ public function __construct(string $buffer = '')
4949 }
5050
5151 /**
52- * Returns number of bytes in buffer.
52+ * @param string|self $value
5353 *
54- * @return int
54+ * @return self
5555 */
56- public function size ( ): int
56+ public function append ( $ value ): self
5757 {
58- return $ this ->size ;
59- }
58+ if ($ value instanceof Binary) {
59+ $ value = $ value ->data ;
60+ }
6061
61- /**
62- * @return boolean
63- */
64- public function empty (): bool
65- {
66- return $ this ->size === 0 ;
62+ $ this ->data .= $ value ;
63+ $ this ->size += \strlen ($ value );
64+
65+ return $ this ;
6766 }
6867
6968 /**
@@ -108,19 +107,6 @@ public function consume(int $n): string
108107 return $ buffer ;
109108 }
110109 }
111-
112- /**
113- * @return string
114- */
115- public function flush (): string
116- {
117- $ data = $ this ->data ;
118-
119- $ this ->data = '' ;
120- $ this ->size = 0 ;
121-
122- return $ data ;
123- }
124110
125111 /**
126112 * @param int $n
@@ -147,25 +133,25 @@ public function discard(int $n): self
147133 /**
148134 * @param int $n
149135 *
150- * @return self
136+ * @return static
151137 */
152138 public function slice (int $ n ): self
153139 {
154140 if ($ this ->size < $ n ) {
155141 throw new Exception \BufferUnderflow ;
156142 } elseif ($ this ->size === $ n ) {
157- return new self ($ this ->data );
143+ return new static ($ this ->data );
158144 } else {
159- return new self (\substr ($ this ->data , 0 , $ n ));
145+ return new static (\substr ($ this ->data , 0 , $ n ));
160146 }
161147 }
162148
163149 /**
164150 * @param int $n
165151 *
166- * @return self
152+ * @return static
167153 */
168- public function consumeSlice (int $ n ): self
154+ public function shift (int $ n ): self
169155 {
170156 if ($ this ->size < $ n ) {
171157 throw new Exception \BufferUnderflow ;
@@ -175,35 +161,45 @@ public function consumeSlice(int $n): self
175161 $ this ->data = '' ;
176162 $ this ->size = 0 ;
177163
178- return new self ($ buffer );
164+ return new static ($ buffer );
179165
180166 } else {
181167 $ buffer = \substr ($ this ->data , 0 , $ n );
182168
183169 $ this ->data = \substr ($ this ->data , $ n );
184170 $ this ->size -= $ n ;
185171
186- return new self ($ buffer );
172+ return new static ($ buffer );
187173 }
188174 }
189175
190176 /**
191- * Appends bytes at the end of the buffer.
192- *
193- * @param string|self $value
194- *
195- * @return self
177+ * @return string
196178 */
197- public function append ( $ value ): self
179+ public function flush ( ): string
198180 {
199- if ($ value instanceof Binary) {
200- $ value = $ value ->data ;
201- }
181+ $ data = $ this ->data ;
202182
203- $ this ->data .= $ value ;
204- $ this ->size += \strlen ( $ value ) ;
183+ $ this ->data = '' ;
184+ $ this ->size = 0 ;
205185
206- return $ this ;
186+ return $ data ;
187+ }
188+
189+ /**
190+ * @return int
191+ */
192+ public function size (): int
193+ {
194+ return $ this ->size ;
195+ }
196+
197+ /**
198+ * @return boolean
199+ */
200+ public function empty (): bool
201+ {
202+ return $ this ->size === 0 ;
207203 }
208204
209205 /**
0 commit comments