Skip to content

Commit b355ca9

Browse files
committed
fix string serializer
1 parent 75610d5 commit b355ca9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Tools/ChainOperations/OperationSerializer.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,21 @@ public static function serializeType($type, $value, $byteBuffer)
110110

111111
if ($strLength <= 128) {
112112
$byteBuffer->writeInt8($strLength);
113-
} else {
114-
113+
}
114+
elseif ($strLength <= 16511) {
115115
$strLength = ceil($strLength / 128) * 256
116116
+ ($strLength - ceil($strLength / 128) * 128);
117117
$byteBuffer->writeInt16LE($strLength);
118+
} else {
119+
$n3 = ceil($strLength / (128 * 128));
120+
$n2 = ceil(($strLength - $n3*128*128) / 128);
121+
$strLength = $n3 * 256 * 256
122+
+ $n2 * 256
123+
+ ($strLength - $n3 * 128 * 128 - $n2 * 128);
124+
$byteBuffer->writeInt32LE($strLength);
125+
if ($strLength <= 16777215) {
126+
$byteBuffer->setCurrentOffset($byteBuffer->getCurrentOffset() - 1);
127+
}
118128
}
119129
$byteBuffer->writeVStringLE($value);
120130
} if ($type === self::TYPE_SET_STRING) {

0 commit comments

Comments
 (0)