encodeLength

@param int $length
@param int $offset
@return \Web3p\RLP\Buffer
487394
protected function encodeLength(int $length, int $offset)
    {
        // if (!is_int($length) || !is_int($offset)) {
        //     throw new InvalidArgumentException('Length and offset must be int when call encodeLength.');
        // }
        if ($length < 56) {
            // var_dump($length, $offset);
            return new Buffer(strval($length + $offset));
        }
        $hexLength = $this->intToHex($length);
        $firstByte = $this->intToHex($offset + 55 + (strlen($hexLength) / 2));
        return new Buffer(strval($firstByte . $hexLength), 'hex');
    }
782980
public function read($length)
    {
        if ($this->offset == $this->array_size) {
            return false;
        }

        // Don't use array slice
        $arrays = [];
        $end = $length + $this->offset;
        for ($i = $this->offset; $i < $end; ++$i) {
            if (!isset($this->array[$i])) {
                break;
            }
            $arrays[] = $this->array[$i];
        }
        $this->offset += $i - $this->offset; // Limit function calls
        $chars = false;
        foreach ($arrays as $array) {
            $chars .= implode('', array_map('chr', $array));
        }

        return $chars;
    }
1046667
public function slice(int $offset, ?int $length = null): self
    {
        return Factory::create(\array_slice($this->items, $offset, $length, true));
    }
785644
public static void encodeLength(ByteArrayOutputStream out, int length) {
        LOG.entering(CLASS_NAME, "encodeLength", new Object[] { out, length });
        int byteCount = 0;
        long encodedLength = 0;

        do {
            // left shift one byte to make room for new data
            encodedLength <<= 8;
            // set 7 bits of length
            encodedLength |= (byte) (length & 0x7f);
            // right shift out the 7 bits we just set
            length >>= 7;
            // increment the byte count that we need to encode
            byteCount++;
        }
        // continue if there are remaining set length bits
        while (length > 0);

        do {
            // get byte from encoded length
            byte encodedByte = (byte) (encodedLength & 0xff);
            // right shift encoded length past byte we just got
            encodedLength >>= 8;
            // The last length byte does not have the highest bit set
            if (byteCount != 1) {
                // set highest bit if this is not the last
                encodedByte |= (byte) 0x80;
            }
            // write encoded byte
            out.write(encodedByte);
        }
        // decrement and continue if we have more bytes left
        while (--byteCount > 0);
    }
797437
public function slice($from, $length = null) {
        if ($length === null) {
            return substr($this->buffer, $from);
        }

        return substr($this->buffer, $from, $length);
    }
566682
public function getSlice($offset, $length)
    {
        $this->resultSet = $this->searchable->search($this->query, array(
            'from' => $offset,
            'size' => $length
        ));

        return $this->convertResultSet($this->resultSet);
    }
221031
public function slice($offset=0, $length=null)
    {
        $result = $this->createChildInstance();
        $result->nodes = \array_slice($this->nodes, $offset, $length);
        $result->length = \count($result->nodes);
        return $result;
    }
119774
public function read(int $length = 8192): string
    {
        $bytes           = substr($this->buffer, $this->position, $length);
        $this->position += strlen($bytes);
        return $bytes;
    }
980106
protected function doWrite(string $data, int $offset, int $length)
    {
        for ($i = 0; $i < $length; $i++) {
            $this->content[$i + $offset] = $data{$i};
        }

        if ($offset >= $this->size) {
            $this->size += $length;
        } elseif (($offset + $length) > $this->size) {
            $this->size = $offset + $length;
        }
    }
937120
public function getSlice($offset, $length)
    {
        return $this->datasetFactory
            ->bookmarks()
            ->load($offset, $length)
            ->getBookmarks();
    }
171641
public function read($length = null)
    {
        $this->_ensureReadable();
        $length = $this->_bufferSize($length);
        if ($length <= 0) {
            return '';
        }
        $result = fread($this->_resource, $length);
        return $result === false ? '' : $result;
    }
813575
static public function generateString($length) {
        $token = '';
        $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        $maxIndex = strlen($chars) - 1;
        
        for ($i = 0; $i < $length; $i++) {
            $token .= $chars[mt_rand(0, $maxIndex)];
        }
         
        return $token;
    }
1332238
public static function substr($string, $offset, $length = null)
    {
        return mb_substr($string, $offset, $length === null ? mb_strlen($string, static::ENC_UTF8) : $length, static::ENC_UTF8);
    }
360287
public function setLength($length)
    {
        $length = intval($length);
        $this->length = empty($length) ? 1 : $length;

        return $this;
    }
1127473
public function sliceSegments($offset, $length = null)
    {
        return new self(implode('/', array_slice($this->getSegments(), $offset, $length)));
    }
844845
public function slice(int $offset, ?int $length = null, bool $preserveKeys = false): self
    {
        return new static(array_slice($this->storage, $offset, $length, $preserveKeys));
    }
49127
public function protectedEncodeASN1Length($length)
    {
        if ($length <= 0x7F) {
            return chr($length);
        }
        $temp = ltrim(pack('N', $length), chr(0));
        return pack('Ca*', 0x80 | strlen($temp), $temp);
    }