Giter Club home page Giter Club logo

php-binary-reader's People

Contributors

gingerbeardman avatar handsomematt avatar jwpage avatar klermonte avatar mdurrant avatar nsknewbie avatar scrutinizer-auto-fixer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-binary-reader's Issues

ReadInt32 with not aligned byte

Hi,

I'm not sure but I think the method bitReader in the class Int32 is wrong.
My fix is on the masks. I think it should be :

        $hiMask = $bitmask->getMask($br->getCurrentBit(), BitMask::MASK_LO) ^ 0xFF;
        $loMask = $bitmask->getMask($br->getCurrentBit(), BitMask::MASK_HI) ^ 0xFF;

Case :

Buffer :
FF 07 00 00 00

Position : 1 (2nd byte)
Current bit : 2
Nest Byte : FF

Try to read int32.

The masks are :
hiMask : 00111111
loMask : 00000011

But should be :
hiMask : 11111100
loMask : 11000000

The result will be 1058799616 (111111000111000000000000000000) and should be 4229693440 (11111100000111000000000000000000).

Tag new release

Great project ๐Ÿ‘

Can the latest commits from june be tagged into a release? Need the floating point reader but don't want to depend on dev-master

Thanks

Not all return types in comments seem correct in BinaryReader.php

Most of the functions specify return type int. While I believe the ones reading from $this->byteReader are returning string. $this->byteReader->read uses fread which returns a string (as mentioned in the comments for $this->byteReader->read).

/**
* @param int $count
* @return int
*/
public function readBytes($count)
{
return $this->byteReader->read($this, $count);
}

Conversely, getUInt16 has return type string in the comments. This should probably be int.

/**
* @return int
*/
public function readInt16()
{
return $this->int16Reader->readSigned($this);
}
/**
* @return string
*/
public function readUInt16()
{
return $this->int16Reader->read($this);
}

I think some other functions have similar problems.

Bit reader doesn't handle custom-length bit values well

I've been using the library to get contiguous bits from a binary file where the bits are not byte-aligned. I have not been getting the values I expect.

After much head-scratching, tweaking and testing I came to realise that the Bit reader wasn't working the way I expected.

It seems to be a little naive in that it assumes byte grouping and order is always based on standard approaches and so it doesn't return the anticipated values when I read bits in sequence from a file that doesn't follow convention.

For example, I have a data file with a series of 40-bit frames. Byte order becomes insignificant because the bits are sequential and variable-length, e.g. a two 14-bit integers, followed by a 5-bit integer, two individual bits, a 3-bit integer and finally 2 bits for padding to a full byte.

The problem appears to be that, for non-standard length frames like this (that potentially cross traditional byte boundaries), this library doesn't handle the bits in the strict order I'm asking for because it breaks the bits down into multi-byte chunks.

Starting at Type/Bit.php#37 for example, it explicitly tries to break down the length of bits requested into a number of whole bytes to read using the 'standard' methods (Int32, Int16 etc).

I've adapted this for my use case and I'm conscious I might not be the only person experiencing this issue, so I'm keen to integrate my changes.

While I'd like to merge my changes in, I first wanted to open up discussion for the best way to handle this as I'm sure the current Bit reader is still useful the way it is and I don't want to disrupt that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.