Skip to content

Commit

Permalink
Remove rewind, prefer set*Offset(0)
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Jan 30, 2024
1 parent 2144b99 commit 688806d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 26 deletions.
10 changes: 0 additions & 10 deletions encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,16 +544,6 @@ BYTE_BUFFER_METHOD(trim) {
}
}

BYTE_BUFFER_METHOD(rewind) {
zend_parse_parameters_none_throw();

auto object = BYTE_BUFFER_THIS();

//TODO: doubtful that rewinding both offsets at the same time is desirable
object->read_offset = 0;
object->write_offset = 0;
}

BYTE_BUFFER_METHOD(__serialize) {
zend_parse_parameters_none_throw();

Expand Down
5 changes: 0 additions & 5 deletions stubs/BaseByteBuffer.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ public function reserve(int $length) : void{}
*/
public function trim() : void{}

/**
* Sets the internal offset to the start of the buffer.
*/
public function rewind() : void{}

public function __serialize() : array{}

public function __unserialize(array $data) : void{}
Expand Down
6 changes: 1 addition & 5 deletions stubs/BaseByteBuffer_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: b482ada5edda8bb0c36f609f5ce7c994c910ff85 */
* Stub hash: 7cd1dd363517d6bc01b82e50e5dc8e16c3ac569b */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_pmmp_encoding_BaseByteBuffer___construct, 0, 0, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, buffer, IS_STRING, 0, "\"\"")
Expand Down Expand Up @@ -38,8 +38,6 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_pmmp_encoding_BaseByteBuffer_trim, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_pmmp_encoding_BaseByteBuffer_rewind arginfo_class_pmmp_encoding_BaseByteBuffer_trim

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_pmmp_encoding_BaseByteBuffer___serialize, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()

Expand All @@ -62,7 +60,6 @@ ZEND_METHOD(pmmp_encoding_BaseByteBuffer, getUsedLength);
ZEND_METHOD(pmmp_encoding_BaseByteBuffer, getReservedLength);
ZEND_METHOD(pmmp_encoding_BaseByteBuffer, reserve);
ZEND_METHOD(pmmp_encoding_BaseByteBuffer, trim);
ZEND_METHOD(pmmp_encoding_BaseByteBuffer, rewind);
ZEND_METHOD(pmmp_encoding_BaseByteBuffer, __serialize);
ZEND_METHOD(pmmp_encoding_BaseByteBuffer, __unserialize);
ZEND_METHOD(pmmp_encoding_BaseByteBuffer, __debugInfo);
Expand All @@ -81,7 +78,6 @@ static const zend_function_entry class_pmmp_encoding_BaseByteBuffer_methods[] =
ZEND_ME(pmmp_encoding_BaseByteBuffer, getReservedLength, arginfo_class_pmmp_encoding_BaseByteBuffer_getReservedLength, ZEND_ACC_PUBLIC)
ZEND_ME(pmmp_encoding_BaseByteBuffer, reserve, arginfo_class_pmmp_encoding_BaseByteBuffer_reserve, ZEND_ACC_PUBLIC)
ZEND_ME(pmmp_encoding_BaseByteBuffer, trim, arginfo_class_pmmp_encoding_BaseByteBuffer_trim, ZEND_ACC_PUBLIC)
ZEND_ME(pmmp_encoding_BaseByteBuffer, rewind, arginfo_class_pmmp_encoding_BaseByteBuffer_rewind, ZEND_ACC_PUBLIC)
ZEND_ME(pmmp_encoding_BaseByteBuffer, __serialize, arginfo_class_pmmp_encoding_BaseByteBuffer___serialize, ZEND_ACC_PUBLIC)
ZEND_ME(pmmp_encoding_BaseByteBuffer, __unserialize, arginfo_class_pmmp_encoding_BaseByteBuffer___unserialize, ZEND_ACC_PUBLIC)
ZEND_ME(pmmp_encoding_BaseByteBuffer, __debugInfo, arginfo_class_pmmp_encoding_BaseByteBuffer___debugInfo, ZEND_ACC_PUBLIC)
Expand Down
6 changes: 3 additions & 3 deletions tests/negative-input-unsigned-varint.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ use pmmp\encoding\ByteBuffer;

$buffer = new ByteBuffer("");
$buffer->writeUnsignedVarInt(-1);
$buffer->rewind();
$buffer->setReadOffset(0);
var_dump($buffer->readUnsignedVarInt());

$buffer->rewind();
$buffer->setWriteOffset(0);
$buffer->writeUnsignedVarLong(-1);
$buffer->rewind();
$buffer->setReadOffset(0);
var_dump($buffer->readUnsignedVarLong());

?>
Expand Down
6 changes: 3 additions & 3 deletions tests/read-triad.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ $buffer = new ByteBuffer("\xff\x00\x00");

var_dump($buffer->readSignedTriadBE());

$buffer->rewind();
$buffer->setReadOffset(0);
var_dump($buffer->readSignedTriadLE());

$buffer->rewind();
$buffer->setReadOffset(0);
var_dump($buffer->readUnsignedTriadBE());

$buffer->rewind();
$buffer->setReadOffset(0);
var_dump($buffer->readUnsignedTriadLE());

?>
Expand Down

0 comments on commit 688806d

Please sign in to comment.