@@ -72,13 +72,16 @@ public function __construct(int $size, int $dtype)
7272 $ code = file_get_contents (__DIR__ . '/../../libs/buffer.h ' );
7373 self ::$ ffi = FFI ::cdef ($ code );
7474 }
75+
7576 if (!isset (self ::$ typeString [$ dtype ])) {
7677 throw new InvalidArgumentException ("Invalid data type " );
7778 }
79+
7880 $ limitsize = intdiv (self ::MAX_BYTES , self ::$ valueSize [$ dtype ]);
7981 if ($ size >= $ limitsize ) {
8082 throw new InvalidArgumentException ("Data size is too large. " );
8183 }
84+
8285 $ this ->size = $ size ;
8386 $ this ->dtype = $ dtype ;
8487 $ declaration = self ::$ typeString [$ dtype ];
@@ -185,20 +188,25 @@ public function offsetUnset(mixed $offset): void
185188
186189 public function dump (): string
187190 {
188- $ byte = self ::$ valueSize [$ this ->dtype ] * $ this ->size ;
189- if ($ byte === 0 ) return '' ;
190- $ buf = FFI ::new ("char[ $ byte] " );
191- FFI ::memcpy ($ buf , $ this ->data , $ byte );
192- return FFI ::string ($ buf , $ byte );
191+ $ byteSize = self ::$ valueSize [$ this ->dtype ] * $ this ->size ;
192+
193+ if ($ byteSize === 0 ) return '' ;
194+
195+ $ buf = FFI ::new ("char[ $ byteSize] " );
196+ FFI ::memcpy ($ buf , $ this ->data , $ byteSize );
197+
198+ return FFI ::string ($ buf , $ byteSize );
193199 }
194200
195201 public function load (string $ string ): void
196202 {
197- $ byte = self ::$ valueSize [$ this ->dtype ] * $ this ->size ;
203+ $ byteSize = self ::$ valueSize [$ this ->dtype ] * $ this ->size ;
204+
198205 $ strlen = strlen ($ string );
199- if ($ strlen != $ byte ) {
200- throw new InvalidArgumentException ("Unmatched data size. buffer size is $ byte . $ strlen byte given. " );
206+ if ($ strlen != $ byteSize ) {
207+ throw new InvalidArgumentException ("Unmatched data size. buffer size is $ byteSize . $ strlen byte given. " );
201208 }
209+
202210 FFI ::memcpy ($ this ->data , $ string , $ strlen );
203211 }
204212}
0 commit comments