davidfowl / BedrockFramework

High performance, low level networking APIs for building custom servers and clients.
MIT License
1.05k stars 153 forks source link

LengthPrefixedProtocol sample bug? #116

Closed RayKoopa closed 3 years ago

RayKoopa commented 3 years ago

Small issue, but shouldn't this line...

if (!reader.TryReadBigEndian(out int length) || input.Length < length)

... be ...

if (!reader.TryReadBigEndian(out int length) || input.Length - sizeof(int) < length)

...?

My understanding was:

davidfowl commented 3 years ago

Good catch! Do you want to send a pull request? You should actually be able to use reader.Remaining.

RayKoopa commented 3 years ago

I did not know about reader.Remaining, good to know! I will submit a PR with it tomorrow.