Search in sources :

Example 1 with ArrayBuffer

use of com.google.gwt.typedarrays.shared.ArrayBuffer in project playn by threerings.

the class HtmlWebSocket method send.

@Override
public void send(ByteBuffer data) {
    int len = data.limit();
    // TODO(haustein) Sending the view directly does not work for some reason.
    // May be a chrome issue...?
    //  Object trick = data;
    // ArrayBufferView ta = ((HasArrayBufferView) trick).getTypedArray();
    // Int8Array view = Int8Array.create(ta.getBuffer(), ta.getByteOffset(), len)
    // ws.send(view);
    ArrayBuffer buf = TypedArrays.createArrayBuffer(len);
    Uint8Array view = TypedArrays.createUint8Array(buf);
    for (int i = 0; i < len; i++) {
        view.set(i, data.get(i));
    }
    ws.send(buf);
}
Also used : ArrayBuffer(com.google.gwt.typedarrays.shared.ArrayBuffer) Uint8Array(com.google.gwt.typedarrays.shared.Uint8Array)

Aggregations

ArrayBuffer (com.google.gwt.typedarrays.shared.ArrayBuffer)1 Uint8Array (com.google.gwt.typedarrays.shared.Uint8Array)1