package net.alphadev.usbstorage.scsi;

import java.nio.ByteBuffer;

/**
 * Created by jan on 27.08.14.
 */
public class CommandStatusWrapper {
    private byte[] mSignature;
    private int mTag;
    private int mDataResidue;
    private byte mStatus;

    public CommandStatusWrapper(byte[] data) {
        if (data.length != 13) {
            throw new IllegalArgumentException("CSW always has a length of 13 bytes!");
        }

        mSignature = new byte[4];
        mSignature[0x0] = data[0x0];
        mSignature[0x1] = data[0x1];
        mSignature[0x2] = data[0x2];
        mSignature[0x3] = data[0x3];

        mTag = ByteBuffer.wrap(data, 0x4, 4).getInt();
        mDataResidue = ByteBuffer.wrap(data, 0x8, 4).getInt();
        mStatus = data[0xc];
    }

    public String getSignature() {
        return new String(mSignature);
    }

    public int getTag() {
        return mTag;
    }

    public int getDataResidue() {
        return mDataResidue;
    }

    public byte getStatus() {
        return mStatus;
    }
}

@@ -59,16 +59,43 @@
 eBuffer;
+%0Aimport java.nio.ByteOrder;
 %0A%0A/**%0A *
@@ -676,24 +676,55 @@
 ta, 0x4, 4).
+order(ByteOrder.LITTLE_ENDIAN).
 getInt();%0A  
@@ -743,16 +743,23 @@
 esidue =
+ mTag =
  ByteBuf
@@ -781,16 +781,47 @@
 0x8, 4).
+order(ByteOrder.LITTLE_ENDIAN).
 getInt()

fix endian-ness of parsed ints.