/**
 * This class is automatically generated by mig. DO NOT EDIT THIS FILE.
 * This class implements a Java interface to the 'AppMsg'
 * message type.
 */

public class AppMsg extends net.tinyos.message.Message {

    /** The default size of this message type in bytes. */
    public static final int DEFAULT_MESSAGE_SIZE = 102;

    /** The Active Message type associated with this message. */
    public static final int AM_TYPE = 30;

    /** Create a new AppMsg of size 102. */
    public AppMsg() {
        super(DEFAULT_MESSAGE_SIZE);
        amTypeSet(AM_TYPE);
    }

    /** Create a new AppMsg of the given data_length. */
    public AppMsg(int data_length) {
        super(data_length);
        amTypeSet(AM_TYPE);
    }

    /**
     * Create a new AppMsg with the given data_length
     * and base offset.
     */
    public AppMsg(int data_length, int base_offset) {
        super(data_length, base_offset);
        amTypeSet(AM_TYPE);
    }

    /**
     * Create a new AppMsg using the given byte array
     * as backing store.
     */
    public AppMsg(byte[] data) {
        super(data);
        amTypeSet(AM_TYPE);
    }

    /**
     * Create a new AppMsg using the given byte array
     * as backing store, with the given base offset.
     */
    public AppMsg(byte[] data, int base_offset) {
        super(data, base_offset);
        amTypeSet(AM_TYPE);
    }

    /**
     * Create a new AppMsg using the given byte array
     * as backing store, with the given base offset and data length.
     */
    public AppMsg(byte[] data, int base_offset, int data_length) {
        super(data, base_offset, data_length);
        amTypeSet(AM_TYPE);
    }

    /**
     * Create a new AppMsg embedded in the given message
     * at the given base offset.
     */
    public AppMsg(net.tinyos.message.Message msg, int base_offset) {
        super(msg, base_offset, DEFAULT_MESSAGE_SIZE);
        amTypeSet(AM_TYPE);
    }

    /**
     * Create a new AppMsg embedded in the given message
     * at the given base offset and length.
     */
    public AppMsg(net.tinyos.message.Message msg, int base_offset, int data_length) {
        super(msg, base_offset, data_length);
        amTypeSet(AM_TYPE);
    }

    /**
    /* Return a String representation of this message. Includes the
     * message type name and the non-indexed field values.
     */
    public String toString() {
      String s = "Message <AppMsg> \n";
      try {
        s += "  [trans_id=0x"+Long.toHexString(get_trans_id())+"]\n";
      } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ }
      try {
        s += "  [app_id=0x"+Long.toHexString(get_app_id())+"]\n";
      } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ }
      try {
        s += "  [payload=";
        for (int i = 0; i < 100; i++) {
          s += "0x"+Long.toHexString(getElement_payload(i) & 0xff)+" ";
        }
        s += "]\n";
      } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ }
      return s;
    }

    // Message-type-specific access methods appear below.

    /////////////////////////////////////////////////////////
    // Accessor methods for field: trans_id
    //   Field type: short, signed
    //   Offset (bits): 0
    //   Size (bits): 8
    /////////////////////////////////////////////////////////

    /**
     * Return whether the field 'trans_id' is signed (true).
     */
    public static boolean isSigned_trans_id() {
        return true;
    }

    /**
     * Return whether the field 'trans_id' is an array (false).
     */
    public static boolean isArray_trans_id() {
        return false;
    }

    /**
     * Return the offset (in bytes) of the field 'trans_id'
     */
    public static int offset_trans_id() {
        return (0 / 8);
    }

    /**
     * Return the offset (in bits) of the field 'trans_id'
     */
    public static int offsetBits_trans_id() {
        return 0;
    }

    /**
     * Return the value (as a short) of the field 'trans_id'
     */
    public short get_trans_id() {
        return (short)getUIntBEElement(offsetBits_trans_id(), 8);
    }

    /**
     * Set the value of the field 'trans_id'
     */
    public void set_trans_id(short value) {
        setUIntBEElement(offsetBits_trans_id(), 8, value);
    }

    /**
     * Return the size, in bytes, of the field 'trans_id'
     */
    public static int size_trans_id() {
        return (8 / 8);
    }

    /**
     * Return the size, in bits, of the field 'trans_id'
     */
    public static int sizeBits_trans_id() {
        return 8;
    }

    /////////////////////////////////////////////////////////
    // Accessor methods for field: app_id
    //   Field type: short, signed
    //   Offset (bits): 8
    //   Size (bits): 8
    /////////////////////////////////////////////////////////

    /**
     * Return whether the field 'app_id' is signed (true).
     */
    public static boolean isSigned_app_id() {
        return true;
    }

    /**
     * Return whether the field 'app_id' is an array (false).
     */
    public static boolean isArray_app_id() {
        return false;
    }

    /**
     * Return the offset (in bytes) of the field 'app_id'
     */
    public static int offset_app_id() {
        return (8 / 8);
    }

    /**
     * Return the offset (in bits) of the field 'app_id'
     */
    public static int offsetBits_app_id() {
        return 8;
    }

    /**
     * Return the value (as a short) of the field 'app_id'
     */
    public short get_app_id() {
        return (short)getUIntBEElement(offsetBits_app_id(), 8);
    }

    /**
     * Set the value of the field 'app_id'
     */
    public void set_app_id(short value) {
        setUIntBEElement(offsetBits_app_id(), 8, value);
    }

    /**
     * Return the size, in bytes, of the field 'app_id'
     */
    public static int size_app_id() {
        return (8 / 8);
    }

    /**
     * Return the size, in bits, of the field 'app_id'
     */
    public static int sizeBits_app_id() {
        return 8;
    }

    /////////////////////////////////////////////////////////
    // Accessor methods for field: payload
    //   Field type: byte[], signed
    //   Offset (bits): 16
    //   Size of each element (bits): 8
    /////////////////////////////////////////////////////////

    /**
     * Return whether the field 'payload' is signed (true).
     */
    public static boolean isSigned_payload() {
        return true;
    }

    /**
     * Return whether the field 'payload' is an array (true).
     */
    public static boolean isArray_payload() {
        return true;
    }

    /**
     * Return the offset (in bytes) of the field 'payload'
     */
    public static int offset_payload(int index1) {
        int offset = 16;
        if (index1 < 0 || index1 >= 100) throw new ArrayIndexOutOfBoundsException();
        offset += 0 + index1 * 8;
        return (offset / 8);
    }

    /**
     * Return the offset (in bits) of the field 'payload'
     */
    public static int offsetBits_payload(int index1) {
        int offset = 16;
        if (index1 < 0 || index1 >= 100) throw new ArrayIndexOutOfBoundsException();
        offset += 0 + index1 * 8;
        return offset;
    }

    /**
     * Return the entire array 'payload' as a byte[]
     */
    public byte[] get_payload() {
        byte[] tmp = new byte[100];
        for (int index0 = 0; index0 < numElements_payload(0); index0++) {
            tmp[index0] = getElement_payload(index0);
        }
        return tmp;
    }

    /**
     * Set the contents of the array 'payload' from the given byte[]
     */
    public void set_payload(byte[] value) {
        for (int index0 = 0; index0 < value.length; index0++) {
            setElement_payload(index0, value[index0]);
        }
    }

    /**
     * Return an element (as a byte) of the array 'payload'
     */
    public byte getElement_payload(int index1) {
        return (byte)getSIntBEElement(offsetBits_payload(index1), 8);
    }

    /**
     * Set an element of the array 'payload'
     */
    public void setElement_payload(int index1, byte value) {
        setSIntBEElement(offsetBits_payload(index1), 8, value);
    }

    /**
     * Return the total size, in bytes, of the array 'payload'
     */
    public static int totalSize_payload() {
        return (800 / 8);
    }

    /**
     * Return the total size, in bits, of the array 'payload'
     */
    public static int totalSizeBits_payload() {
        return 800;
    }

    /**
     * Return the size, in bytes, of each element of the array 'payload'
     */
    public static int elementSize_payload() {
        return (8 / 8);
    }

    /**
     * Return the size, in bits, of each element of the array 'payload'
     */
    public static int elementSizeBits_payload() {
        return 8;
    }

    /**
     * Return the number of dimensions in the array 'payload'
     */
    public static int numDimensions_payload() {
        return 1;
    }

    /**
     * Return the number of elements in the array 'payload'
     */
    public static int numElements_payload() {
        return 100;
    }

    /**
     * Return the number of elements in the array 'payload'
     * for the given dimension.
     */
    public static int numElements_payload(int dimension) {
      int array_dims[] = { 100,  };
        if (dimension < 0 || dimension >= 1) throw new ArrayIndexOutOfBoundsException();
        if (array_dims[dimension] == 0) throw new IllegalArgumentException("Array dimension "+dimension+" has unknown size");
        return array_dims[dimension];
    }

    /**
     * Fill in the array 'payload' with a String
     */
    public void setString_payload(String s) { 
         int len = s.length();
         int i;
         for (i = 0; i < len; i++) {
             setElement_payload(i, (byte)s.charAt(i));
         }
         setElement_payload(i, (byte)0); //null terminate
    }

    /**
     * Read the array 'payload' as a String
     */
    public String getString_payload() { 
         char carr[] = new char[Math.min(net.tinyos.message.Message.MAX_CONVERTED_STRING_LENGTH,100)];
         int i;
         for (i = 0; i < carr.length; i++) {
             if ((char)getElement_payload(i) == (char)0) break;
             carr[i] = (char)getElement_payload(i);
         }
         return new String(carr,0,i);
    }

}
