package ttk;

import java.nio.ByteOrder;
import java.util.Random;

public class Util {
    private static Random rand = new Random();

    public static byte[] makeLsbDword(int number){
        //TAG_TTK_REQUEST_ID is binary and represented as little-endian in TTK-buffers
        java.nio.ByteBuffer byte_buffer = java.nio.ByteBuffer.allocate(Integer.BYTES);
        byte_buffer.putInt(Integer.reverseBytes(number));
        byte_buffer.order(ByteOrder.LITTLE_ENDIAN);
        return  byte_buffer.array();
    }

    public static byte[] makeLsbWord(short number){
        //TAG_TTK_REQUEST_ID is binary and represented as little-endian in TTK-buffers
        java.nio.ByteBuffer byte_buffer = java.nio.ByteBuffer.allocate(Short.BYTES);
        byte_buffer.putShort(Short.reverseBytes(number));
        byte_buffer.order(ByteOrder.LITTLE_ENDIAN);
        return  byte_buffer.array();
    }


    public static String intToString(int number, int len){
        String amountString = String.valueOf(number);
        while(amountString.length() < len)
            amountString = '0' + amountString;
        return amountString;
    }

    public static String intToUnsignedString(int number, int len){
        String amountString = Integer.toUnsignedString(number);
        while(amountString.length() < len)
            amountString = '0' + amountString;
        return amountString;
    }
    public static int generateNegativeDWORD(){
        return rand.nextInt() | 0x80000000;
    }

    public static int generateDWORD(){
        return rand.nextInt();
    }
}
