@@ -49,21 +49,20 @@ public function __construct(string $buffer = '')
49
49
}
50
50
51
51
/**
52
- * Returns number of bytes in buffer.
52
+ * @param string|self $value
53
53
*
54
- * @return int
54
+ * @return self
55
55
*/
56
- public function size ( ): int
56
+ public function append ( $ value ): self
57
57
{
58
- return $ this ->size ;
59
- }
58
+ if ($ value instanceof Binary) {
59
+ $ value = $ value ->data ;
60
+ }
60
61
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 ;
67
66
}
68
67
69
68
/**
@@ -108,19 +107,6 @@ public function consume(int $n): string
108
107
return $ buffer ;
109
108
}
110
109
}
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
- }
124
110
125
111
/**
126
112
* @param int $n
@@ -147,25 +133,25 @@ public function discard(int $n): self
147
133
/**
148
134
* @param int $n
149
135
*
150
- * @return self
136
+ * @return static
151
137
*/
152
138
public function slice (int $ n ): self
153
139
{
154
140
if ($ this ->size < $ n ) {
155
141
throw new Exception \BufferUnderflow ;
156
142
} elseif ($ this ->size === $ n ) {
157
- return new self ($ this ->data );
143
+ return new static ($ this ->data );
158
144
} else {
159
- return new self (\substr ($ this ->data , 0 , $ n ));
145
+ return new static (\substr ($ this ->data , 0 , $ n ));
160
146
}
161
147
}
162
148
163
149
/**
164
150
* @param int $n
165
151
*
166
- * @return self
152
+ * @return static
167
153
*/
168
- public function consumeSlice (int $ n ): self
154
+ public function shift (int $ n ): self
169
155
{
170
156
if ($ this ->size < $ n ) {
171
157
throw new Exception \BufferUnderflow ;
@@ -175,35 +161,45 @@ public function consumeSlice(int $n): self
175
161
$ this ->data = '' ;
176
162
$ this ->size = 0 ;
177
163
178
- return new self ($ buffer );
164
+ return new static ($ buffer );
179
165
180
166
} else {
181
167
$ buffer = \substr ($ this ->data , 0 , $ n );
182
168
183
169
$ this ->data = \substr ($ this ->data , $ n );
184
170
$ this ->size -= $ n ;
185
171
186
- return new self ($ buffer );
172
+ return new static ($ buffer );
187
173
}
188
174
}
189
175
190
176
/**
191
- * Appends bytes at the end of the buffer.
192
- *
193
- * @param string|self $value
194
- *
195
- * @return self
177
+ * @return string
196
178
*/
197
- public function append ( $ value ): self
179
+ public function flush ( ): string
198
180
{
199
- if ($ value instanceof Binary) {
200
- $ value = $ value ->data ;
201
- }
181
+ $ data = $ this ->data ;
202
182
203
- $ this ->data .= $ value ;
204
- $ this ->size += \strlen ( $ value ) ;
183
+ $ this ->data = '' ;
184
+ $ this ->size = 0 ;
205
185
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 ;
207
203
}
208
204
209
205
/**
0 commit comments