package com.bonait.bnframework.HBL.DataUtil;


import com.bonait.bnframework.HBL.Enum.DataFormat;

public class ByteTransDataFormat {
    public byte[] ByteTransDataFormat2(byte[] data, DataFormat df, int offset ){
        if (offset+2<2) return new byte[2];
        byte[] numArray = new byte[2];
        if (df==DataFormat.ABCD||df==DataFormat.BADC){
            numArray[0] = data[offset+1];
            numArray[1] = data[offset];
        }
        else {
            numArray[0] = data[offset];
            numArray[1] = data[offset+1];
        }
        return numArray;
    }

    public byte[] ByteTransDataFormat4(byte[] data, DataFormat df,int offset ){
        if (offset+4<4) return new byte[4];
        byte[] numArray = new byte[4];
        if (df==DataFormat.ABCD){
            numArray[0] = data[offset+3];
            numArray[1] = data[offset+2];
            numArray[2] = data[offset+1];
            numArray[3] = data[offset];
        }
        else if (df==DataFormat.BADC){
            numArray[0] = data[offset+2];
            numArray[1] = data[offset+3];
            numArray[2] = data[offset];
            numArray[3] = data[offset+1];
        }
        else if(df==DataFormat.CDAB){
            numArray[0] = data[offset+1];
            numArray[1] = data[offset];
            numArray[2] = data[offset+3];
            numArray[3] = data[offset+2];
        }
        else if(df==DataFormat.DCBA){
            numArray[0] = data[offset];
            numArray[1] = data[offset+1];
            numArray[2] = data[offset+2];
            numArray[3] = data[offset+3];
        }
        return numArray;
    }
}

