oops, forgot to add new file
This commit is contained in:
parent
22a54fceaf
commit
94f76d3964
1 changed files with 29 additions and 0 deletions
29
runtime/src/main/java/org/capnproto/Serialize.java
Normal file
29
runtime/src/main/java/org/capnproto/Serialize.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package org.capnproto;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.GatheringByteChannel;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
public final class Serialize {
|
||||
public static void writeMessage(GatheringByteChannel outputChannel,
|
||||
MessageBuilder message) throws IOException {
|
||||
ByteBuffer[] segments = message.getSegmentsForOutput();
|
||||
int tableSize = (segments.length + 2) & (~1);
|
||||
|
||||
ByteBuffer table = ByteBuffer.allocate(4 * tableSize);
|
||||
table.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
table.putInt(0, segments.length - 1);
|
||||
|
||||
for (int i = 0; i < segments.length; ++i) {
|
||||
table.putInt(4 * (i + 1), segments[i].limit() / 8);
|
||||
}
|
||||
|
||||
// Any padding is already zeroed.
|
||||
|
||||
outputChannel.write(table);
|
||||
|
||||
outputChannel.write(segments);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue