angelobreuer / bufferio Goto Github PK
View Code? Open in Web Editor NEWExtensible Big-Endian Byte Buffer and Binary read- / write streams.
License: MIT License
Extensible Big-Endian Byte Buffer and Binary read- / write streams.
License: MIT License
Code:
var headerBytes = Encoding.UTF8.GetBytes(Header);
var buffer = new ByteBuffer(4 * 2 + headerBytes.Length);
buffer.Write(ID);
buffer.Write(headerBytes.Length);
buffer.Write(headerBytes);
return buffer.GetBuffer();
ByteBuffer:
Debug:
Capacity [int]:
16
Endianness [Endianness]:
BigEndian
IsEmpty [bool]:
false
IsExpandable [bool]:
true
IsExposable [bool]:
true
IsPooled [bool]:
true
IsReadOnly [bool]:
false
Length [int]:
13
Position [int]:
13
ArraySement:
Array [byte[]]:
{byte[16]}
Count [int]:
0
Offset [int]:
0
Seems Length be Capacity
ByteBuffer.cs:201
public int Remaining => Length - Position;
The ReadBytes
function is implemented as the following:
public void ReadBytes(byte[] buffer, int offset, int count)
{
if (BaseStream.Read(buffer, offset, count) < 0)
{
throw new EndOfStreamException();
}
}
Stream.Read(buffer, offset, count)
does not return a negative value. It can return less bytes than expected (if that many bytes is not available at the moment), or 0 at the end of stream. (If not at the end of stream, then the function will wait until at least one character is read. For example: if the stream is a pipe and no bytes are available, then reading will hang until the writer either closes the stream, or writes at least one byte.) So the result is that the function may silently fill the array with less bytes than expected, and give no indication that this is what has happened.
In addition, the non-public FillReadBuffer
function is implemented incorrectly. Again, Stream.Read
may return less bytes than expected; this is normal and doesn't necessarily mean that the end of stream has been reached.
Contrast this - e.g. using ILSpy utility - with the implementation of .NET BinaryReader
, where ReadBytes
returns the array instead of filling it, and both ReadBytes
and the typed Read
functions (using non-public function FillBuffer
) repeatedly call Stream.Read
if necessary.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.