Skip to content
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

Merged
merged 7 commits into from
Nov 29, 2022
Merged

1592 bug of mqttbufferreader #1593

merged 7 commits into from
Nov 29, 2022

Conversation

chkr1011
Copy link
Collaborator

No description provided.

@chkr1011 chkr1011 linked an issue Nov 28, 2022 that may be closed by this pull request
var byte1 = _buffer[_position++];
var byte2 = _buffer[_position++];
var byte3 = _buffer[_position++];
var byte0 = _buffer[_offset + Position];
Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

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)
Copy link
Member

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.

Copy link
Member

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);
correct and as I would assume only the most significant bit is relevant.
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...

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Member

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.

@chkr1011 chkr1011 merged commit 56750ad into master Nov 29, 2022
@chkr1011 chkr1011 deleted the 1592-bug-of-mqttbufferreader branch November 29, 2022 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug of MqttBufferReader
3 participants