Skip to content

Commit

Permalink
fix(code-gen/java): Updated the codegen for java to generally use sma…
Browse files Browse the repository at this point in the history
…ller types for unsigned integers (a byte is able to keep an unsigned integer value to 7 bits and not up to 4 bits)
  • Loading branch information
chrisdutz committed Jul 21, 2023
1 parent 8772f90 commit 3917dab
Show file tree
Hide file tree
Showing 72 changed files with 456 additions and 462 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static PlcValue staticParse(
value = new LinkedList<>();
for (int curItem = 0; curItem < itemCount; curItem++) {
value.add(
new PlcUINT(
new PlcUSINT(
(Short) /*TODO: migrate me*/ /*TODO: migrate me*/
readBuffer.readUnsignedShort("", 8)));
}
Expand Down Expand Up @@ -291,7 +291,7 @@ public static PlcValue staticParse(
value = new LinkedList<>();
for (int curItem = 0; curItem < itemCount; curItem++) {
value.add(
new PlcUINT(
new PlcUSINT(
(Short) /*TODO: migrate me*/ /*TODO: migrate me*/
readBuffer.readUnsignedShort("", 8)));
}
Expand Down Expand Up @@ -321,7 +321,7 @@ public static PlcValue staticParse(
value = new LinkedList<>();
for (int curItem = 0; curItem < itemCount; curItem++) {
value.add(
new PlcUDINT(
new PlcUINT(
(Integer) /*TODO: migrate me*/ /*TODO: migrate me*/
readBuffer.readUnsignedInt("", 16)));
}
Expand Down Expand Up @@ -351,7 +351,7 @@ public static PlcValue staticParse(
value = new LinkedList<>();
for (int curItem = 0; curItem < itemCount; curItem++) {
value.add(
new PlcULINT(
new PlcUDINT(
(Long) /*TODO: migrate me*/ /*TODO: migrate me*/
readBuffer.readUnsignedLong("", 32)));
}
Expand Down Expand Up @@ -382,7 +382,7 @@ public static PlcValue staticParse(
value = new LinkedList<>();
for (int curItem = 0; curItem < itemCount; curItem++) {
value.add(
new PlcLINT(
new PlcULINT(
(BigInteger) /*TODO: migrate me*/ /*TODO: migrate me*/
readBuffer.readUnsignedBigInteger("", 64)));
}
Expand Down Expand Up @@ -620,7 +620,7 @@ public static PlcValue staticParse(
value = new LinkedList<>();
for (int curItem = 0; curItem < itemCount; curItem++) {
value.add(
new PlcUINT(
new PlcUSINT(
(Short) /*TODO: migrate me*/ /*TODO: migrate me*/
readBuffer.readUnsignedShort("", 8)));
}
Expand All @@ -643,7 +643,7 @@ public static PlcValue staticParse(
value = new LinkedList<>();
for (int curItem = 0; curItem < itemCount; curItem++) {
value.add(
new PlcUINT(
new PlcUSINT(
(Short) /*TODO: migrate me*/ /*TODO: migrate me*/
readBuffer.readUnsignedShort("", 8)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public class DceRpc_ObjectUuid implements Message {

// Properties.
protected final byte interfaceNumber;
protected final int nodeNumber;
protected final short nodeNumber;
protected final int deviceId;
protected final int vendorId;

public DceRpc_ObjectUuid(byte interfaceNumber, int nodeNumber, int deviceId, int vendorId) {
public DceRpc_ObjectUuid(byte interfaceNumber, short nodeNumber, int deviceId, int vendorId) {
super();
this.interfaceNumber = interfaceNumber;
this.nodeNumber = nodeNumber;
Expand All @@ -61,7 +61,7 @@ public byte getInterfaceNumber() {
return interfaceNumber;
}

public int getNodeNumber() {
public short getNodeNumber() {
return nodeNumber;
}

Expand Down Expand Up @@ -121,7 +121,7 @@ public void serialize(WriteBuffer writeBuffer) throws SerializationException {
writeSimpleField(
"nodeNumber",
nodeNumber,
writeUnsignedInt(writeBuffer, 12),
writeUnsignedShort(writeBuffer, 12),
WithOption.WithByteOrder(ByteOrder.BIG_ENDIAN));

// Simple Field (deviceId)
Expand Down Expand Up @@ -209,10 +209,10 @@ public static DceRpc_ObjectUuid staticParse(ReadBuffer readBuffer) throws ParseE
readUnsignedByte(readBuffer, 4),
WithOption.WithByteOrder(ByteOrder.BIG_ENDIAN));

int nodeNumber =
short nodeNumber =
readSimpleField(
"nodeNumber",
readUnsignedInt(readBuffer, 12),
readUnsignedShort(readBuffer, 12),
WithOption.WithByteOrder(ByteOrder.BIG_ENDIAN));

int deviceId =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class DceRpc_Packet implements Message {
// Reserved Fields
private Boolean reservedField0;
private Boolean reservedField1;
private Short reservedField2;
private Byte reservedField2;
private Boolean reservedField3;
private Short reservedField4;

Expand Down Expand Up @@ -291,8 +291,8 @@ public void serialize(WriteBuffer writeBuffer) throws SerializationException {
// Reserved Field (reserved)
writeReservedField(
"reserved",
reservedField2 != null ? reservedField2 : (short) 0x00,
writeUnsignedShort(writeBuffer, 6),
reservedField2 != null ? reservedField2 : (byte) 0x00,
writeUnsignedByte(writeBuffer, 6),
WithOption.WithByteOrder(ByteOrder.BIG_ENDIAN));

// Const Field (cancelWasPending)
Expand Down Expand Up @@ -685,11 +685,11 @@ public static DceRpc_Packet staticParse(ReadBuffer readBuffer) throws ParseExcep
(boolean) false,
WithOption.WithByteOrder(ByteOrder.BIG_ENDIAN));

Short reservedField2 =
Byte reservedField2 =
readReservedField(
"reserved",
readUnsignedShort(readBuffer, 6),
(short) 0x00,
readUnsignedByte(readBuffer, 6),
(byte) 0x00,
WithOption.WithByteOrder(ByteOrder.BIG_ENDIAN));

boolean cancelWasPending =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public TlvType getTlvId() {
return TlvType.END_OF_LLDP;
}

public EndOfLldp(int tlvIdLength) {
public EndOfLldp(short tlvIdLength) {
super(tlvIdLength);
}

Expand Down Expand Up @@ -84,7 +84,7 @@ public static class EndOfLldpBuilderImpl implements LldpUnit.LldpUnitBuilder {

public EndOfLldpBuilderImpl() {}

public EndOfLldp build(int tlvIdLength) {
public EndOfLldp build(short tlvIdLength) {
EndOfLldp endOfLldp = new EndOfLldp(tlvIdLength);
return endOfLldp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public Integer getPacketType() {
// Constant values.
public static final Byte VERSION = 0x4;
public static final Byte HEADERLENGTH = 0x5;
public static final Short DIFFERENTIATEDSERVICESCODEPOINT = 0x00;
public static final Byte DIFFERENTIATEDSERVICESCODEPOINT = 0x00;
public static final Byte EXPLICITCONGESTIONNOTIFICATION = 0x0;
public static final Integer FRAGMENTOFFSET = 0x00;
public static final Short FRAGMENTOFFSET = 0x00;
public static final Short PROTOCOL = 0x11;

// Properties.
Expand Down Expand Up @@ -130,15 +130,15 @@ public byte getHeaderLength() {
return HEADERLENGTH;
}

public short getDifferentiatedServicesCodepoint() {
public byte getDifferentiatedServicesCodepoint() {
return DIFFERENTIATEDSERVICESCODEPOINT;
}

public byte getExplicitCongestionNotification() {
return EXPLICITCONGESTIONNOTIFICATION;
}

public int getFragmentOffset() {
public short getFragmentOffset() {
return FRAGMENTOFFSET;
}

Expand All @@ -163,7 +163,7 @@ protected void serializeEthernet_FramePayloadChild(WriteBuffer writeBuffer)
writeConstField(
"differentiatedServicesCodepoint",
DIFFERENTIATEDSERVICESCODEPOINT,
writeUnsignedShort(writeBuffer, 6));
writeUnsignedByte(writeBuffer, 6));

// Const Field (explicitCongestionNotification)
writeConstField(
Expand Down Expand Up @@ -192,7 +192,7 @@ protected void serializeEthernet_FramePayloadChild(WriteBuffer writeBuffer)
writeSimpleField("moreFragments", moreFragments, writeBoolean(writeBuffer));

// Const Field (fragmentOffset)
writeConstField("fragmentOffset", FRAGMENTOFFSET, writeUnsignedInt(writeBuffer, 13));
writeConstField("fragmentOffset", FRAGMENTOFFSET, writeUnsignedShort(writeBuffer, 13));

// Simple Field (timeToLive)
writeSimpleField("timeToLive", timeToLive, writeUnsignedShort(writeBuffer, 8));
Expand Down Expand Up @@ -339,10 +339,10 @@ public static Ethernet_FramePayloadBuilder staticParseEthernet_FramePayloadBuild
readUnsignedByte(readBuffer, 4),
Ethernet_FramePayload_IPv4.HEADERLENGTH);

short differentiatedServicesCodepoint =
byte differentiatedServicesCodepoint =
readConstField(
"differentiatedServicesCodepoint",
readUnsignedShort(readBuffer, 6),
readUnsignedByte(readBuffer, 6),
Ethernet_FramePayload_IPv4.DIFFERENTIATEDSERVICESCODEPOINT);

byte explicitCongestionNotification =
Expand All @@ -362,10 +362,10 @@ public static Ethernet_FramePayloadBuilder staticParseEthernet_FramePayloadBuild

boolean moreFragments = readSimpleField("moreFragments", readBoolean(readBuffer));

int fragmentOffset =
short fragmentOffset =
readConstField(
"fragmentOffset",
readUnsignedInt(readBuffer, 13),
readUnsignedShort(readBuffer, 13),
Ethernet_FramePayload_IPv4.FRAGMENTOFFSET);

short timeToLive = readSimpleField("timeToLive", readUnsignedShort(readBuffer, 8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public Integer getPacketType() {
// Properties.
protected final VirtualLanPriority priority;
protected final boolean ineligible;
protected final int id;
protected final short id;
protected final Ethernet_FramePayload payload;

public Ethernet_FramePayload_VirtualLan(
VirtualLanPriority priority, boolean ineligible, int id, Ethernet_FramePayload payload) {
VirtualLanPriority priority, boolean ineligible, short id, Ethernet_FramePayload payload) {
super();
this.priority = priority;
this.ineligible = ineligible;
Expand All @@ -65,7 +65,7 @@ public boolean getIneligible() {
return ineligible;
}

public int getId() {
public short getId() {
return id;
}

Expand Down Expand Up @@ -94,7 +94,7 @@ protected void serializeEthernet_FramePayloadChild(WriteBuffer writeBuffer)
writeSimpleField("ineligible", ineligible, writeBoolean(writeBuffer));

// Simple Field (id)
writeSimpleField("id", id, writeUnsignedInt(writeBuffer, 12));
writeSimpleField("id", id, writeUnsignedShort(writeBuffer, 12));

// Simple Field (payload)
writeSimpleField("payload", payload, new DataWriterComplexDefault<>(writeBuffer));
Expand Down Expand Up @@ -143,7 +143,7 @@ public static Ethernet_FramePayloadBuilder staticParseEthernet_FramePayloadBuild

boolean ineligible = readSimpleField("ineligible", readBoolean(readBuffer));

int id = readSimpleField("id", readUnsignedInt(readBuffer, 12));
short id = readSimpleField("id", readUnsignedShort(readBuffer, 12));

Ethernet_FramePayload payload =
readSimpleField(
Expand All @@ -160,11 +160,11 @@ public static class Ethernet_FramePayload_VirtualLanBuilderImpl
implements Ethernet_FramePayload.Ethernet_FramePayloadBuilder {
private final VirtualLanPriority priority;
private final boolean ineligible;
private final int id;
private final short id;
private final Ethernet_FramePayload payload;

public Ethernet_FramePayload_VirtualLanBuilderImpl(
VirtualLanPriority priority, boolean ineligible, int id, Ethernet_FramePayload payload) {
VirtualLanPriority priority, boolean ineligible, short id, Ethernet_FramePayload payload) {
this.priority = priority;
this.ineligible = ineligible;
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public abstract class LldpUnit implements Message {
public abstract TlvType getTlvId();

// Properties.
protected final int tlvIdLength;
protected final short tlvIdLength;

public LldpUnit(int tlvIdLength) {
public LldpUnit(short tlvIdLength) {
super();
this.tlvIdLength = tlvIdLength;
}

public int getTlvIdLength() {
public short getTlvIdLength() {
return tlvIdLength;
}

Expand All @@ -66,10 +66,10 @@ public void serialize(WriteBuffer writeBuffer) throws SerializationException {
"TlvType",
getTlvId(),
new DataWriterEnumDefault<>(
TlvType::getValue, TlvType::name, writeUnsignedShort(writeBuffer, 7)));
TlvType::getValue, TlvType::name, writeUnsignedByte(writeBuffer, 7)));

// Simple Field (tlvIdLength)
writeSimpleField("tlvIdLength", tlvIdLength, writeUnsignedInt(writeBuffer, 9));
writeSimpleField("tlvIdLength", tlvIdLength, writeUnsignedShort(writeBuffer, 9));

// Switch field (Serialize the sub-type)
serializeLldpUnitChild(writeBuffer);
Expand Down Expand Up @@ -112,9 +112,9 @@ public static LldpUnit staticParse(ReadBuffer readBuffer) throws ParseException
TlvType tlvId =
readDiscriminatorField(
"tlvId",
new DataReaderEnumDefault<>(TlvType::enumForValue, readUnsignedShort(readBuffer, 7)));
new DataReaderEnumDefault<>(TlvType::enumForValue, readUnsignedByte(readBuffer, 7)));

int tlvIdLength = readSimpleField("tlvIdLength", readUnsignedInt(readBuffer, 9));
short tlvIdLength = readSimpleField("tlvIdLength", readUnsignedShort(readBuffer, 9));

// Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type)
LldpUnitBuilder builder = null;
Expand Down Expand Up @@ -151,7 +151,7 @@ public static LldpUnit staticParse(ReadBuffer readBuffer) throws ParseException
}

public interface LldpUnitBuilder {
LldpUnit build(int tlvIdLength);
LldpUnit build(short tlvIdLength);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public PnIoCm_BlockType getBlockType() {
// Constant values.
public static final Integer PADFIELD = 0x0000;
public static final Integer MULTIPLEINTERFACEMODERESERVED2 = 0x0000;
public static final Integer MULTIPLEINTERFACEMODERESERVED1 = 0x0000;
public static final Short MULTIPLEINTERFACEMODERESERVED1 = 0x0000;

// Properties.
protected final short blockVersionHigh;
Expand Down Expand Up @@ -82,7 +82,7 @@ public int getMultipleInterfaceModeReserved2() {
return MULTIPLEINTERFACEMODERESERVED2;
}

public int getMultipleInterfaceModeReserved1() {
public short getMultipleInterfaceModeReserved1() {
return MULTIPLEINTERFACEMODERESERVED1;
}

Expand Down Expand Up @@ -133,7 +133,7 @@ protected void serializePnIoCm_BlockChild(WriteBuffer writeBuffer) throws Serial
writeConstField(
"multipleInterfaceModeReserved1",
MULTIPLEINTERFACEMODERESERVED1,
writeUnsignedInt(writeBuffer, 15),
writeUnsignedShort(writeBuffer, 15),
WithOption.WithByteOrder(ByteOrder.BIG_ENDIAN));

// Simple Field (multipleInterfaceModeNameOfDevice)
Expand Down Expand Up @@ -223,10 +223,10 @@ public static PnIoCm_BlockBuilder staticParsePnIoCm_BlockBuilder(ReadBuffer read
PDInterfaceAdjust.MULTIPLEINTERFACEMODERESERVED2,
WithOption.WithByteOrder(ByteOrder.BIG_ENDIAN));

int multipleInterfaceModeReserved1 =
short multipleInterfaceModeReserved1 =
readConstField(
"multipleInterfaceModeReserved1",
readUnsignedInt(readBuffer, 15),
readUnsignedShort(readBuffer, 15),
PDInterfaceAdjust.MULTIPLEINTERFACEMODERESERVED1,
WithOption.WithByteOrder(ByteOrder.BIG_ENDIAN));

Expand Down
Loading

0 comments on commit 3917dab

Please sign in to comment.