Skip to content

Commit 8d2c552

Browse files
authored
0.11.0
Msgpack encoder/decoder Fix incomplete lists requests Change DSNode.equals & hashCode Add DSIObject.isEqual Fix path encoding Make DSBytes an element Move TestLink from test to main
1 parent 034deb1 commit 8d2c552

39 files changed

+1716
-131
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.10.0'
5+
version '0.11.0'
66

77
sourceCompatibility = 1.6
88
targetCompatibility = 1.6

dslink-core/src/main/java/com/acuity/iot/dsa/dslink/protocol/protocol_v1/DS1Session.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ protected void processEnvelope(DSIReader reader) {
188188
switch (reader.next()) {
189189
case END_MAP:
190190
return;
191-
case KEY:
191+
case STRING:
192192
break;
193193
default:
194194
throw new IllegalStateException("Poorly formatted request");

dslink-core/src/main/java/com/acuity/iot/dsa/dslink/protocol/protocol_v1/responder/DS1InboundList.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ private void writeChildren(DSIWriter out) {
478478
encodeChild(child, out);
479479
}
480480
if (getResponder().shouldEndMessage()) {
481+
enqueueResponse();
481482
return;
482483
}
483484
}
@@ -500,14 +501,15 @@ private void writeInit(DSIWriter out) {
500501
}
501502

502503
private void writeUpdates(DSIWriter out) {
503-
Update update;
504504
DS1Responder session = getResponder();
505-
while (!session.shouldEndMessage()) {
506-
update = dequeue();
507-
if (update == null) {
505+
Update update = dequeue();
506+
while (update != null) {
507+
encodeUpdate(update, out);
508+
if (session.shouldEndMessage()) {
509+
enqueueResponse();
508510
break;
509511
}
510-
encodeUpdate(update, out);
512+
update = dequeue();
511513
}
512514
}
513515

dslink-core/src/test/java/org/iot/dsa/dslink/TestLink.java renamed to dslink-core/src/main/java/com/acuity/iot/dsa/dslink/test/TestLink.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
package org.iot.dsa.dslink;
1+
package com.acuity.iot.dsa.dslink.test;
22

33
import com.acuity.iot.dsa.dslink.DSTransport;
44
import com.acuity.iot.dsa.dslink.protocol.protocol_v1.DS1ConnectionInit;
55
import com.acuity.iot.dsa.dslink.protocol.protocol_v1.DS1LinkConnection;
66
import com.acuity.iot.dsa.dslink.protocol.protocol_v1.DS1Session;
77
import java.util.logging.Level;
8+
import org.iot.dsa.dslink.DSLink;
9+
import org.iot.dsa.dslink.DSLinkConfig;
10+
import org.iot.dsa.dslink.DSRootNode;
811
import org.iot.dsa.node.DSMap;
912

1013
/**

dslink-core/src/test/java/org/iot/dsa/dslink/TestTransport.java renamed to dslink-core/src/main/java/com/acuity/iot/dsa/dslink/test/TestTransport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package org.iot.dsa.dslink;
1+
package com.acuity.iot.dsa.dslink.test;
22

33
import com.acuity.iot.dsa.dslink.DSTransport;
44
import java.io.IOException;
55
import java.io.InputStream;
66
import java.io.OutputStream;
77
import java.util.logging.Level;
8+
import org.iot.dsa.dslink.DSLinkConnection;
89
import org.iot.dsa.io.DSByteBuffer;
910
import org.iot.dsa.io.DSIoException;
1011
import org.iot.dsa.io.DSIReader;

dslink-core/src/main/java/org/iot/dsa/dslink/DSLink.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public DSLink() {
9595
@Override
9696
protected void declareDefaults() {
9797
declareDefault(SAVE, new DSAction()).setConfig(true);
98-
declareDefault(NODES, new DSNode()).setTransient(true);
98+
declareDefault(NODES, new DSNode());
9999
}
100100

101101
public DSLinkConfig getConfig() {

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

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.iot.dsa.io;
22

3+
import org.iot.dsa.node.DSBytes;
34
import org.iot.dsa.node.DSElement;
45
import org.iot.dsa.node.DSList;
56
import org.iot.dsa.node.DSMap;
@@ -18,6 +19,7 @@ public abstract class AbstractReader implements DSIReader {
1819

1920
private Token last = Token.ROOT;
2021
protected boolean valBoolean;
22+
protected byte[] valBytes;
2123
protected double valReal;
2224
protected long valLong;
2325
protected String valString;
@@ -33,6 +35,14 @@ public boolean getBoolean() {
3335
return valBoolean;
3436
}
3537

38+
@Override
39+
public byte[] getBytes() {
40+
if (last != Token.BYTES) {
41+
throw new IllegalStateException("Not bytes");
42+
}
43+
return valBytes;
44+
}
45+
3646
@Override
3747
public double getDouble() {
3848
switch (last) {
@@ -52,8 +62,8 @@ public DSElement getElement() {
5262
next();
5363
}
5464
switch (last) {
55-
case KEY:
56-
return DSElement.make(valString);
65+
case BYTES:
66+
return DSElement.make(valBytes);
5767
case BOOLEAN:
5868
return DSElement.make(valBoolean);
5969
case DOUBLE:
@@ -89,11 +99,12 @@ public DSList getList() {
8999
return ret;
90100
case END_MAP:
91101
throw new IllegalStateException("Unexpected end of map in list");
92-
case KEY:
93-
throw new IllegalStateException("Unexpected key in list");
94102
case BOOLEAN:
95103
ret.add(valBoolean);
96104
break;
105+
case BYTES:
106+
ret.add(DSElement.make(valBytes));
107+
break;
97108
case DOUBLE:
98109
ret.add(valReal);
99110
break;
@@ -144,7 +155,7 @@ public DSMap getMap() {
144155
String key = null;
145156
while (true) {
146157
switch (next()) {
147-
case KEY:
158+
case STRING:
148159
key = valString;
149160
break;
150161
case END_MAP:
@@ -160,11 +171,12 @@ public DSMap getMap() {
160171
throw new IllegalStateException("Unexpected end of list in map");
161172
case END_MAP:
162173
return ret;
163-
case KEY:
164-
throw new IllegalStateException("Unexpected key in map");
165174
case BOOLEAN:
166175
ret.put(key, DSElement.make(valBoolean));
167176
break;
177+
case BYTES:
178+
ret.put(key, DSElement.make(valBytes));
179+
break;
168180
case DOUBLE:
169181
ret.put(key, DSElement.make(valReal));
170182
break;
@@ -191,7 +203,7 @@ public DSMap getMap() {
191203

192204
@Override
193205
public String getString() {
194-
if ((last != Token.STRING) && (last != Token.KEY)) {
206+
if (last != Token.STRING) {
195207
throw new IllegalStateException("Not a string");
196208
}
197209
return valString;
@@ -233,30 +245,21 @@ protected Token setEndInput() {
233245
return last = Token.END_INPUT;
234246
}
235247

236-
/**
237-
* Call setNextValue(String) before calling this.
238-
*
239-
* @see #setNextValue(String)
240-
*/
241-
protected Token setNextKey() {
242-
return last = Token.KEY;
243-
}
244-
245248
protected Token setNextValue(boolean arg) {
246249
valBoolean = arg;
247250
return last = Token.BOOLEAN;
248251
}
249252

253+
protected Token setNextValue(byte[] arg) {
254+
valBytes = arg;
255+
return last = Token.BYTES;
256+
}
257+
250258
protected Token setNextValue(double arg) {
251259
valReal = arg;
252260
return last = Token.DOUBLE;
253261
}
254262

255-
/**
256-
* If this is a key, call this immediately followed by setNextKey()
257-
*
258-
* @see #setNextKey()
259-
*/
260263
protected Token setNextValue(long arg) {
261264
valLong = arg;
262265
return last = Token.LONG;

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.Closeable;
44
import java.io.IOException;
5+
import org.iot.dsa.node.DSBytes;
56
import org.iot.dsa.node.DSElement;
67
import org.iot.dsa.node.DSList;
78
import org.iot.dsa.node.DSMap;
@@ -186,6 +187,9 @@ public AbstractWriter value(DSElement arg) {
186187
case BOOLEAN:
187188
value(arg.toBoolean());
188189
break;
190+
case BYTES:
191+
value(arg.toBytes());
192+
break;
189193
case LONG:
190194
value(arg.toLong());
191195
break;
@@ -248,6 +252,34 @@ public AbstractWriter value(boolean arg) {
248252
return this;
249253
}
250254

255+
@Override
256+
public AbstractWriter value(byte[] arg) {
257+
try {
258+
switch (last) {
259+
case LAST_DONE:
260+
throw new IllegalStateException("Nesting error");
261+
case LAST_INIT:
262+
throw new IllegalStateException("Not expecting byte[] value");
263+
case LAST_VAL:
264+
case LAST_END:
265+
writeSeparator();
266+
if (prettyPrint) {
267+
writeNewLineIndent();
268+
}
269+
break;
270+
case LAST_LIST:
271+
if (prettyPrint) {
272+
writeNewLineIndent();
273+
}
274+
}
275+
write(arg);
276+
last = LAST_VAL;
277+
} catch (IOException x) {
278+
throw new RuntimeException(x);
279+
}
280+
return this;
281+
}
282+
251283
@Override
252284
public AbstractWriter value(double arg) {
253285
try {
@@ -369,6 +401,11 @@ public AbstractWriter value(String arg) {
369401
*/
370402
protected abstract void write(boolean arg) throws IOException;
371403

404+
/**
405+
* Write the value.
406+
*/
407+
protected abstract void write(byte[] arg) throws IOException;
408+
372409
/**
373410
* Write the value.
374411
*/

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,13 @@ public DSByteBuffer setTimeout(long timeout) {
259259
return this;
260260
}
261261

262+
/**
263+
* Returns a new array.
264+
*/
262265
public byte[] toByteArray() {
263266
byte[] ret = new byte[length];
264267
read(ret, 0, length);
265268
return ret;
266269
}
267270

268-
/////////////////////////////////////////////////////////////////
269-
// Inner Classes
270-
/////////////////////////////////////////////////////////////////
271-
272-
/////////////////////////////////////////////////////////////////
273-
// Initialization
274-
/////////////////////////////////////////////////////////////////
275-
276271
}

0 commit comments

Comments
 (0)