com.amx.duet.tools.io
Class MarshallUtil

java.lang.Object
  extended bycom.amx.duet.tools.io.MarshallUtil

public class MarshallUtil
extends java.lang.Object

Utility class used to marshall data similar to NetLinx marshalling.


Constructor Summary
MarshallUtil()
           
 
Method Summary
static int LengthVariableToString(Marshall encode)
          This routine calculates how many bytes it takes to encode a variable.
static int LengthVariableToString(Marshall[] encodeArray)
          This routine calculates how many bytes it takes to encode an array variable.
static int StringToVariable(Marshall[] decodeArray, ObjectRef rBuffer, ObjectRef rPos)
          This routine takes the Encode array data from rBuffer and loads the values into the decode array variable.
static int StringToVariable(Marshall decode, ObjectRef rBuffer, ObjectRef rPos)
          This routine takes the Encode data from rBuffer and loads the values into the decode variable.
static int VariableToString(Marshall[] encodeArray, ObjectRef rBuffer, ObjectRef rPos)
          This routine takes the variable encodeArray and creates entries in the buffer to represent that array.
static int VariableToString(Marshall encode, ObjectRef rBuffer, ObjectRef rPos)
          This routine takes the variable encode and creates entries in the buffer to represent that variable.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MarshallUtil

public MarshallUtil()
Method Detail

VariableToString

public static final int VariableToString(Marshall encode,
                                         ObjectRef rBuffer,
                                         ObjectRef rPos)
This routine takes the variable encode and creates entries in the buffer to represent that variable. The variable passed in can be of any intrinsic type or a class that implements the IStruct interface.

Note: NetLinx intrinsic types are smaller than java types
Example: INTEGER = short and LONG = int

Parameters:
encode - This is the variable to be encoded.

Example:

 ObjectRef encoder = new ObjectRef(0);
 ObjectRef buffer = new ObjectRef("");
 ObjectRef rPos = new rPos((long)0);
 String sDate = "";
 int ret = 0;
 
 // do some date processing...
 
 encoder.valueOf(sDate);
 if ((ret = NetLinx.VariableToString(encoder, buffer, rPos)) < 0) return ret;
 
rBuffer - Must be of type String. This is where the encode data is placed.

Create rbuffer with a valueOf(String) Example:
ObjectRef rBuffer = new ObjectRef("") or rBuffer.valueOf("")

rPos - Must be of type long. This is where the first byte of the encoding is placed. It is also modified to point to the next location after the last encoded byte. That means that successive calls to this function can be made without modifying position. Position should be set to 0 on the first call.

Create rPos with a valueOf(long) Example:
ObjectRef rPos = new ObjectRef((long)0) or rPos.valueOf((long)0)

Returns:
  • 0 Encoded OK
  • -1 Encoded variable unrecognized type
  • -2 Encoded data would not fit into buffer, buffer too small

VariableToString

public static final int VariableToString(Marshall[] encodeArray,
                                         ObjectRef rBuffer,
                                         ObjectRef rPos)
This routine takes the variable encodeArray and creates entries in the buffer to represent that array. The array passed in can be of any intrinsic type or an array of classes that implement the IStruct interface.

Note: NetLinx intrinsic types are smaller than java types
Example: INTEGER = short and LONG = int

Parameters:
encodeArray - This is the variable to be encoded.

Example (class Appointment implements IStruct):

 ObjectRef buffer = new ObjectRef("");
 ObjectRef rPos = new rPos((long)0);
 Appointment sAppts[] = new Appointment[10];
 int ret = 0;
 
 // do some appointment processing...
 
 ObjectRef[] encodeArray = new ObjectRef[sAppts.length];
 for (int i = 0; i < sAppts.length; i++)
 	encodeArray[i] = new ObjectRef(sAppts[i]);
 if ((ret = NetLinx.VariableToString(encodeArray, buffer, rPos)) < 0) return ret;
 
rBuffer - Must be of type String. This is where the encode data is placed.

Create rbuffer with a valueOf(String) Example:
ObjectRef rBuffer = new ObjectRef("") or rBuffer.valueOf("")

rPos - Must be of type long. This is where the first byte of the encoding is placed. It is also modified to point to the next location after the last encoded byte. That means that successive calls to this function can be made without modifying position. Position should be set to 0 on the first call.

Create rPos with a valueOf(long) Example:
ObjectRef rPos = new ObjectRef((long)0) or rPos.valueOf((long)0)

Returns:
  • 0 Encoded OK
  • -1 Encoded variable unrecognized type
  • -2 Encoded data would not fit into buffer, buffer too small

StringToVariable

public static final int StringToVariable(Marshall decode,
                                         ObjectRef rBuffer,
                                         ObjectRef rPos)
This routine takes the Encode data from rBuffer and loads the values into the decode variable. The decode variable must match the type of the encoded variable. In the case where the Encode variable was a structure then the decode variable members must match in type and order. However if the number of members of the structures doesn’t match then the routine will fill all it can or skip any unused data members.

Note: NetLinx intrinsic types are smaller than java types
Example: INTEGER = short and LONG = int

Parameters:
decode - This is the variable to be decoded into.

Example:

 ObjectRef decoder = new ObjectRef(0);
 ObjectRef buffer = new ObjectRef("");
 ObjectRef rPos = new rPos((long)0);
 String sDate = "";
 int ret = 0;
 
 // do some date processing...
 
 decoder.valueOf(sDate);
 if ((ret = NetLinx.StringToVariable(decoder, buffer, rPos)) < 0) return ret;
 sDate = decoder.toString();
 
rBuffer - Must be of type String. This is where the decode data is found.

Create rbuffer with a valueOf(String) Example:
ObjectRef rBuffer = new ObjectRef("") or rBuffer.valueOf("")

rPos - Must be of type long. This is where the first byte of the decode data. Is it also modified to point to the next location after the last decoded byte. That means that successive calls to this function can be made without modifying position. Position should be set to 0 on the first call.

Create rPos with a valueOf(long) Example:
ObjectRef rPos = new ObjectRef((long)0) or rPos.valueOf((long)0)

Returns:
  • 2 - Decode data to small, more members in structure
  • 1 - Structure to small, more members in decode string
  • 0 - Decoded OK
  • -1 - Decode variable type mismatch
  • -2 - Decode data too small, decoder ran out of data

StringToVariable

public static final int StringToVariable(Marshall[] decodeArray,
                                         ObjectRef rBuffer,
                                         ObjectRef rPos)
This routine takes the Encode array data from rBuffer and loads the values into the decode array variable. The decode array variable must match the type of the encoded array variable. In the case where the Encode variable was a structure array then the decode variable members must match in type and order. However if the number of members of the structures doesn’t match then the routine will fill all it can or skip any unused data members.

Note: NetLinx intrinsic types are smaller than java types
Example: INTEGER = short and LONG = int

Parameters:
decodeArray - This is the variable to be decoded into.

Example (class Appointment implements IStruct):

 ObjectRef buffer = new ObjectRef("");
 ObjectRef rPos = new rPos((long)0);
 Appointment sAppts[] = new Appointment[10];
 int ret = 0;
 
 // do some appointment processing...
 
 ObjectRef[] decodeArray = new ObjectRef[sAppts.length];
 for (int i = 0; i < sAppts.length; i++)
 	decodeArray[i] = new ObjectRef(sAppts[i]);
 if ((ret = NetLinx.StringToVariable(decodeArray, buffer, rTempPos)) < 0) return ret;
 

Note: Class objects such as the Appointment class are passed by reference to the ObjectRef class. Therefore, the values will change along with the decodeArray value and don't need to be passed back to the sAppts array, but intrinsic type arrays do need their values to be passed back. So you will need to something like this:

 public int [] nApptList = new int[10];
 decodeArray = new ObjectRef[nApptList.length];
 for (int i = 0; i < nApptList.length; i++)
 	decodeArray[i] = new ObjectRef((short)nApptList[i]);
 if ((ret = NetLinx.StringToVariable(decodeArray, buffer, rTempPos)) < 0) return ret;
 for (int i = 0; i < nApptList.length; i++)
 	nApptList[i] = decodeArray[i].toInt();
 
rBuffer - Must be of type String. This is where the decode data is found.

Create rbuffer with a valueOf(String) Example:
ObjectRef rBuffer = new ObjectRef("") or rBuffer.valueOf("")

rPos - Must be of type long. This is where the first byte of the decode data. Is it also modified to point to the next location after the last decoded byte. That means that successive calls to this function can be made without modifying position. Position should be set to 0 on the first call.

Create rPos with a valueOf(long) Example:
ObjectRef rPos = new ObjectRef((long)0) or rPos.valueOf((long)0)

Returns:
  • 2 - Decode data to small, more members in structure
  • 1 - Structure to small, more members in decode string
  • 0 - Decoded OK
  • -1 - Decode variable type mismatch
  • -2 - Decode data too small, decoder ran out of data

LengthVariableToString

public static final int LengthVariableToString(Marshall encode)
This routine calculates how many bytes it takes to encode a variable.

Parameters:
encode - any type of variable. This is the variable to be encoded. Example:
ObjectRef encode = new ObjectRef(0) or encode.valueOf(0)
Returns:
Number of bytes required to encode variable. 0 if there is an error.

LengthVariableToString

public static final int LengthVariableToString(Marshall[] encodeArray)
This routine calculates how many bytes it takes to encode an array variable.

Parameters:
encodeArray - any type of array variable. This is the array to be encoded. Example:
 ObjectRef[] encodeArray = new ObjectRef[nValues.length];
 for (int i = 0; i < nValues.length; i++)
 	encodeArray[i] = new ObjectRef(nValues[i]);
 
Returns:
Number of bytes required to encode variable. 0 if there is an error.


Copyright © 2008 AMX LLC. All Rights Reserved.