convertBytesEndianType function

List<int> convertBytesEndianType(
  1. Iterable<int> bytes,
  2. int k,
  3. EndianType endianType
)

Implementation

List<int> convertBytesEndianType(Iterable<int> bytes, int k, EndianType endianType) {
  switch(endianType) {
    case EndianType.littleEndian:
      var ret = List<int>.from(bytes).reversed.toList();
      ret.addAll(List<int>.filled(k - bytes.length, 0));
      return ret;
    case EndianType.bigEndian:
    default:
      var ret = List<int>.filled(k - bytes.length, 0, growable: true);
      ret.addAll(bytes);
      return ret;
  }
}