Search in sources :

Example 1 with TapCallback

use of com.koushikdutta.async.TapCallback in project AndroidAsync by koush.

the class ByteUtilTests method testPushParserTapUntil.

public void testPushParserTapUntil() {
    valRead = 0;
    FilteredDataEmitter mock = new FilteredDataEmitter() {

        @Override
        public boolean isPaused() {
            return false;
        }
    };
    new PushParser(mock).until((byte) 0, new DataCallback.NullDataCallback()).readInt().tap(new TapCallback() {

        public void parsed(int arg) {
            valRead = arg;
        }
    });
    byte[] bytes = new byte[] { 5, 5, 5, 5, 0, 10, 5, 5, 5 };
    Util.emitAllData(mock, new ByteBufferList(bytes));
    assertEquals(valRead, 0x0A050505);
}
Also used : FilteredDataEmitter(com.koushikdutta.async.FilteredDataEmitter) PushParser(com.koushikdutta.async.PushParser) ByteBufferList(com.koushikdutta.async.ByteBufferList) DataCallback(com.koushikdutta.async.callback.DataCallback) TapCallback(com.koushikdutta.async.TapCallback)

Example 2 with TapCallback

use of com.koushikdutta.async.TapCallback in project AndroidAsync by koush.

the class ByteUtilTests method testTapCallback.

public void testTapCallback() {
    readInt = 0;
    readByte = 0;
    readString = "";
    FilteredDataEmitter mock = new FilteredDataEmitter() {

        @Override
        public boolean isPaused() {
            return false;
        }
    };
    new PushParser(mock).readInt().readByte().readString().tap(new TapCallback() {

        void tap(int i, byte b, String s) {
            readInt = i;
            readByte = b;
            readString = s;
        }
    });
    byte[] bytes = new byte[] { 10, 5, 5, 5, 3, 0, 0, 0, 4, 116, 101, 115, 116 };
    Util.emitAllData(mock, new ByteBufferList(bytes));
    assertEquals(readInt, 0x0A050505);
    assertEquals(readByte, (byte) 3);
    assertEquals(readString, "test");
}
Also used : FilteredDataEmitter(com.koushikdutta.async.FilteredDataEmitter) PushParser(com.koushikdutta.async.PushParser) ByteBufferList(com.koushikdutta.async.ByteBufferList) TapCallback(com.koushikdutta.async.TapCallback)

Aggregations

ByteBufferList (com.koushikdutta.async.ByteBufferList)2 FilteredDataEmitter (com.koushikdutta.async.FilteredDataEmitter)2 PushParser (com.koushikdutta.async.PushParser)2 TapCallback (com.koushikdutta.async.TapCallback)2 DataCallback (com.koushikdutta.async.callback.DataCallback)1