@@ -159,12 +159,8 @@ public function getType(): int
159
159
public function read (Reader $ reader , bool $ named = true ): static
160
160
{
161
161
if ($ named && static ::canBeNamed ()) {
162
- $ nameLength = $ reader ->getDeserializer ()->readStringLengthPrefix ()->getValue ();
163
- $ name = $ reader ->read ($ nameLength );
164
- if (strlen ($ name ) !== $ nameLength ) {
165
- throw new Exception ("Failed to read name of " . static ::class);
166
- }
167
- $ this ->setName ($ name );
162
+ $ name = $ reader ->getDeserializer ()->readString ();
163
+ $ this ->setName ($ name ->getValue ());
168
164
}
169
165
return $ this ->readContent ($ reader );
170
166
}
@@ -180,12 +176,8 @@ public static function readRaw(Reader $reader, TagOptions $options, bool $named
180
176
{
181
177
$ result = "" ;
182
178
if ($ named && static ::canBeNamed ()) {
183
- $ nameLength = $ reader ->getDeserializer ()->readStringLengthPrefix ();
184
- $ name = $ reader ->read ($ nameLength ->getValue ());
185
- if (strlen ($ name ) !== $ nameLength ->getValue ()) {
186
- throw new Exception ("Failed to read name of " . static ::class);
187
- }
188
- $ result .= $ nameLength ->getRawData () . $ name ;
179
+ $ name = $ reader ->getDeserializer ()->readString ();
180
+ $ result .= $ name ->getRawData ();
189
181
}
190
182
$ result .= static ::readContentRaw ($ reader , $ options );
191
183
return $ result ;
@@ -210,8 +202,7 @@ public function writeData(Writer $writer, bool $named = true): static
210
202
if (is_null ($ name )) {
211
203
throw new Exception ("Cannot write named tag, because tag does not have a name value " );
212
204
}
213
- $ serializer ->writeStringLengthPrefix (strlen ($ this ->getName ()));
214
- $ writer ->write ($ this ->getName ());
205
+ $ serializer ->writeString ($ this ->getName ());
215
206
}
216
207
$ this ->writeContent ($ writer );
217
208
$ this ->isBeingSerialized = false ;
0 commit comments