File tree Expand file tree Collapse file tree 3 files changed +19
-9
lines changed
Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Original file line number Diff line number Diff line change 22
33namespace Bolt \PackStream ;
44
5+ use Generator ;
6+
57/**
68 * Interface IPacker
79 *
@@ -14,7 +16,7 @@ interface IPacker
1416 /**
1517 * @param $signature
1618 * @param mixed ...$params
17- * @return string
19+ * @return Generator
1820 */
19- public function pack ($ signature , ...$ params ): string ;
21+ public function pack ($ signature , ...$ params ): Generator ;
2022}
Original file line number Diff line number Diff line change 44
55use Bolt \PackStream \IPacker ;
66use Bolt \error \PackException ;
7+ use Generator ;
78
89/**
910 * Class Packer of PackStream version 1
@@ -23,10 +24,10 @@ class Packer implements IPacker
2324 * Pack message with parameters
2425 * @param $signature
2526 * @param mixed ...$params
26- * @return string
27+ * @return Generator
2728 * @throws PackException
2829 */
29- public function pack ($ signature , ...$ params ): string
30+ public function pack ($ signature , ...$ params ): Generator
3031 {
3132 $ output = '' ;
3233
@@ -49,7 +50,13 @@ public function pack($signature, ...$params): string
4950 }
5051
5152 //structure buffer
52- return pack ('n ' , mb_strlen ($ output , '8bit ' )) . $ output . chr (0x00 ) . chr (0x00 );
53+ $ len = mb_strlen ($ output , 'UTF-8 ' );
54+ for ($ i = 0 ; $ i < $ len ; $ i += 65535 ) {
55+ $ chunk = mb_substr ($ output , $ i , 65535 , '8bit ' );
56+ yield pack ('n ' , mb_strlen ($ chunk , '8bit ' )) . $ chunk ;
57+ }
58+
59+ yield chr (0x00 ) . chr (0x00 );
5360 }
5461
5562 /**
Original file line number Diff line number Diff line change 22
33namespace Bolt \protocol ;
44
5- use Bolt \ Bolt ;
5+ use Generator ;
66use Bolt \PackStream \{IPacker , IUnpacker };
77use Bolt \connection \IConnection ;
88use Exception ;
@@ -72,12 +72,13 @@ public function goodbye(...$args)
7272
7373 /**
7474 * Write to connection
75- * @param string $buffer
75+ * @param Generator $generator
7676 * @throws Exception
7777 */
78- protected function write (string $ buffer )
78+ protected function write (Generator $ generator )
7979 {
80- $ this ->connection ->write ($ buffer );
80+ foreach ($ generator as $ buffer )
81+ $ this ->connection ->write ($ buffer );
8182 }
8283
8384 /**
You can’t perform that action at this time.
0 commit comments