-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1592 bug of mqttbufferreader #1593
Conversation
var byte1 = _buffer[_position++]; | ||
var byte2 = _buffer[_position++]; | ||
var byte3 = _buffer[_position++]; | ||
var byte0 = _buffer[_offset + Position]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: for "modern targets" this could be done via BinaryPrimitives.ReadUInt32BigEndian
-method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I adopted this but enforced the reverse order. With the method you mentioned it depends on the CPU.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right that "cleans up" the order automatically. MemoryMarshal.ReadXYZ
would be the correct one.
The gain is one memory read instead of the individual bytes (which wil most likely be in the same cacheline). Effect will be only 1 bound-check instead of the 4.
|
||
return result; | ||
if (value <= 16383) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be expressed as 0x7F
, 0x3F_FF
, 0x1F_FF_FF
? To make it a bit more obvious where these constants come from? The old algorithm was clearer on that regard.
Or as comment just a link to the spec that dictates that encoding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also when I read
} while ((encodedByte & 128) != 0); |
With the constants used it's 1, 2, 3 bits that are "reserved for continuation", while only 1 is needed?
So the constants should be
0x7F
, 0x7F_FF
, 0x7F_FF_FF
? So bigger ranges can be encoded with less bytes used. Or I'm missing something...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imported some documentation from the RFC to explain the values.
I do not really unterstand what you are referring to in the ReaderExtensions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will merge this PR so that I can release a hotfix version soon. We can discuss this in another branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not really unterstand what you are referring to in the ReaderExtensions.
Sorry, I mixed the plain and the encoding threshoulds.
No description provided.