Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public final int getOctetBoundary() {
@Override
public final int getEncodedLength(int position, Object value) throws OOcodecException {
if (value == null) {
throw new InvalidValue("Invalid null value for enumerator");
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

// not allowed to encode the HLA_UNKNOWN_ENUM
Expand Down Expand Up @@ -213,7 +213,7 @@ public final int getEncodedLength(int position, Object value) throws OOcodecExce
@Override
public final void encode(ByteArrayWrapper byteWrapper, Object value) throws OOcodecException {
if (value == null) {
throw new InvalidValue("Invalid null value for enumerator");
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

if (value == this.unknownEnum) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class HLAextendableVariantRecordCodec extends HLAvariantRecordCodec {

@Override
public int getEncodedLength(int position, Object value) throws OOcodecException {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

try {
// save start position
int offset = position;
Expand Down Expand Up @@ -77,6 +81,10 @@ public int getOctetBoundary() {

@Override
public void encode(ByteArrayWrapper byteWrapper, Object value) throws OOcodecException {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

try {
// save start position
int offset = byteWrapper.getPos();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ public final int getOctetBoundary() {

@Override
public final int getEncodedLength(int position, Object value) throws OOcodecException {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + this.componentName);
}

switch (this.datatype) {
default:
case ARRAY:
Expand Down Expand Up @@ -250,6 +254,10 @@ public final int getEncodedLength(int position, Object value) throws OOcodecExce

@Override
public final void encode(ByteArrayWrapper byteWrapper, Object value) throws OOcodecException {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + this.componentName);
}

switch (this.datatype) {
default:
case ARRAY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import nl.tno.omt.helpers.OmtJavaMapping;
import nl.tno.oorti.ooencoder.exceptions.InvalidClassStructure;
import nl.tno.oorti.ooencoder.exceptions.InvalidType;
import nl.tno.oorti.ooencoder.exceptions.InvalidValue;
import nl.tno.oorti.ooencoder.exceptions.OOcodecException;

/**
Expand Down Expand Up @@ -149,14 +150,33 @@ public final int getOctetBoundary() {

@Override
public final int getEncodedLength(int position, Object value) throws OOcodecException {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

try {
if (memberAccessors.length > 0) {
for (int i = 0; i < memberFieldCodecs.length - 1; i++) {
// add size of component i
OmtDatatypeCodec codec = memberFieldCodecs[i];
Accessor accessor = this.memberAccessors[i];
position =
codec.getEncodedLength(position, accessor == null ? null : accessor.get(value));

if (accessor != null) {
Object fieldValue = accessor.get(value);
if (fieldValue == null) {
throw new InvalidValue(
"Invalid null value for field "
+ this.memberNames[i]
+ " of datatype "
+ dt.getName().getValue());
}

position = codec.getEncodedLength(position, fieldValue);
} else {
// this is a field with a padding encoding, use a null value
// and the padding codec must return the padding length
position = codec.getEncodedLength(position, null);
}

// add padding
position += this.paddingSize(position, memberFieldCodecs[i + 1].getOctetBoundary());
Expand All @@ -165,7 +185,23 @@ public final int getEncodedLength(int position, Object value) throws OOcodecExce
// add size of last component
OmtDatatypeCodec codec = memberFieldCodecs[memberFieldCodecs.length - 1];
Accessor accessor = this.memberAccessors[memberFieldCodecs.length - 1];
position = codec.getEncodedLength(position, accessor == null ? null : accessor.get(value));

if (accessor != null) {
Object fieldValue = accessor.get(value);
if (fieldValue == null) {
throw new InvalidValue(
"Invalid null value for field "
+ this.memberNames[memberFieldCodecs.length - 1]
+ " of datatype "
+ dt.getName().getValue());
}

position = codec.getEncodedLength(position, fieldValue);
} else {
// this is a field with a padding encoding, use a null value
// and the padding codec must return the padding length
position = codec.getEncodedLength(position, null);
}
}

return position;
Expand All @@ -176,6 +212,10 @@ public final int getEncodedLength(int position, Object value) throws OOcodecExce

@Override
public final void encode(ByteArrayWrapper byteWrapper, Object value) throws OOcodecException {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

try {
if (memberAccessors.length > 0) {
for (int i = 0; i < memberAccessors.length - 1; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class HLAfloat32BECodec implements OmtBasicDatatypeCodec {
static final int OCTETBOUNDARY = 4;
static final int ENCODEDLENGTH = 4;

final BasicData dt;

HLAfloat32BECodec(OmtCodecFactory codecFactory, Type type, BasicData dt)
throws InvalidType, InvalidClassStructure {
Class clazz = (Class) type;
Expand All @@ -24,9 +26,15 @@ class HLAfloat32BECodec implements OmtBasicDatatypeCodec {
throw new InvalidClassStructure("Missing Type");
}

if (dt == null) {
throw new InvalidType("Missing OMT datatype");
}

if (!clazz.equals(Float.class) && !clazz.equals(float.class)) {
throw new InvalidType("Expected Float class, but got " + clazz.getSimpleName());
}

this.dt = dt;
}

@Override
Expand All @@ -53,13 +61,21 @@ public final int getOctetBoundary() {
}

@Override
public final int getEncodedLength(int position, Object value) {
public final int getEncodedLength(int position, Object value) throws InvalidValue {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

return position + ENCODEDLENGTH;
}

@Override
public final void encode(ByteArrayWrapper byteWrapper, Object value)
throws ByteWrapperOutOfBoundsException {
throws ByteWrapperOutOfBoundsException, InvalidValue {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

byteWrapper.putFloat((float) value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class HLAfloat64BECodec implements OmtBasicDatatypeCodec {
static final int OCTETBOUNDARY = 8;
static final int ENCODEDLENGTH = 8;

final BasicData dt;

HLAfloat64BECodec(OmtCodecFactory codecFactory, Type type, BasicData dt)
throws InvalidType, InvalidClassStructure {
Class clazz = (Class) type;
Expand All @@ -24,9 +26,15 @@ class HLAfloat64BECodec implements OmtBasicDatatypeCodec {
throw new InvalidClassStructure("Missing Type");
}

if (dt == null) {
throw new InvalidType("Missing OMT datatype");
}

if (!clazz.equals(Double.class) && !clazz.equals(double.class)) {
throw new InvalidType("Expected Double class, but got " + clazz.getSimpleName());
}

this.dt = dt;
}

@Override
Expand All @@ -53,13 +61,21 @@ public final int getOctetBoundary() {
}

@Override
public final int getEncodedLength(int position, Object value) {
public final int getEncodedLength(int position, Object value) throws InvalidValue {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

return position + ENCODEDLENGTH;
}

@Override
public final void encode(ByteArrayWrapper byteWrapper, Object value)
throws ByteWrapperOutOfBoundsException {
throws ByteWrapperOutOfBoundsException, InvalidValue {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

byteWrapper.putDouble((double) value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class HLAinteger16BECodec implements OmtBasicDatatypeCodec {

static final int OCTETBOUNDARY = 2;
static final int ENCODEDLENGTH = 2;

final BasicData dt;

HLAinteger16BECodec(OmtCodecFactory codecFactory, Type type, BasicData dt)
throws InvalidType, InvalidClassStructure {
Expand All @@ -24,9 +26,15 @@ class HLAinteger16BECodec implements OmtBasicDatatypeCodec {
throw new InvalidClassStructure("Missing Type");
}

if (dt == null) {
throw new InvalidType("Missing OMT datatype");
}

if (!clazz.equals(Short.class) && !clazz.equals(short.class)) {
throw new InvalidType("Expected Short class, but got " + clazz.getSimpleName());
}

this.dt = dt;
}

@Override
Expand All @@ -53,13 +61,21 @@ public final int getOctetBoundary() {
}

@Override
public final int getEncodedLength(int position, Object value) {
public final int getEncodedLength(int position, Object value) throws InvalidValue {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

return position + ENCODEDLENGTH;
}

@Override
public final void encode(ByteArrayWrapper byteWrapper, Object value)
throws ByteWrapperOutOfBoundsException {
throws ByteWrapperOutOfBoundsException, InvalidValue {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

byteWrapper.putShort((short) value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class HLAinteger32BECodec implements OmtBasicDatatypeCodec {

static final int OCTETBOUNDARY = 4;
static final int ENCODEDLENGTH = 4;

final BasicData dt;

HLAinteger32BECodec(OmtCodecFactory codecFactory, Type type, BasicData dt)
throws InvalidType, InvalidClassStructure {
Expand All @@ -24,9 +26,15 @@ class HLAinteger32BECodec implements OmtBasicDatatypeCodec {
throw new InvalidClassStructure("Missing Type");
}

if (dt == null) {
throw new InvalidType("Missing OMT datatype");
}

if (!clazz.equals(Integer.class) && !clazz.equals(int.class)) {
throw new InvalidType("Expected Integer class, but got " + clazz.getSimpleName());
}

this.dt = dt;
}

@Override
Expand All @@ -53,13 +61,21 @@ public final int getOctetBoundary() {
}

@Override
public final int getEncodedLength(int position, Object value) {
public final int getEncodedLength(int position, Object value) throws InvalidValue {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

return position + ENCODEDLENGTH;
}

@Override
public final void encode(ByteArrayWrapper byteWrapper, Object value)
throws ByteWrapperOutOfBoundsException {
throws ByteWrapperOutOfBoundsException, InvalidValue {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

byteWrapper.putInt((int) value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class HLAinteger64BECodec implements OmtBasicDatatypeCodec {

static final int OCTETBOUNDARY = 8;
static final int ENCODEDLENGTH = 8;

final BasicData dt;

HLAinteger64BECodec(OmtCodecFactory codecFactory, Type type, BasicData dt)
throws InvalidType, InvalidClassStructure {
Expand All @@ -24,9 +26,15 @@ class HLAinteger64BECodec implements OmtBasicDatatypeCodec {
throw new InvalidClassStructure("Missing Type");
}

if (dt == null) {
throw new InvalidType("Missing OMT datatype");
}

if (!clazz.equals(Long.class) && !clazz.equals(long.class)) {
throw new InvalidType("Expected Long class, but got " + clazz.getSimpleName());
}

this.dt = dt;
}

@Override
Expand All @@ -53,13 +61,21 @@ public final int getOctetBoundary() {
}

@Override
public final int getEncodedLength(int position, Object value) {
public final int getEncodedLength(int position, Object value) throws InvalidValue {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

return position + ENCODEDLENGTH;
}

@Override
public final void encode(ByteArrayWrapper byteWrapper, Object value)
throws ByteWrapperOutOfBoundsException {
throws ByteWrapperOutOfBoundsException, InvalidValue {
if (value == null) {
throw new InvalidValue("Invalid null value for datatype " + dt.getName().getValue());
}

byteWrapper.putLong((long) value);
}

Expand Down
Loading
Loading