Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

Fix Client read() function... #96

Closed
wants to merge 1 commit into from
Closed

Conversation

lalmat
Copy link

@lalmat lalmat commented Mar 5, 2015

... to allow to read small message sent by the server

Okay, to be clear, I'm not proud of this pull request. This is clearly NOT the best way to do it, but it works...

The (int) and (bool) cast wasn't working for me and I don't know why. The more disapointing was the bindec function... I was supposing that hexdec(bin2hex()) = bindec() but it wasn't...

This code is ugly, but it works. Maybe this could inspire Taluu to do his magic stuff on it.

@Taluu
Copy link
Contributor

Taluu commented Mar 5, 2015

With some tests, it seems that bin2hex is reproducing some strange results :

<?php
const VALUE = 42;

var_dump(decbin(42)); // expected  : 101010
var_dump(0b101010); // expected : 42

But, if we check the doc for bin2hex, it seems that the argument is not a number, but binary-data, which is something else by itself. This is indeed strange as why hexdec(bin2hex($part)) is producing a different value (should check on that), but I'll do some more tests.

I'll keep your PR around and get a look at it when I'll get the chance to :)

$length = (int) (bin2hex($part) & ~0x80); // removing the mask bit
$mask = (bool) (bin2hex($part) & 0x80);
$mask = hexdec((bin2hex($part) & 0x80)) == 1;
$length = hexdec(bin2hex($part)); // Working...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this length here has the mask bit, does it not ? Shouldn't it get a wrong result if the mask bit is 1 ?

@Taluu
Copy link
Contributor

Taluu commented May 27, 2015

Seems that #106 solved it, with a fix similar to yours... closing I guess.

@Taluu Taluu closed this May 27, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants