public override java.nio.LongBuffer duplicate() { java.nio.ByteBuffer bb = byteBuffer.duplicate().order(byteBuffer.order()); java.nio.LongToByteBufferAdapter buf = new java.nio.LongToByteBufferAdapter(bb); buf._limit = _limit; buf._position = _position; buf._mark = _mark; return(buf); }
internal static java.nio.ByteBuffer makeByteBuffer(int bytes) { java.nio.ByteBuffer result = java.nio.ByteBuffer.prepare(bytes); result.order(java.nio.ByteOrder.LITTLE_ENDIAN); result.mark(); return(result); }
/// <exception cref="System.IO.IOException"/> public static void Write(java.nio.channels.WritableByteChannel outputChannel, Capnproto.MessageBuilder message) { java.nio.ByteBuffer[] segments = message.GetSegmentsForOutput(); int tableSize = (segments.Length + 2) & (~1); java.nio.ByteBuffer table = java.nio.ByteBuffer.allocate(4 * tableSize); table.order(java.nio.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. while (table.hasRemaining()) { outputChannel.Write(table); } foreach (java.nio.ByteBuffer buffer in segments) { while (buffer.hasRemaining()) { outputChannel.Write(buffer); } } }
///Upon return, `bb.position()` will be at the end of the message. /// <exception cref="System.IO.IOException"/> public static Capnproto.MessageReader Read(java.nio.ByteBuffer bb, Capnproto.ReaderOptions options) { bb.order(java.nio.ByteOrder.LITTLE_ENDIAN); int segmentCount = 1 + bb.getInt(); if (segmentCount > 512) { throw new System.IO.IOException("too many segments"); } java.nio.ByteBuffer[] segmentSlices = new java.nio.ByteBuffer[segmentCount]; int segmentSizesBase = bb.position(); int segmentSizesSize = segmentCount * 4; int align = Capnproto.Constants.BYTES_PER_WORD - 1; int segmentBase = (segmentSizesBase + segmentSizesSize + align) & ~align; int totalWords = 0; for (int ii = 0; ii < segmentCount; ++ii) { int segmentSize = bb.getInt(segmentSizesBase + ii * 4); bb.position(segmentBase + totalWords * Capnproto.Constants.BYTES_PER_WORD); segmentSlices[ii] = bb.slice(); segmentSlices[ii].limit(segmentSize * Capnproto.Constants.BYTES_PER_WORD); segmentSlices[ii].order(java.nio.ByteOrder.LITTLE_ENDIAN); totalWords += segmentSize; } bb.position(segmentBase + totalWords * Capnproto.Constants.BYTES_PER_WORD); if (totalWords > options.traversalLimitInWords) { throw new Capnproto.DecodeException("Message size exceeds traversal limit."); } return(new Capnproto.MessageReader(segmentSlices, options)); }
internal static java.nio.ShortBuffer asShortBuffer(java.nio.ByteBuffer byteBuffer ) { java.nio.ByteBuffer slice_1 = byteBuffer.slice(); slice_1.order(byteBuffer.order()); return(new java.nio.ShortToByteBufferAdapter(slice_1)); }
public static Capnproto.SegmentReader decodeRawBytes(string s) { try { java.nio.ByteBuffer buffer = java.nio.ByteBuffer.wrap(Sharpen.Runtime.GetBytesForString(s, "ISO_8859-1")).asReadOnlyBuffer(); buffer.order(java.nio.ByteOrder.LITTLE_ENDIAN); return(new Capnproto.SegmentReader(buffer, new Capnproto.ReaderArena(new java.nio.ByteBuffer[0], unchecked ((long)(0x7fffffffffffffffL))))); } catch (System.Exception) { throw new System.Exception("could not decode raw bytes from String"); } }
public java.nio.ByteBuffer[] getSegmentsForOutput() { java.nio.ByteBuffer[] result = new java.nio.ByteBuffer[this.segments.Count]; for (int ii = 0; ii < this.segments.Count; ++ii) { Capnproto.SegmentBuilder segment = segments[ii]; segment.buffer.rewind(); java.nio.ByteBuffer slice = segment.buffer.slice(); slice.limit(segment.currentSize() * Capnproto.Constants.BYTES_PER_WORD); slice.order(java.nio.ByteOrder.LITTLE_ENDIAN); result[ii] = slice; } return(result); }