Skip to content

Commit

Permalink
Merge pull request #44 from open-dis/rm-onebytechunk
Browse files Browse the repository at this point in the history
Replace OneByteChunk with byte array
  • Loading branch information
mcgredonps authored Jul 6, 2017
2 parents 43a0c02 + 9cebc6c commit 3614c4b
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 768 deletions.
57 changes: 13 additions & 44 deletions src/main/java/edu/nps/moves/dis/GridAxisRecordRepresentation0.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GridAxisRecordRepresentation0 extends GridAxisRecord implements Ser
protected int numberOfBytes;

/** variable length variablelist of data parameters ^^^this is wrong--need padding as well */
protected List< OneByteChunk > dataValues = new ArrayList< OneByteChunk >();
protected byte[] dataValues = new byte[0];

/** Constructor */
public GridAxisRecordRepresentation0()
Expand All @@ -33,18 +33,14 @@ public int getMarshalledSize()

marshalSize = super.getMarshalledSize();
marshalSize = marshalSize + 2; // numberOfBytes
for(int idx=0; idx < dataValues.size(); idx++)
{
OneByteChunk listElement = dataValues.get(idx);
marshalSize = marshalSize + listElement.getMarshalledSize();
}
marshalSize = marshalSize + dataValues.length;

return marshalSize;
}


public int getNumberOfBytes()
{ return (int)dataValues.size();
{ return dataValues.length;
}

/** Note that setting this value will not change the marshalled value. The list whose length this describes is used for that purpose.
Expand All @@ -55,11 +51,11 @@ public void setNumberOfBytes(int pNumberOfBytes)
{ numberOfBytes = pNumberOfBytes;
}

public void setDataValues(List<OneByteChunk> pDataValues)
public void setDataValues(byte[] pDataValues)
{ dataValues = pDataValues;
}

public List<OneByteChunk> getDataValues()
public byte[] getDataValues()
{ return dataValues; }


Expand All @@ -68,13 +64,7 @@ public void marshal(DataOutputStream dos)
super.marshal(dos);
try
{
dos.writeShort( (short)dataValues.size());

for(int idx = 0; idx < dataValues.size(); idx++)
{
OneByteChunk aOneByteChunk = dataValues.get(idx);
aOneByteChunk.marshal(dos);
} // end of list marshalling
dos.write(dataValues);

} // end try
catch(Exception e)
Expand All @@ -89,13 +79,8 @@ public void unmarshal(DataInputStream dis)
try
{
numberOfBytes = (int)dis.readUnsignedShort();
for(int idx = 0; idx < numberOfBytes; idx++)
{
OneByteChunk anX = new OneByteChunk();
anX.unmarshal(dis);
dataValues.add(anX);
}

dataValues = new byte[numberOfBytes];
dis.read(dataValues);
} // end try
catch(Exception e)
{
Expand All @@ -115,14 +100,8 @@ public void unmarshal(DataInputStream dis)
public void marshal(java.nio.ByteBuffer buff)
{
super.marshal(buff);
buff.putShort( (short)dataValues.size());

for(int idx = 0; idx < dataValues.size(); idx++)
{
OneByteChunk aOneByteChunk = (OneByteChunk)dataValues.get(idx);
aOneByteChunk.marshal(buff);
} // end of list marshalling

buff.putShort((short)dataValues.length);
buff.put(dataValues);
} // end of marshal method

/**
Expand All @@ -137,13 +116,8 @@ public void unmarshal(java.nio.ByteBuffer buff)
super.unmarshal(buff);

numberOfBytes = (int)(buff.getShort() & 0xFFFF);
for(int idx = 0; idx < numberOfBytes; idx++)
{
OneByteChunk anX = new OneByteChunk();
anX.unmarshal(buff);
dataValues.add(anX);
}

dataValues = new byte[numberOfBytes];
buff.get(dataValues);
} // end of unmarshal method


Expand Down Expand Up @@ -179,12 +153,7 @@ public boolean equalsImpl(Object obj)
final GridAxisRecordRepresentation0 rhs = (GridAxisRecordRepresentation0)obj;

if( ! (numberOfBytes == rhs.numberOfBytes)) ivarsEqual = false;

for(int idx = 0; idx < dataValues.size(); idx++)
{
if( ! ( dataValues.get(idx).equals(rhs.dataValues.get(idx)))) ivarsEqual = false;
}

if( ! (Arrays.equals(dataValues, rhs.dataValues))) ivarsEqual = false;

return ivarsEqual && super.equalsImpl(rhs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class IntercomCommunicationsParameters extends Object implements Serializ
protected int recordLength;

/** variable length variablelist of data parameters */
protected List< OneByteChunk > parameterValues = new ArrayList< OneByteChunk >();
protected byte[] parameterValues = new byte[0];

/** Constructor */
public IntercomCommunicationsParameters()
Expand All @@ -36,11 +36,7 @@ public int getMarshalledSize()

marshalSize = marshalSize + 2; // recordType
marshalSize = marshalSize + 2; // recordLength
for(int idx=0; idx < parameterValues.size(); idx++)
{
OneByteChunk listElement = parameterValues.get(idx);
marshalSize = marshalSize + listElement.getMarshalledSize();
}
marshalSize = marshalSize + parameterValues.length;

return marshalSize;
}
Expand All @@ -55,7 +51,7 @@ public int getRecordType()
}

public int getRecordLength()
{ return (int)parameterValues.size();
{ return parameterValues.length;
}

/** Note that setting this value will not change the marshalled value. The list whose length this describes is used for that purpose.
Expand All @@ -66,11 +62,11 @@ public void setRecordLength(int pRecordLength)
{ recordLength = pRecordLength;
}

public void setParameterValues(List<OneByteChunk> pParameterValues)
public void setParameterValues(byte[] pParameterValues)
{ parameterValues = pParameterValues;
}

public List<OneByteChunk> getParameterValues()
public byte[] getParameterValues()
{ return parameterValues; }


Expand All @@ -79,14 +75,8 @@ public void marshal(DataOutputStream dos)
try
{
dos.writeShort( (short)recordType);
dos.writeShort( (short)parameterValues.size());

for(int idx = 0; idx < parameterValues.size(); idx++)
{
OneByteChunk aOneByteChunk = parameterValues.get(idx);
aOneByteChunk.marshal(dos);
} // end of list marshalling

dos.writeShort( (short)parameterValues.length);
dos.write(parameterValues);
} // end try
catch(Exception e)
{
Expand All @@ -99,13 +89,8 @@ public void unmarshal(DataInputStream dis)
{
recordType = (int)dis.readUnsignedShort();
recordLength = (int)dis.readUnsignedShort();
for(int idx = 0; idx < recordLength; idx++)
{
OneByteChunk anX = new OneByteChunk();
anX.unmarshal(dis);
parameterValues.add(anX);
}

parameterValues = new byte[recordLength];
dis.read(parameterValues);
} // end try
catch(Exception e)
{
Expand All @@ -125,14 +110,8 @@ public void unmarshal(DataInputStream dis)
public void marshal(java.nio.ByteBuffer buff)
{
buff.putShort( (short)recordType);
buff.putShort( (short)parameterValues.size());

for(int idx = 0; idx < parameterValues.size(); idx++)
{
OneByteChunk aOneByteChunk = (OneByteChunk)parameterValues.get(idx);
aOneByteChunk.marshal(buff);
} // end of list marshalling

buff.putShort( (short)parameterValues.length);
buff.put(parameterValues);
} // end of marshal method

/**
Expand All @@ -146,13 +125,8 @@ public void unmarshal(java.nio.ByteBuffer buff)
{
recordType = (int)(buff.getShort() & 0xFFFF);
recordLength = (int)(buff.getShort() & 0xFFFF);
for(int idx = 0; idx < recordLength; idx++)
{
OneByteChunk anX = new OneByteChunk();
anX.unmarshal(buff);
parameterValues.add(anX);
}

parameterValues = new byte[recordLength];
buff.get(parameterValues);
} // end of unmarshal method


Expand Down Expand Up @@ -194,12 +168,7 @@ public boolean equalsImpl(Object obj)

if( ! (recordType == rhs.recordType)) ivarsEqual = false;
if( ! (recordLength == rhs.recordLength)) ivarsEqual = false;

for(int idx = 0; idx < parameterValues.size(); idx++)
{
if( ! ( parameterValues.get(idx).equals(rhs.parameterValues.get(idx)))) ivarsEqual = false;
}

if( ! (Arrays.equals(parameterValues, rhs.parameterValues))) ivarsEqual = false;

return ivarsEqual;
}
Expand Down
59 changes: 14 additions & 45 deletions src/main/java/edu/nps/moves/dis/IntercomSignalPdu.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class IntercomSignalPdu extends RadioCommunicationsFamilyPdu implements S
protected int samples;

/** data bytes */
protected List< OneByteChunk > data = new ArrayList< OneByteChunk >();
protected byte[] data = new byte[0];

/** Constructor */
public IntercomSignalPdu()
Expand All @@ -58,11 +58,7 @@ public int getMarshalledSize()
marshalSize = marshalSize + 4; // sampleRate
marshalSize = marshalSize + 2; // dataLength
marshalSize = marshalSize + 2; // samples
for(int idx=0; idx < data.size(); idx++)
{
OneByteChunk listElement = data.get(idx);
marshalSize = marshalSize + listElement.getMarshalledSize();
}
marshalSize = marshalSize + data.length;

return marshalSize;
}
Expand Down Expand Up @@ -109,7 +105,7 @@ public long getSampleRate()
}

public int getDataLength()
{ return (int)data.size();
{ return data.length;
}

/** Note that setting this value will not change the marshalled value. The list whose length this describes is used for that purpose.
Expand All @@ -128,11 +124,11 @@ public int getSamples()
{ return samples;
}

public void setData(List<OneByteChunk> pData)
public void setData(byte[] pData)
{ data = pData;
}

public List<OneByteChunk> getData()
public byte[] getData()
{ return data; }


Expand All @@ -146,15 +142,9 @@ public void marshal(DataOutputStream dos)
dos.writeShort( (short)encodingScheme);
dos.writeShort( (short)tdlType);
dos.writeInt( (int)sampleRate);
dos.writeShort( (short)data.size());
dos.writeShort( (short)data.length);
dos.writeShort( (short)samples);

for(int idx = 0; idx < data.size(); idx++)
{
OneByteChunk aOneByteChunk = data.get(idx);
aOneByteChunk.marshal(dos);
} // end of list marshalling

dos.write(data);
} // end try
catch(Exception e)
{
Expand All @@ -174,13 +164,8 @@ public void unmarshal(DataInputStream dis)
sampleRate = dis.readInt();
dataLength = (int)dis.readUnsignedShort();
samples = (int)dis.readUnsignedShort();
for(int idx = 0; idx < dataLength; idx++)
{
OneByteChunk anX = new OneByteChunk();
anX.unmarshal(dis);
data.add(anX);
}

data = new byte[dataLength];
dis.read(data);
} // end try
catch(Exception e)
{
Expand All @@ -205,15 +190,9 @@ public void marshal(java.nio.ByteBuffer buff)
buff.putShort( (short)encodingScheme);
buff.putShort( (short)tdlType);
buff.putInt( (int)sampleRate);
buff.putShort( (short)data.size());
buff.putShort( (short)data.length);
buff.putShort( (short)samples);

for(int idx = 0; idx < data.size(); idx++)
{
OneByteChunk aOneByteChunk = (OneByteChunk)data.get(idx);
aOneByteChunk.marshal(buff);
} // end of list marshalling

buff.put(data);
} // end of marshal method

/**
Expand All @@ -234,13 +213,8 @@ public void unmarshal(java.nio.ByteBuffer buff)
sampleRate = buff.getInt();
dataLength = (int)(buff.getShort() & 0xFFFF);
samples = (int)(buff.getShort() & 0xFFFF);
for(int idx = 0; idx < dataLength; idx++)
{
OneByteChunk anX = new OneByteChunk();
anX.unmarshal(buff);
data.add(anX);
}

data = new byte[dataLength];
buff.get(data);
} // end of unmarshal method


Expand Down Expand Up @@ -282,12 +256,7 @@ public boolean equalsImpl(Object obj)
if( ! (sampleRate == rhs.sampleRate)) ivarsEqual = false;
if( ! (dataLength == rhs.dataLength)) ivarsEqual = false;
if( ! (samples == rhs.samples)) ivarsEqual = false;

for(int idx = 0; idx < data.size(); idx++)
{
if( ! ( data.get(idx).equals(rhs.data.get(idx)))) ivarsEqual = false;
}

if( ! (Arrays.equals(data, rhs.data))) ivarsEqual = false;

return ivarsEqual && super.equalsImpl(rhs);
}
Expand Down
Loading

0 comments on commit 3614c4b

Please sign in to comment.