System.VarintBitConverter.GetVarintBytes C# (CSharp) Method

GetVarintBytes() public static method

Returns the specified 64-bit unsigned value as varint encoded array of bytes.
public static GetVarintBytes ( ulong value ) : byte[]
value ulong 64-bit unsigned value
return byte[]
        public static byte[] GetVarintBytes(ulong value)
        {
            var buffer = new byte[10];
            var pos = 0;
            do
            {
                var byteVal = value & 0x7f;
                value >>= 7;

                if (value != 0)
                {
                    byteVal |= 0x80;
                }

                buffer[pos++] = (byte)byteVal;

            } while (value != 0);

            var result = new byte[pos];
            Buffer.BlockCopy(buffer, 0, result, 0, pos);

            return result;
        }

Same methods

VarintBitConverter::GetVarintBytes ( byte value ) : byte[]
VarintBitConverter::GetVarintBytes ( int value ) : byte[]
VarintBitConverter::GetVarintBytes ( long value ) : byte[]
VarintBitConverter::GetVarintBytes ( short value ) : byte[]
VarintBitConverter::GetVarintBytes ( uint value ) : byte[]
VarintBitConverter::GetVarintBytes ( ushort value ) : byte[]