Skip to content

Commit 9568f86

Browse files
authored
0.9.2
Fix binary date type IO. Fix already parented exceptions for lists and maps. Added dynamic value type, and use it with DSNull.
1 parent 0a658de commit 9568f86

File tree

9 files changed

+41
-32
lines changed

9 files changed

+41
-32
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'java'
22
apply plugin: 'maven'
33

44
group 'org.iot.dsa'
5-
version '0.9.1'
5+
version '0.9.2'
66

77
sourceCompatibility = 1.6
88
targetCompatibility = 1.6

dslink-core/src/main/java/org/iot/dsa/io/NodeDecoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public static DSNode decode(DSIReader in) {
5454
}
5555

5656
/**
57-
* Will create new instances for DSNodes, or return the NULL instance for DSIValues.
57+
* Will create new instances for anything without a decoder, otherwise returns the decoder
58+
* instance.
5859
*/
5960
private DSIObject getInstance(String type) {
6061
DSIObject ret = null;

dslink-core/src/main/java/org/iot/dsa/io/NodeEncoder.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void writeObject(DSInfo arg) {
160160
}
161161
if (!arg.equalsDefaultType()) {
162162
DSIObject obj = arg.getObject();
163-
if (obj != null) {
163+
if ((obj != null) && !(obj instanceof DSElement)) {
164164
out.key("t").value(getToken(obj));
165165
}
166166
}
@@ -179,7 +179,9 @@ void writeValue(DSInfo arg) {
179179
if (!arg.equalsDefaultType()) {
180180
DSIValue v = (DSIValue) arg.getObject();
181181
if (v != null) {
182-
out.key("t").value(getToken(v));
182+
if (!(v instanceof DSElement)) {
183+
out.key("t").value(getToken(v));
184+
}
183185
out.key("v").value(v.store());
184186
} else {
185187
out.key("v").value((String) null);
@@ -195,12 +197,4 @@ void writeValue(DSInfo arg) {
195197
out.endMap();
196198
}
197199

198-
///////////////////////////////////////////////////////////////////////////
199-
// Inner Classes
200-
///////////////////////////////////////////////////////////////////////////
201-
202-
///////////////////////////////////////////////////////////////////////////
203-
// Initialization
204-
///////////////////////////////////////////////////////////////////////////
205-
206200
}

dslink-core/src/main/java/org/iot/dsa/node/DSBytes.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import org.iot.dsa.io.DSBase64;
55

66
/**
7-
* A Java float. Try not to use, floats can only be converted to doubles by first converting them
8-
* to strings.
7+
* Byte array that gets encoded as a base64 string.
98
*
109
* @author Aaron Hansen
1110
*/
@@ -15,6 +14,7 @@ public class DSBytes extends DSValue {
1514
// ---------
1615

1716
public static final DSBytes NULL = new DSBytes(new byte[0]);
17+
private static final String PREFIX = "\u001Bbytes:";
1818

1919
// Fields
2020
// ------
@@ -91,7 +91,7 @@ public String toString() {
9191
if (isNull()) {
9292
return "null";
9393
}
94-
return DSBase64.encodeUrl(value);
94+
return PREFIX + DSBase64.encodeUrl(value);
9595
}
9696

9797
@Override
@@ -116,6 +116,9 @@ public static DSBytes valueOf(String arg) {
116116
} else if (arg.equalsIgnoreCase("null")) {
117117
return NULL;
118118
}
119+
if (arg.startsWith(PREFIX)) {
120+
arg = arg.substring(PREFIX.length());
121+
}
119122
return new DSBytes(DSBase64.decode(arg));
120123
}
121124

dslink-core/src/main/java/org/iot/dsa/node/DSList.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,20 +321,12 @@ public DSElement next() {
321321
}
322322

323323
/**
324-
* Not implements, throws an exception.
324+
* Not implemented, throws an exception.
325325
*/
326326
@Override
327327
public void remove() {
328328
throw new IllegalStateException("Not implemented");
329329
}
330330
}
331331

332-
// Initialization
333-
// --------------
334-
335-
static {
336-
DSRegistry.registerDecoder(DSList.class, new DSList());
337-
}
338-
339-
340332
}

dslink-core/src/main/java/org/iot/dsa/node/DSMap.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -550,11 +550,4 @@ void setValue(DSElement val) {
550550
}
551551
}
552552

553-
// Initialization
554-
// --------------
555-
556-
static {
557-
DSRegistry.registerDecoder(DSMap.class, new DSMap());
558-
}
559-
560553
}

dslink-core/src/main/java/org/iot/dsa/node/DSNull.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public boolean equals(Object arg) {
5858

5959
@Override
6060
public DSValueType getValueType() {
61-
return null;
61+
return DSValueType.DYNAMIC;
6262
}
6363

6464
/**

dslink-core/src/main/java/org/iot/dsa/node/DSValueType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public enum DSValueType {
1010

1111
BINARY("binary"),
1212
BOOL("bool"),
13+
DYNAMIC("dynamic"),
1314
ENUM("enum"),
1415
LIST("array"),
1516
MAP("map"),

dslink-core/src/test/java/org/iot/dsa/dslink/SerializationTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.iot.dsa.io.json.JsonWriter;
1111
import org.iot.dsa.node.DSFloat;
1212
import org.iot.dsa.node.DSInt;
13+
import org.iot.dsa.node.DSList;
14+
import org.iot.dsa.node.DSMap;
1315
import org.iot.dsa.node.DSNode;
1416
import org.iot.dsa.node.DSString;
1517
import org.junit.Assert;
@@ -78,6 +80,29 @@ public void theTest() throws Exception {
7880
Assert.assertTrue(orig.equals(decoded));
7981
}
8082

83+
/**
84+
* Testing an "Already parented" bug that cropped up.
85+
*/
86+
@Test
87+
public void testMultipleGroups() throws Exception {
88+
DSNode node = new MyNode();
89+
DSList list = new DSList();
90+
list.add("a").add("b").add("c");
91+
node.put("first", list);
92+
list = new DSList();
93+
list.add("d").add("e").add("f");
94+
node.put("second", list);
95+
node = decode(encode(node));
96+
list = (DSList) node.get("first");
97+
Assert.assertTrue(list.getString(0).equals("a"));
98+
Assert.assertTrue(list.getString(1).equals("b"));
99+
Assert.assertTrue(list.getString(2).equals("c"));
100+
list = (DSList) node.get("second");
101+
Assert.assertTrue(list.getString(0).equals("d"));
102+
Assert.assertTrue(list.getString(1).equals("e"));
103+
Assert.assertTrue(list.getString(2).equals("f"));
104+
}
105+
81106
// Inner Classes
82107
// -------------
83108

0 commit comments

Comments
 (0)