Skip to content

Commit 4f8cf89

Browse files
committed
vtype-json: adding support for all unsigned scalar integers
1 parent 0a3d280 commit 4f8cf89

6 files changed

Lines changed: 104 additions & 2 deletions

File tree

epics-vtype/vtype-json/src/main/java/org/epics/vtype/json/JsonVTypeBuilder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
import static org.epics.vtype.json.JsonArrays.*;
1717
import org.epics.util.array.ListBoolean;
1818
import org.epics.util.array.ListNumber;
19+
import org.epics.util.number.UByte;
20+
import org.epics.util.number.UInteger;
1921
import org.epics.util.number.ULong;
22+
import org.epics.util.number.UShort;
2023
import org.epics.vtype.Alarm;
2124
import org.epics.vtype.Display;
2225
import org.epics.vtype.Time;
@@ -203,9 +206,9 @@ public JsonVTypeBuilder addObject(String string, Object o) {
203206

204207
if (o instanceof Double || o instanceof Float) {
205208
add(string, ((Number) o).doubleValue());
206-
} else if (o instanceof Byte || o instanceof Short || o instanceof Integer) {
209+
} else if (o instanceof Integer || o instanceof UShort || o instanceof Short || o instanceof UByte || o instanceof Byte) {
207210
add(string, ((Number) o).intValue());
208-
} else if (o instanceof Long) {
211+
} else if (o instanceof Long || o instanceof UInteger) {
209212
add(string, ((Number) o).longValue());
210213
} else if (o instanceof ULong) {
211214
add(string, ((ULong) o).bigIntegerValue());

epics-vtype/vtype-json/src/main/java/org/epics/vtype/json/VTypeToJsonV1.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import java.util.List;
88
import javax.json.JsonObject;
99
import org.epics.util.array.ListNumber;
10+
import org.epics.util.number.UByte;
11+
import org.epics.util.number.UInteger;
1012
import org.epics.util.number.ULong;
13+
import org.epics.util.number.UShort;
1114
import org.epics.vtype.EnumDisplay;
1215
import org.epics.vtype.VEnum;
1316
import org.epics.vtype.VNumber;
@@ -27,8 +30,11 @@ static VType toVType(JsonObject json) {
2730
case "VFloat":
2831
case "VULong":
2932
case "VLong":
33+
case "VUInt":
3034
case "VInt":
35+
case "VUShort":
3136
case "VShort":
37+
case "VUByte":
3238
case "VByte":
3339
return toVNumber(json);
3440
case "VDoubleArray":
@@ -84,12 +90,21 @@ static VNumber toVNumber(JsonObject json) {
8490
case "VLong":
8591
value = (long) mapper.getJsonNumber("value").longValue();
8692
break;
93+
case "VUInt":
94+
value = new UInteger(mapper.getJsonNumber("value").intValue());
95+
break;
8796
case "VInt":
8897
value = (int) mapper.getJsonNumber("value").intValue();
8998
break;
99+
case "VUShort":
100+
value = new UShort((short) mapper.getJsonNumber("value").intValue());
101+
break;
90102
case "VShort":
91103
value = (short) mapper.getJsonNumber("value").intValue();
92104
break;
105+
case "VUByte":
106+
value = new UByte((byte) mapper.getJsonNumber("value").intValue());
107+
break;
93108
case "VByte":
94109
value = (byte) mapper.getJsonNumber("value").intValue();
95110
break;

epics-vtype/vtype-json/src/test/java/org/epics/vtype/json/VTypeToJsonTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
import org.epics.util.array.ArrayInteger;
2323
import org.epics.util.array.ArrayLong;
2424
import org.epics.util.array.ArrayShort;
25+
import org.epics.util.number.UByte;
26+
import org.epics.util.number.UInteger;
2527
import org.epics.util.number.ULong;
28+
import org.epics.util.number.UShort;
2629
import org.epics.vtype.Alarm;
2730
import org.epics.vtype.AlarmSeverity;
2831
import org.epics.vtype.AlarmStatus;
@@ -44,7 +47,10 @@
4447
import org.epics.vtype.VShortArray;
4548
import org.epics.vtype.VString;
4649
import org.epics.vtype.VType;
50+
import org.epics.vtype.VUByte;
51+
import org.epics.vtype.VUInt;
4752
import org.epics.vtype.VULong;
53+
import org.epics.vtype.VUShort;
4854
import org.junit.Test;
4955
import static org.junit.Assert.*;
5056
import static org.hamcrest.Matchers.*;
@@ -186,6 +192,13 @@ public void vLong1() {
186192
testDeserialization("VLong1a", vLong1);
187193
}
188194

195+
@Test
196+
public void vUInt1() {
197+
VUInt vUInt1 = VUInt.of(new UInteger(-1), Alarm.none(), Time.of(Instant.ofEpochSecond(0, 0)), Display.none());
198+
testSerialization(vUInt1, "VUInt1");
199+
testDeserialization("VUInt1", vUInt1);
200+
}
201+
189202
@Test
190203
public void vInt1() {
191204
VInt vInt1 = VInt.of(314, Alarm.none(), Time.of(Instant.ofEpochSecond(0, 0)), Display.none());
@@ -194,6 +207,13 @@ public void vInt1() {
194207
testDeserialization("VInt1a", vInt1);
195208
}
196209

210+
@Test
211+
public void vUShort1() {
212+
VUShort vUShort1 = VUShort.of(new UShort((short) -1), Alarm.of(AlarmSeverity.MINOR, AlarmStatus.DB, "HIGH"), Time.of(Instant.ofEpochSecond(0, 0)), Display.none());
213+
testSerialization(vUShort1, "VUShort1");
214+
testDeserialization("VUShort1", vUShort1);
215+
}
216+
197217
@Test
198218
public void vShort1() {
199219
VShort vShort1 = VShort.of((short) 314, Alarm.none(), Time.of(Instant.ofEpochSecond(0, 0)), Display.none());
@@ -202,6 +222,13 @@ public void vShort1() {
202222
testDeserialization("VShort1a", vShort1);
203223
}
204224

225+
@Test
226+
public void vUByte1() {
227+
VUByte vUByte1 = VUByte.of(new UByte((byte) -1), Alarm.of(AlarmSeverity.MINOR, AlarmStatus.DB, "HIGH"), Time.of(Instant.ofEpochSecond(0, 0)), Display.none());
228+
testSerialization(vUByte1, "VUByte1");
229+
testDeserialization("VUByte1", vUByte1);
230+
}
231+
205232
@Test
206233
public void vByte1() {
207234
VByte vByte1 = VByte.of((byte) 31, Alarm.none(), Time.of(Instant.ofEpochSecond(0, 0)), Display.none());
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"type":{
3+
"name":"VUByte",
4+
"version":1
5+
},
6+
"value":255,
7+
"alarm":{
8+
"severity":"MINOR",
9+
"status":"DB",
10+
"name":"HIGH"
11+
},
12+
"time":{
13+
"unixSec":0,
14+
"nanoSec":0
15+
},
16+
"display":{
17+
"units":""
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"type":{
3+
"name":"VUInt",
4+
"version":1
5+
},
6+
"value":4294967295,
7+
"alarm":{
8+
"severity":"NONE",
9+
"status":"NONE",
10+
"name":"None"
11+
},
12+
"time":{
13+
"unixSec":0,
14+
"nanoSec":0
15+
},
16+
"display":{
17+
"units":""
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"type":{
3+
"name":"VUShort",
4+
"version":1
5+
},
6+
"value":65535,
7+
"alarm":{
8+
"severity":"MINOR",
9+
"status":"DB",
10+
"name":"HIGH"
11+
},
12+
"time":{
13+
"unixSec":0,
14+
"nanoSec":0
15+
},
16+
"display":{
17+
"units":""
18+
}
19+
}

0 commit comments

Comments
 (0)