//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
namespace ImageProcessorCore.IO
{
///
/// Implementation of EndianBitConverter which converts to/from little-endian
/// byte arrays.
///
/// Adapted from Miscellaneous Utility Library
/// This product includes software developed by Jon Skeet and Marc Gravell. Contact , or see
/// .
///
///
internal sealed class LittleEndianBitConverter : EndianBitConverter
{
///
public override Endianness Endianness => Endianness.LittleEndian;
///
public override bool IsLittleEndian() => true;
///
protected internal override void CopyBytesImpl(long value, int bytes, byte[] buffer, int index)
{
for (int i = 0; i < bytes; i++)
{
buffer[i + index] = unchecked((byte)(value & 0xff));
value = value >> 8;
}
}
///
protected internal override long FromBytes(byte[] buffer, int startIndex, int bytesToConvert)
{
long ret = 0;
for (int i = 0; i < bytesToConvert; i++)
{
ret = unchecked((ret << 8) | buffer[startIndex + bytesToConvert - 1 - i]);
}
return ret;
}
}
}