zbx91 / BinaryEncoding

Easy encoding of numbers to BigEndian, LittleEndian and Varint.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BinaryEncoding

Build Status Build status NuGet Badge

BinaryEncoding simplifies the encoding of numbers to BigEndian, LittleEndian and Varint to byte arrays.

API

To set values to an array of bytes:

Binary.BigEndian.Set(bytes, offset, value);
Binary.LittleEndian.Set(bytes, offset, value);
Binary.Varint.Write(bytes, offset, value);

Extension methods are provided for retrieving the bytes:

Binary.BigEndian.GetBytes(value);
Binary.LittleEndian.GetBytes(value);
Binary.Varint.GetBytes(value);

Also, for converting bytes to numbers:

Binary.BigEndian.GetInt16(bytes, offset);
Binary.BigEndian.GetInt32(bytes, offset);
Binary.BigEndian.GetInt64(bytes, offset);
Binary.BigEndian.GetUInt16(bytes, offset);
Binary.BigEndian.GetUInt32(bytes, offset);
Binary.BigEndian.GetUInt64(bytes, offset);
Binary.LittleEndian.GetInt16(bytes, offset);
Binary.LittleEndian.GetInt32(bytes, offset);
Binary.LittleEndian.GetInt64(bytes, offset);
Binary.LittleEndian.GetUInt16(bytes, offset);
Binary.LittleEndian.GetUInt32(bytes, offset);
Binary.LittleEndian.GetUInt64(bytes, offset);

// varint, returns number of bytes consumed
// value can be short, ushort, int, uint, long, ulong
Binary.Varint.Read(bytes, out value);

.. more to come

About

Easy encoding of numbers to BigEndian, LittleEndian and Varint.

License:MIT License


Languages

Language:C# 98.9%Language:Shell 1.1%