GWTBuff(Uint8ArrayNative toWrap) { super(false); _array = null; _typed = toWrap; _limit = toWrap.length(); }
@Override public int capacity() { if (_useTypedArrays) return _typed.length(); return _array.length; }
private void onMessage(Uint8ArrayNative typed) { if (resumeRead()) { int offset = 0; int length = typed.length(); while (offset < length) { // TODO wrap instead of copy GWTBuff buff = (GWTBuff) Buff.getOrCreate(); buff.position(Buff.getLargestUnsplitable()); int copy = Math.min(length - offset, buff.remaining()); Uint8ArrayNative sub = typed.subarray(offset, offset + copy); buff.typed().set(sub, buff.position()); buff.limit(buff.position() + copy); offset += copy; read(buff); buff.recycle(); } suspendRead(); } }