Git Product home page Git Product logo

Comments (3)

Charanor avatar Charanor commented on June 9, 2024 1

"sometimes 11" is very odd and shouldn't be happening unless you haven't read out all your "real" data

Given my silly typo in my other issue I think this was also just user error, I went through and checked all my current messages and when they arrive they never have more than 7 bits of padding. My bad again 🙏

from riptide.

tom-weiland avatar tom-weiland commented on June 9, 2024

It's not so much "intended" as it is expected. Bytes are the smallest unit of data that you can send over the network, so if a message consists of 60 bits (7.5 bytes) it will be sent as 8 bytes, with the last 4 bits being empty "filler" data. The receiving end will see that it received 8 bytes and set the writeBit (which is used to calculate UnreadBits) to 8 bytes * 8 bits per byte = 64 bits, even though the last 4 bits technically shouldn't be interpreted as data.

To prevent this from happening, senders would have to write the total number of usable bits into the message itself (near the beginning) so the receiver can read it and know exactly where the data ends. I figured this extra overhead wasn't worth it, especially since it's easy to implement yourself if you really want/need it. Additionally, you probably shouldn't be relying on there being a specific number of bits left over for any logic decisions, as a malicious client could send more or less bits (or manipulate/lie about the length value) and thereby cause problems.

The number of "extra" UnreadBits that remain after you read out all your data depends on how many bits it takes to round up to the nearest byte, meaning that you should never be seeing more than 7 "extra" bits on the receiving end. The fact that you say it's "sometimes 11" is very odd and shouldn't be happening unless you haven't read out all your "real" data...

In the example you gave, UnreadBits should always be returning 4. If it's changing/fluctuating then that's also concerning.

from riptide.

Charanor avatar Charanor commented on June 9, 2024

Thank you! Lack of knowledge from me, I just assumed network data was sent as bits, now the padding makes sense. And I was not using it for any game logic, it was just something I noticed when I added some sanity-checks around the code, one of them checking that all data was read. I'll just change the check to account for this padding. Cheers!

from riptide.

Related Issues (20)

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.