Download the PHP package thesis/varint without Composer

On this page you can find all versions of the php package thesis/varint. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package varint

Varint and ZigZag encoding implementation

Variable-width integers are at the core of the wire format of protobuf, kafka protocol and many other protocols and codecs.

Installation

Usage

The library uses \BcMath\Number instead of int in its API to support the serialization of large numbers and avoid overflow issues. A library built on top of thesis/varint may choose to offer int in its API if it's certain that no overflow issues will occur or handle overflow errors itself. This is not the responsibility of this library.

Example of varint encoding using BcMath implementation:

Zigzag encoding is used for serializing negative varint numbers.

You can get the size of a varint in bytes before encoding it:

Likewise, you can decode a varint to get both the number and its size in bytes:

This is useful to use in protocols because you don't know in advance how many bytes to consume from the buffer to read a varint. Therefore, you read it first and then consume that many bytes from the buffer based on the size obtained from $sized->size.

Why not use brick/math?

brick/math is a fairly good library, and an early version of this library used it specifically. However, while developing the protobuf tooling, it became clear that working with numeric-string was inconvenient, so a type that was simple and stable enough to be part of the API was needed. Here, the BigInteger from brick/math faces a competitor in the form of the Number type from bcmath for PHP 8.4.

Since bcmath is a bundled extension, users won't need to install it explicitly, making it a more stable dependency compared to brick/math, which still hasn't reached a major version. Although brick/math allows using the gmp extension instead of bcmath as a faster alternative, this speed is lost behind brick/math's abstractions, as a simple benchmark of varint/zigzag encoding demonstrated.

Therefore, we decided to settle on bcmath and explicitly use its Number type.


All versions of varint with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
ext-bcmath Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package thesis/varint contains the following files

Loading the files please wait ...