tedd / tedd.spanutils Goto Github PK
View Code? Open in Web Editor NEWUtilities for reading/writing to Span<byte>
License: GNU Lesser General Public License v3.0
Utilities for reading/writing to Span<byte>
License: GNU Lesser General Public License v3.0
Change this
<TargetFrameworks>net461;net462;net47;net471;net472;net48;netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0</TargetFrameworks>
Into
<TargetFrameworks>net461;netstandard2.0;netstandard2.1</TargetFrameworks>
Info:
Benchmark different ways to copy into Span. Different techniques result in different opcodes. Some with many branches. Also writing last byte first to span causes all consecutive overflow checks to be removed. But chances are we will cross cache lines in reverse order. Benchmark, benchmark benchmark.
Can you please make your library compatible with .net standard 2.0 ?
Hello @tedd ,
I thought that the SpanStream
could be used to replace BinaryReader
and BinaryWriter
, however this does not work because the byte storing is reversed.
Your code
public static UInt32 ReadUInt32(this Span<byte> span)
{
// return MemoryMarshal.Cast<byte, UInt32>(span)[0];
return (UInt32)(
((UInt32)span[3])
| ((UInt32)span[2] << (8 * 1))
| ((UInt32)span[1] << (8 * 2))
| ((UInt32)span[0] << (8 * 3))
);
}
Code from BinaryReader (https://referencesource.microsoft.com/#mscorlib/system/io/binaryreader.cs,185)
return (int)(m_buffer[0] | m_buffer[1] << 8 | m_buffer[2] << 16 | m_buffer[3] << 24);
Is this intentional?
Are these compatible?
See this document which describes the VINT:
https://github.com/ietf-wg-cellar/ebml-specification/blob/master/specification.markdown#variable-size-integer
Add aliases for known datatypes
I think this should be byte
?
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.