Commit 7b1cf84d authored by Yoann Pigné's avatar Yoann Pigné

update java implementation to take into account bugfix #56 in gs-core

parent d89e4128
...@@ -485,10 +485,12 @@ package org.netstream; ...@@ -485,10 +485,12 @@ package org.netstream;
* </p> * </p>
* <ul class="simple"> * <ul class="simple">
* <li>the attribute name (TYPE_STRING format)</li> * <li>the attribute name (TYPE_STRING format)</li>
* <li>the attribute value type (one of the bytes shown in the &quot;Data * <li>the attribute'd old value type (one of the bytes shown in the &quot;Data
* Types&quot; section)</li> * Types&quot; section)</li>
* <li>the old attribute value, encoded according to its value type (see the * <li>the old attribute value, encoded according to its value type (see the
* &quot;Data Types&quot; section)</li> * &quot;Data Types&quot; section)</li>
* <li>the attribute's new value type (one of the bytes shown in the &quot;Data
* Types&quot; section)</li>
* <li>the new attribute value, encoded according to its value type (see the * <li>the new attribute value, encoded according to its value type (see the
* &quot;Data Types&quot; section)</li> * &quot;Data Types&quot; section)</li>
* </ul> * </ul>
...@@ -528,10 +530,12 @@ package org.netstream; ...@@ -528,10 +530,12 @@ package org.netstream;
* <ul class="simple"> * <ul class="simple">
* <li>the ID of the considered node (TYPE_STRING format)</li> * <li>the ID of the considered node (TYPE_STRING format)</li>
* <li>the attribute name (TYPE_STRING format)</li> * <li>the attribute name (TYPE_STRING format)</li>
* <li>the attribute value type (one of the bytes shown in the &quot;Data * <li>the attribute's old value type (one of the bytes shown in the &quot;Data
* Types&quot; section)</li> * Types&quot; section)</li>
* <li>the old attribute value, encoded according to its value type (see the * <li>the old attribute value, encoded according to its value type (see the
* &quot;Data Types&quot; section)</li> * &quot;Data Types&quot; section)</li>
* <li>the attribute's new value type (one of the bytes shown in the &quot;Data
* Types&quot; section)</li>
* <li>the new attribute value, encoded according to its value type (see the * <li>the new attribute value, encoded according to its value type (see the
* &quot;Data Types&quot; section)</li> * &quot;Data Types&quot; section)</li>
* </ul> * </ul>
...@@ -553,10 +557,10 @@ package org.netstream; ...@@ -553,10 +557,10 @@ package org.netstream;
* <tt class="docutils literal">EVENT_ADD_EDGE_ATTR</tt> [0x1C] * <tt class="docutils literal">EVENT_ADD_EDGE_ATTR</tt> [0x1C]
* </p> * </p>
* <p> * <p>
* Add an attribute to a node. Followed by: * Add an attribute to an edge. Followed by:
* </p> * </p>
* <ul class="simple"> * <ul class="simple">
* <li>the ID of the considered node (TYPE_STRING format)</li> * <li>the ID of the considered edge (TYPE_STRING format)</li>
* <li>the attribute name (TYPE_STRING format)</li> * <li>the attribute name (TYPE_STRING format)</li>
* <li>the attribute value type (one of the bytes shown in the &quot;Data * <li>the attribute value type (one of the bytes shown in the &quot;Data
* Types&quot; section)</li> * Types&quot; section)</li>
...@@ -569,15 +573,17 @@ package org.netstream; ...@@ -569,15 +573,17 @@ package org.netstream;
* <tt class="docutils literal">EVENT_CHG_EDGE_ATTR</tt> [0x1D] * <tt class="docutils literal">EVENT_CHG_EDGE_ATTR</tt> [0x1D]
* </p> * </p>
* <p> * <p>
* Change an existing attribute on a given node. Followed by: * Change an existing attribute on a given edge. Followed by:
* </p> * </p>
* <ul class="simple"> * <ul class="simple">
* <li>the ID of the considered node (TYPE_STRING format)</li> * <li>the ID of the considered edge (TYPE_STRING format)</li>
* <li>the attribute name (TYPE_STRING format)</li> * <li>the attribute name (TYPE_STRING format)</li>
* <li>the attribute value type (one of the bytes shown in the &quot;Data * <li>the attribute's old value type (one of the bytes shown in the &quot;Data
* Types&quot; section)</li> * Types&quot; section)</li>
* <li>the old attribute value, encoded according to its value type (see the * <li>the old attribute value, encoded according to its value type (see the
* &quot;Data Types&quot; section)</li> * &quot;Data Types&quot; section)</li>
* <li>the attribute's new value type (one of the bytes shown in the &quot;Data
* Types&quot; section)</li>
* <li>the new attribute value, encoded according to its value type (see the * <li>the new attribute value, encoded according to its value type (see the
* &quot;Data Types&quot; section)</li> * &quot;Data Types&quot; section)</li>
* </ul> * </ul>
...@@ -587,10 +593,10 @@ package org.netstream; ...@@ -587,10 +593,10 @@ package org.netstream;
* <tt class="docutils literal">EVENT_DEL_EDGE_ATTR</tt> [0x1E] * <tt class="docutils literal">EVENT_DEL_EDGE_ATTR</tt> [0x1E]
* </p> * </p>
* <p> * <p>
* Remove an attribute from a given node. Followed by: * Remove an attribute from a given edge. Followed by:
* </p> * </p>
* <ul class="simple"> * <ul class="simple">
* <li>the ID of the considered node (TYPE_STRING format)</li> * <li>the ID of the considered edge (TYPE_STRING format)</li>
* <li>the attribute name (encoded with the TYPE_STRING format).</li> * <li>the attribute name (encoded with the TYPE_STRING format).</li>
* </ul> * </ul>
* </li> * </li>
......
...@@ -38,6 +38,7 @@ import java.nio.charset.Charset; ...@@ -38,6 +38,7 @@ import java.nio.charset.Charset;
import org.netstream.packing.NetStreamPacker; import org.netstream.packing.NetStreamPacker;
/** /**
* <p> * <p>
* This class implements a sender according to specifications the NetStream * This class implements a sender according to specifications the NetStream
...@@ -64,7 +65,8 @@ import org.netstream.packing.NetStreamPacker; ...@@ -64,7 +65,8 @@ import org.netstream.packing.NetStreamPacker;
* @author Yoann Pigné * @author Yoann Pigné
* *
*/ */
public class NetStreamSender {
public class NetStreamSender{
protected String stream; protected String stream;
byte[] streamIdArray; byte[] streamIdArray;
protected String host; protected String host;
...@@ -496,11 +498,12 @@ public class NetStreamSender { ...@@ -496,11 +498,12 @@ public class NetStreamSender {
sourceIdBuff = sourceId.getBytes(Charset.forName("UTF-8")); sourceIdBuff = sourceId.getBytes(Charset.forName("UTF-8"));
} }
byte[] attrArray = attribute.getBytes(Charset.forName("UTF-8")); byte[] attrArray = attribute.getBytes(Charset.forName("UTF-8"));
int valueType = getType(oldValue); int oldValueType = getType(oldValue);
int newValueType = getType(newValue);
ByteBuffer bOldValue = encodeValue(oldValue, valueType); ByteBuffer bOldValue = encodeValue(oldValue, oldValueType);
bOldValue.flip(); bOldValue.flip();
ByteBuffer bNewValue = encodeValue(newValue, valueType); ByteBuffer bNewValue = encodeValue(newValue, newValueType);
bNewValue.flip(); bNewValue.flip();
ByteBuffer buff = ByteBuffer.allocate(4 + streamIdArray.length + // Stream ByteBuffer buff = ByteBuffer.allocate(4 + streamIdArray.length + // Stream
...@@ -509,13 +512,19 @@ public class NetStreamSender { ...@@ -509,13 +512,19 @@ public class NetStreamSender {
4 + sourceIdBuff.length + // source id 4 + sourceIdBuff.length + // source id
8 + // timeId 8 + // timeId
4 + attrArray.length + // attr name 4 + attrArray.length + // attr name
1 + bOldValue.capacity() + bNewValue.capacity()); // values 1 + // value type
bOldValue.capacity() +
1 + // value type
bNewValue.capacity()); // values
buff.putInt(streamIdArray.length).put(streamIdArray) buff.putInt(streamIdArray.length).put(streamIdArray)
.put((byte) NetStreamConstants.EVENT_CHG_GRAPH_ATTR) .put((byte) NetStreamConstants.EVENT_CHG_GRAPH_ATTR)
.putInt(sourceIdBuff.length).put(sourceIdBuff).putLong(timeId) .putInt(sourceIdBuff.length).put(sourceIdBuff).putLong(timeId)
.putInt(attrArray.length).put(attrArray).put((byte) valueType) .putInt(attrArray.length).put(attrArray)
.put(bOldValue).put(bNewValue); .put((byte) oldValueType)
.put(bOldValue)
.put((byte) newValueType)
.put(bNewValue);
doSend(buff); doSend(buff);
...@@ -614,11 +623,12 @@ public class NetStreamSender { ...@@ -614,11 +623,12 @@ public class NetStreamSender {
} }
byte[] attrArray = attribute.getBytes(Charset.forName("UTF-8")); byte[] attrArray = attribute.getBytes(Charset.forName("UTF-8"));
byte[] nodeIdArray = nodeId.getBytes(Charset.forName("UTF-8")); byte[] nodeIdArray = nodeId.getBytes(Charset.forName("UTF-8"));
int valueType = getType(oldValue); int oldValueType = getType(oldValue);
int newValueType = getType(newValue);
ByteBuffer bOldValue = encodeValue(oldValue, valueType); ByteBuffer bOldValue = encodeValue(oldValue, oldValueType);
bOldValue.flip(); bOldValue.flip();
ByteBuffer bNewValue = encodeValue(newValue, valueType); ByteBuffer bNewValue = encodeValue(newValue, newValueType);
bNewValue.flip(); bNewValue.flip();
ByteBuffer buff = ByteBuffer.allocate(4 + streamIdArray.length + // stream ByteBuffer buff = ByteBuffer.allocate(4 + streamIdArray.length + // stream
...@@ -629,6 +639,7 @@ public class NetStreamSender { ...@@ -629,6 +639,7 @@ public class NetStreamSender {
(4 + attrArray.length) + // attribute (4 + attrArray.length) + // attribute
1 + // value type 1 + // value type
bOldValue.capacity() + // value bOldValue.capacity() + // value
1 + // value type
bNewValue.capacity() // new value bNewValue.capacity() // new value
); );
...@@ -639,8 +650,9 @@ public class NetStreamSender { ...@@ -639,8 +650,9 @@ public class NetStreamSender {
.putInt(sourceIdBuff.length).put(sourceIdBuff).putLong(timeId) .putInt(sourceIdBuff.length).put(sourceIdBuff).putLong(timeId)
.putInt(nodeIdArray.length).put(nodeIdArray) // nodeId .putInt(nodeIdArray.length).put(nodeIdArray) // nodeId
.putInt(attrArray.length).put(attrArray) // attribute .putInt(attrArray.length).put(attrArray) // attribute
.put((byte) valueType) // value type .put((byte) oldValueType) // value type
.put(bOldValue) // value .put(bOldValue) // value
.put((byte) newValueType) // value type
.put(bNewValue); // value .put(bNewValue); // value
doSend(buff); doSend(buff);
} }
...@@ -742,11 +754,12 @@ public class NetStreamSender { ...@@ -742,11 +754,12 @@ public class NetStreamSender {
} }
byte[] edgeIdArray = edgeId.getBytes(Charset.forName("UTF-8")); byte[] edgeIdArray = edgeId.getBytes(Charset.forName("UTF-8"));
byte[] attrArray = attribute.getBytes(Charset.forName("UTF-8")); byte[] attrArray = attribute.getBytes(Charset.forName("UTF-8"));
int valueType = getType(oldValue); int oldValueType = getType(oldValue);
int newValueType = getType(newValue);
ByteBuffer bOldValue = encodeValue(oldValue, valueType); ByteBuffer bOldValue = encodeValue(oldValue, oldValueType);
bOldValue.flip(); bOldValue.flip();
ByteBuffer bNewValue = encodeValue(newValue, valueType); ByteBuffer bNewValue = encodeValue(newValue, newValueType);
bNewValue.flip(); bNewValue.flip();
ByteBuffer buff = ByteBuffer.allocate(4 + streamIdArray.length + // stream ByteBuffer buff = ByteBuffer.allocate(4 + streamIdArray.length + // stream
...@@ -758,6 +771,7 @@ public class NetStreamSender { ...@@ -758,6 +771,7 @@ public class NetStreamSender {
(4 + attrArray.length) + // attribute (4 + attrArray.length) + // attribute
1 + // value type 1 + // value type
bOldValue.capacity() + // value bOldValue.capacity() + // value
1 + // value type
bNewValue.capacity() // new value bNewValue.capacity() // new value
); );
...@@ -768,8 +782,9 @@ public class NetStreamSender { ...@@ -768,8 +782,9 @@ public class NetStreamSender {
.putInt(sourceIdBuff.length).put(sourceIdBuff).putLong(timeId) .putInt(sourceIdBuff.length).put(sourceIdBuff).putLong(timeId)
.putInt(edgeIdArray.length).put(edgeIdArray) // nodeId .putInt(edgeIdArray.length).put(edgeIdArray) // nodeId
.putInt(attrArray.length).put(attrArray) // attribute .putInt(attrArray.length).put(attrArray) // attribute
.put((byte) valueType) // value type .put((byte) oldValueType) // value type
.put(bOldValue) // value .put(bOldValue) // value
.put((byte) newValueType) // value type
.put(bNewValue); // value .put(bNewValue); // value
doSend(buff); doSend(buff);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment