Changed length of encoded message length to 4 bytes
This commit is contained in:
parent
e13438eefd
commit
2592334b05
7
pom.xml
7
pom.xml
@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>informatik-ag-ngl</groupId>
|
||||
<artifactId>envoy-server-standalone</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<version>0.1-alpha</version>
|
||||
|
||||
<name>Envoy Server</name>
|
||||
<url>https://github.com/informatik-ag-ngl/envoy-server-standalone</url>
|
||||
@ -18,6 +18,11 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>informatik-ag-ngl</groupId>
|
||||
<artifactId>envoy-common</artifactId>
|
||||
<version>0.2-alpha</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>informatik-ag-ngl</groupId>
|
||||
<artifactId>java-nio-server</artifactId>
|
||||
|
@ -20,9 +20,8 @@ public class ObjectMessageProcessor implements IMessageProcessor {
|
||||
|
||||
@Override
|
||||
public void process(Message message, WriteProxy writeProxy) {
|
||||
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(message.sharedArray, message.offset + 1, message.length - 1))) {
|
||||
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(message.sharedArray, message.offset + 4, message.length - 4))) {
|
||||
Object obj = in.readObject();
|
||||
|
||||
// TODO: Process pipeline
|
||||
System.out.println("Read object: " + obj.toString());
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
|
@ -41,18 +41,26 @@ public class ObjectMessageReader implements IMessageReader {
|
||||
}
|
||||
|
||||
nextMessage.writeToMessage(buffer);
|
||||
|
||||
int length = nextMessage.sharedArray[nextMessage.offset];
|
||||
if(nextMessage.length - nextMessage.offset >= length) {
|
||||
|
||||
// Get message length
|
||||
if (nextMessage.length - nextMessage.offset < 4) return;
|
||||
int length = fromByteArray(nextMessage.sharedArray, nextMessage.offset) + 4;
|
||||
|
||||
if (nextMessage.length - nextMessage.offset >= length) {
|
||||
Message message = messageBuffer.getMessage();
|
||||
message.writePartialMessageToMessage(nextMessage, nextMessage.offset + length);
|
||||
completeMessages.add(nextMessage);
|
||||
nextMessage = message;
|
||||
}
|
||||
|
||||
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
private int fromByteArray(byte[] bytes, int offset) {
|
||||
return ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8)
|
||||
| ((bytes[offset + 3] & 0xFF) << 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Message> getMessages() { return completeMessages; }
|
||||
}
|
Reference in New Issue
Block a user