refactoring

pull/1204/head
Nikita 7 years ago
parent 2e8145046d
commit 2d85018431

@ -92,7 +92,7 @@ public class CommandDecoder extends ReplayingDecoder<State> {
if (data == null) {
while (in.writerIndex() > in.readerIndex()) {
decode(in, null, null, ctx.channel());
decode(in, null, null, ctx.channel());
}
} else if (data instanceof CommandData) {
CommandData<Object, Object> cmd = (CommandData<Object, Object>)data;
@ -330,7 +330,7 @@ public class CommandDecoder extends ReplayingDecoder<State> {
if (parts.isEmpty()) {
return null;
}
}
}
return data.getCommand().getReplayMultiDecoder();
}
@ -342,8 +342,9 @@ public class CommandDecoder extends ReplayingDecoder<State> {
Decoder<Object> decoder = data.getCommand().getReplayDecoder();
if (parts != null) {
MultiDecoder<Object> multiDecoder = data.getCommand().getReplayMultiDecoder();
if (multiDecoder.isApplicable(parts.size(), state())) {
decoder = multiDecoder;
Decoder<Object> mDecoder = multiDecoder.getDecoder(parts.size(), state());
if (mDecoder != null) {
decoder = mDecoder;
}
}
if (decoder == null) {

@ -176,11 +176,11 @@ public class CommandPubSubDecoder extends CommandDecoder {
if (data == null && parts != null) {
if (parts.size() == 2 && "message".equals(parts.get(0))) {
String channelName = (String) parts.get(1);
return entries.get(channelName).getDecoder();
return entries.get(channelName).getDecoder().getDecoder(parts.size(), state());
}
if (parts.size() == 3 && "pmessage".equals(parts.get(0))) {
String patternName = (String) parts.get(1);
return entries.get(patternName).getDecoder();
return entries.get(patternName).getDecoder().getDecoder(parts.size(), state());
}
}
return super.selectDecoder(data, parts);

@ -15,11 +15,8 @@
*/
package org.redisson.client.protocol.decoder;
import java.io.IOException;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -34,17 +31,13 @@ public class FlatNestedMultiDecoder<T> extends NestedMultiDecoder {
}
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
return firstDecoder.decode(buf, state);
}
@Override
public boolean isApplicable(int paramNum, State state) {
public Decoder<Object> getDecoder(int paramNum, State state) {
NestedDecoderState ds = getDecoder(state);
if (paramNum == 0) {
ds.resetDecoderIndex();
}
return firstDecoder.isApplicable(paramNum, state);
return firstDecoder.getDecoder(paramNum, state);
}
}

@ -15,14 +15,12 @@
*/
package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -31,8 +29,6 @@ import io.netty.buffer.ByteBuf;
*/
public class GeoDistanceDecoder implements MultiDecoder<List<Object>> {
private final ThreadLocal<Integer> pos = new ThreadLocal<Integer>();
private final Codec codec;
public GeoDistanceDecoder(Codec codec) {
@ -41,17 +37,11 @@ public class GeoDistanceDecoder implements MultiDecoder<List<Object>> {
}
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
if (pos.get() % 2 == 0) {
return codec.getValueDecoder().decode(buf, state);
public Decoder<Object> getDecoder(int paramNum, State state) {
if (paramNum % 2 == 0) {
return codec.getValueDecoder();
}
return DoubleCodec.INSTANCE.getValueDecoder().decode(buf, state);
}
@Override
public boolean isApplicable(int paramNum, State state) {
pos.set(paramNum);
return true;
return DoubleCodec.INSTANCE.getValueDecoder();
}
@Override

@ -15,7 +15,6 @@
*/
package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -23,8 +22,7 @@ import java.util.Map;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -33,8 +31,6 @@ import io.netty.buffer.ByteBuf;
*/
public class GeoDistanceMapDecoder implements MultiDecoder<Map<Object, Object>> {
private final ThreadLocal<Integer> pos = new ThreadLocal<Integer>();
private final Codec codec;
public GeoDistanceMapDecoder(Codec codec) {
@ -43,17 +39,11 @@ public class GeoDistanceMapDecoder implements MultiDecoder<Map<Object, Object>>
}
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
if (pos.get() % 2 == 0) {
return codec.getValueDecoder().decode(buf, state);
public Decoder<Object> getDecoder(int paramNum, State state) {
if (paramNum % 2 == 0) {
return codec.getValueDecoder();
}
return DoubleCodec.INSTANCE.getValueDecoder().decode(buf, state);
}
@Override
public boolean isApplicable(int paramNum, State state) {
pos.set(paramNum);
return true;
return DoubleCodec.INSTANCE.getValueDecoder();
}
@Override

@ -20,8 +20,7 @@ import java.util.List;
import java.util.Map;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -31,8 +30,8 @@ import io.netty.buffer.ByteBuf;
public class GeoMapReplayDecoder implements MultiDecoder<Map<Object, Object>> {
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
public Decoder<Object> getDecoder(int paramNum, State state) {
return null;
}
@Override
@ -45,9 +44,4 @@ public class GeoMapReplayDecoder implements MultiDecoder<Map<Object, Object>> {
return result;
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
}
}

@ -15,14 +15,12 @@
*/
package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List;
import org.redisson.api.GeoPosition;
import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -32,13 +30,8 @@ import io.netty.buffer.ByteBuf;
public class GeoPositionDecoder implements MultiDecoder<GeoPosition> {
@Override
public Double decode(ByteBuf buf, State state) throws IOException {
return (Double) DoubleCodec.INSTANCE.getValueDecoder().decode(buf, state);
}
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
public Decoder<Object> getDecoder(int paramNum, State state) {
return DoubleCodec.INSTANCE.getValueDecoder();
}
@Override

@ -15,15 +15,13 @@
*/
package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -39,13 +37,8 @@ public class GeoPositionMapDecoder implements MultiDecoder<Map<Object, Object>>
}
@Override
public Double decode(ByteBuf buf, State state) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
public Decoder<Object> getDecoder(int paramNum, State state) {
return null;
}
@Override

@ -15,9 +15,11 @@
*/
package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
@ -30,10 +32,18 @@ import io.netty.util.CharsetUtil;
public class KeyValueObjectDecoder implements MultiDecoder<Object> {
@Override
public Object decode(ByteBuf buf, State state) {
String status = buf.toString(CharsetUtil.UTF_8);
buf.skipBytes(1);
return status;
public Decoder<Object> getDecoder(int paramNum, State state) {
if (paramNum == 0) {
return new Decoder<Object>() {
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
String status = buf.toString(CharsetUtil.UTF_8);
buf.skipBytes(1);
return status;
}
};
}
return null;
}
@Override
@ -44,9 +54,4 @@ public class KeyValueObjectDecoder implements MultiDecoder<Object> {
return new KeyValueMessage(parts.get(0), parts.get(1));
}
@Override
public boolean isApplicable(int paramNum, State state) {
return paramNum == 0;
}
}

@ -18,8 +18,7 @@ package org.redisson.client.protocol.decoder;
import java.util.List;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -28,11 +27,6 @@ import io.netty.buffer.ByteBuf;
*/
public class ListFirstObjectDecoder implements MultiDecoder<Object> {
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
}
@Override
public Object decode(List<Object> parts, State state) {
if (!parts.isEmpty()) {
@ -42,8 +36,8 @@ public class ListFirstObjectDecoder implements MultiDecoder<Object> {
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
public Decoder<Object> getDecoder(int paramNum, State state) {
return null;
}
}

@ -18,8 +18,7 @@ package org.redisson.client.protocol.decoder;
import java.util.List;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -28,19 +27,14 @@ import io.netty.buffer.ByteBuf;
*/
public class ListIteratorReplayDecoder implements MultiDecoder<ListIteratorResult<Object>> {
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
}
@Override
public ListIteratorResult<Object> decode(List<Object> parts, State state) {
return new ListIteratorResult<Object>(parts.get(0), Long.valueOf(parts.get(1).toString()));
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
public Decoder<Object> getDecoder(int paramNum, State state) {
return null;
}
}

@ -15,12 +15,10 @@
*/
package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -90,19 +88,16 @@ public class ListMultiDecoder<T> implements MultiDecoder<Object> {
this.decoders = decoders;
}
public Object decode(ByteBuf buf, State state) throws IOException {
int index = getDecoder(state).getIndex();
return decoders[index].decode(buf, state);
}
@Override
public boolean isApplicable(int paramNum, State state) {
public Decoder<Object> getDecoder(int paramNum, State state) {
if (paramNum == 0) {
NestedDecoderState s = getDecoder(state);
s.incIndex();
s.resetPartsIndex();
}
return true;
int index = getDecoder(state).getIndex();
return decoders[index].getDecoder(paramNum, state);
}
@Override

@ -19,10 +19,9 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import org.redisson.client.protocol.Decoder;
/**
*
@ -32,8 +31,8 @@ import io.netty.util.CharsetUtil;
public class ListResultReplayDecoder implements MultiDecoder<List<Map<Object, Object>>> {
@Override
public Object decode(ByteBuf buf, State state) {
return buf.toString(CharsetUtil.UTF_8);
public Decoder<Object> getDecoder(int paramNum, State state) {
return StringCodec.INSTANCE.getValueDecoder();
}
@Override
@ -43,9 +42,4 @@ public class ListResultReplayDecoder implements MultiDecoder<List<Map<Object, Ob
return Arrays.asList(res);
}
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
}
}

@ -17,10 +17,9 @@ package org.redisson.client.protocol.decoder;
import java.util.List;
import org.redisson.client.codec.LongCodec;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import org.redisson.client.protocol.Decoder;
/**
*
@ -30,8 +29,11 @@ import io.netty.util.CharsetUtil;
public class ListScanResultReplayDecoder implements MultiDecoder<ListScanResult<Object>> {
@Override
public Object decode(ByteBuf buf, State state) {
return Long.valueOf(buf.toString(CharsetUtil.UTF_8));
public Decoder<Object> getDecoder(int paramNum, State state) {
if (paramNum == 0) {
return LongCodec.INSTANCE.getValueDecoder();
}
return null;
}
@Override
@ -39,9 +41,4 @@ public class ListScanResultReplayDecoder implements MultiDecoder<ListScanResult<
return new ListScanResult<Object>((Long)parts.get(0), (List<Object>)parts.get(1));
}
@Override
public boolean isApplicable(int paramNum, State state) {
return paramNum == 0;
}
}

@ -15,13 +15,11 @@
*/
package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List;
import org.redisson.client.codec.LongCodec;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -31,13 +29,8 @@ import io.netty.buffer.ByteBuf;
public class LongMultiDecoder implements MultiDecoder<Object> {
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
return LongCodec.INSTANCE.getValueDecoder().decode(buf, state);
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
public Decoder<Object> getDecoder(int paramNum, State state) {
return LongCodec.INSTANCE.getValueDecoder();
}
@Override

@ -15,13 +15,11 @@
*/
package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -30,11 +28,6 @@ import io.netty.buffer.ByteBuf;
*/
public class MapCacheScanResultReplayDecoder implements MultiDecoder<MapCacheScanResult<Object, Object>> {
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public MapCacheScanResult<Object, Object> decode(List<Object> parts, State state) {
Long pos = (Long)parts.get(0);
@ -44,8 +37,8 @@ public class MapCacheScanResultReplayDecoder implements MultiDecoder<MapCacheSca
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
public Decoder<Object> getDecoder(int paramNum, State state) {
return null;
}
}

@ -18,10 +18,9 @@ package org.redisson.client.protocol.decoder;
import java.util.List;
import java.util.Map;
import org.redisson.client.codec.LongCodec;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import org.redisson.client.protocol.Decoder;
/**
*
@ -31,8 +30,11 @@ import io.netty.util.CharsetUtil;
public class MapScanResultReplayDecoder implements MultiDecoder<MapScanResult<Object, Object>> {
@Override
public Object decode(ByteBuf buf, State state) {
return Long.valueOf(buf.toString(CharsetUtil.UTF_8));
public Decoder<Object> getDecoder(int paramNum, State state) {
if (paramNum == 0) {
return LongCodec.INSTANCE.getValueDecoder();
}
return null;
}
@Override
@ -40,9 +42,4 @@ public class MapScanResultReplayDecoder implements MultiDecoder<MapScanResult<Ob
return new MapScanResult<Object, Object>((Long)parts.get(0), (Map<Object, Object>)parts.get(1));
}
@Override
public boolean isApplicable(int paramNum, State state) {
return paramNum == 0;
}
}

@ -26,9 +26,9 @@ import org.redisson.client.protocol.Decoder;
*
* @param <T> type
*/
public interface MultiDecoder<T> extends Decoder<Object> {
public interface MultiDecoder<T> {
boolean isApplicable(int paramNum, State state);
Decoder<Object> getDecoder(int paramNum, State state);
T decode(List<Object> parts, State state);

@ -15,12 +15,10 @@
*/
package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -102,22 +100,7 @@ public class NestedMultiDecoder<T> implements MultiDecoder<Object> {
}
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
NestedDecoderState ds = getDecoder(state);
MultiDecoder<?> decoder = null;
if (ds.getFlipDecoderIndex() == 2) {
decoder = firstDecoder;
}
if (ds.getFlipDecoderIndex() == 1) {
decoder = secondDecoder;
}
return decoder.decode(buf, state);
}
@Override
public boolean isApplicable(int paramNum, State state) {
public Decoder<Object> getDecoder(int paramNum, State state) {
NestedDecoderState ds = getDecoder(state);
if (paramNum == 0) {
ds.incFlipDecoderIndex();
@ -137,7 +120,7 @@ public class NestedMultiDecoder<T> implements MultiDecoder<Object> {
decoder = secondDecoder;
}
return decoder.isApplicable(paramNum, state);
return decoder.getDecoder(paramNum, state);
}
protected final NestedDecoderState getDecoder(State state) {

@ -18,8 +18,7 @@ package org.redisson.client.protocol.decoder;
import java.util.List;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -29,19 +28,14 @@ import io.netty.buffer.ByteBuf;
*/
public class ObjectFirstResultReplayDecoder<T> implements MultiDecoder<T> {
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
}
@Override
public T decode(List<Object> parts, State state) {
return (T) parts.get(0);
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
public Decoder<Object> getDecoder(int paramNum, State state) {
return null;
}
}

@ -15,13 +15,11 @@
*/
package org.redisson.client.protocol.decoder;
import java.math.BigDecimal;
import java.util.List;
import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import org.redisson.client.protocol.Decoder;
/**
*
@ -32,8 +30,11 @@ import io.netty.util.CharsetUtil;
public class ObjectFirstScoreReplayDecoder implements MultiDecoder<Double> {
@Override
public Object decode(ByteBuf buf, State state) {
return new BigDecimal(buf.toString(CharsetUtil.UTF_8)).doubleValue();
public Decoder<Object> getDecoder(int paramNum, State state) {
if (paramNum % 2 != 0) {
return DoubleCodec.INSTANCE.getValueDecoder();
}
return null;
}
@Override
@ -41,9 +42,4 @@ public class ObjectFirstScoreReplayDecoder implements MultiDecoder<Double> {
return (Double) parts.get(1);
}
@Override
public boolean isApplicable(int paramNum, State state) {
return paramNum % 2 != 0;
}
}

@ -15,13 +15,11 @@
*/
package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.List;
import org.redisson.client.codec.Codec;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -39,8 +37,8 @@ public class ObjectListDecoder<T> implements MultiDecoder<List<T>> {
}
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
return codec.getMapKeyDecoder().decode(buf, state);
public Decoder<Object> getDecoder(int paramNum, State state) {
return codec.getMapKeyDecoder();
}
@Override
@ -48,9 +46,4 @@ public class ObjectListDecoder<T> implements MultiDecoder<List<T>> {
return (List<T>) parts;
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
}
}

@ -18,8 +18,7 @@ package org.redisson.client.protocol.decoder;
import java.util.List;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -29,19 +28,13 @@ import io.netty.buffer.ByteBuf;
*/
public class ObjectListReplayDecoder<T> implements MultiDecoder<List<T>> {
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
}
@Override
public List<T> decode(List<Object> parts, State state) {
return (List<T>) parts;
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
public Decoder<Object> getDecoder(int paramNum, State state) {
return null;
}
}

@ -15,15 +15,13 @@
*/
package org.redisson.client.protocol.decoder;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.redisson.client.codec.Codec;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -42,11 +40,11 @@ public class ObjectMapDecoder implements MultiDecoder<Map<Object, Object>> {
private int pos;
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
public Decoder<Object> getDecoder(int paramNum, State state) {
if (pos++ % 2 == 0) {
return codec.getMapKeyDecoder().decode(buf, state);
return codec.getMapKeyDecoder();
}
return codec.getMapValueDecoder().decode(buf, state);
return codec.getMapValueDecoder();
}
@Override
@ -60,9 +58,4 @@ public class ObjectMapDecoder implements MultiDecoder<Map<Object, Object>> {
return result;
}
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
}
}

@ -22,8 +22,7 @@ import java.util.Map.Entry;
import java.util.Set;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -33,8 +32,8 @@ import io.netty.buffer.ByteBuf;
public class ObjectMapEntryReplayDecoder implements MultiDecoder<Set<Entry<Object, Object>>> {
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
public Decoder<Object> getDecoder(int paramNum, State state) {
return null;
}
@Override
@ -48,9 +47,4 @@ public class ObjectMapEntryReplayDecoder implements MultiDecoder<Set<Entry<Objec
return result.entrySet();
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
}
}

@ -20,8 +20,7 @@ import java.util.List;
import java.util.Map;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -30,11 +29,6 @@ import io.netty.buffer.ByteBuf;
*/
public class ObjectMapReplayDecoder implements MultiDecoder<Map<Object, Object>> {
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
}
@Override
public Map<Object, Object> decode(List<Object> parts, State state) {
Map<Object, Object> result = new LinkedHashMap<Object, Object>(parts.size()/2);
@ -47,8 +41,8 @@ public class ObjectMapReplayDecoder implements MultiDecoder<Map<Object, Object>>
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
public Decoder<Object> getDecoder(int paramNum, State state) {
return null;
}
}

@ -20,8 +20,7 @@ import java.util.List;
import java.util.Set;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import org.redisson.client.protocol.Decoder;
/**
*
@ -31,19 +30,14 @@ import io.netty.buffer.ByteBuf;
*/
public class ObjectSetReplayDecoder<T> implements MultiDecoder<Set<T>> {
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
}
@Override
public Set<T> decode(List<Object> parts, State state) {
return new LinkedHashSet(parts);
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
public Decoder<Object> getDecoder(int paramNum, State state) {
return null;
}
}

@ -15,16 +15,14 @@
*/
package org.redisson.client.protocol.decoder;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.ScoredEntry;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
/**
*
* @author Nikita Koksharov
@ -34,8 +32,11 @@ import io.netty.util.CharsetUtil;
public class ScoredSortedSetReplayDecoder<T> implements MultiDecoder<List<ScoredEntry<T>>> {
@Override
public Object decode(ByteBuf buf, State state) {
return new BigDecimal(buf.toString(CharsetUtil.UTF_8));
public Decoder<Object> getDecoder(int paramNum, State state) {
if (paramNum % 2 != 0) {
return DoubleCodec.INSTANCE.getValueDecoder();
}
return null;
}
@Override
@ -47,9 +48,4 @@ public class ScoredSortedSetReplayDecoder<T> implements MultiDecoder<List<Scored
return result;
}
@Override
public boolean isApplicable(int paramNum, State state) {
return paramNum % 2 != 0;
}
}

@ -15,12 +15,9 @@
*/
package org.redisson.client.protocol.decoder;
import java.math.BigDecimal;
import org.redisson.client.codec.DoubleCodec;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import org.redisson.client.protocol.Decoder;
/**
*
@ -31,13 +28,11 @@ import io.netty.util.CharsetUtil;
public class ScoredSortedSetScanDecoder<T> extends ObjectListReplayDecoder<T> {
@Override
public Object decode(ByteBuf buf, State state) {
return new BigDecimal(buf.toString(CharsetUtil.UTF_8));
}
@Override
public boolean isApplicable(int paramNum, State state) {
return paramNum % 2 != 0;
public Decoder<Object> getDecoder(int paramNum, State state) {
if (paramNum % 2 != 0) {
return DoubleCodec.INSTANCE.getValueDecoder();
}
return super.getDecoder(paramNum, state);
}
}

@ -17,10 +17,9 @@ package org.redisson.client.protocol.decoder;
import java.util.List;
import org.redisson.client.codec.LongCodec;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import org.redisson.client.protocol.Decoder;
/**
*
@ -30,8 +29,11 @@ import io.netty.util.CharsetUtil;
public class ScoredSortedSetScanReplayDecoder implements MultiDecoder<ListScanResult<Object>> {
@Override
public Object decode(ByteBuf buf, State state) {
return Long.valueOf(buf.toString(CharsetUtil.UTF_8));
public Decoder<Object> getDecoder(int paramNum, State state) {
if (paramNum == 0) {
return LongCodec.INSTANCE.getValueDecoder();
}
return null;
}
@Override
@ -43,9 +45,4 @@ public class ScoredSortedSetScanReplayDecoder implements MultiDecoder<ListScanRe
return new ListScanResult<Object>((Long)parts.get(0), values);
}
@Override
public boolean isApplicable(int paramNum, State state) {
return paramNum == 0;
}
}

@ -22,12 +22,11 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.cluster.ClusterSlotRange;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
/**
*
* @author Nikita Koksharov
@ -36,8 +35,8 @@ import io.netty.util.CharsetUtil;
public class SlotsDecoder implements MultiDecoder<Object> {
@Override
public Object decode(ByteBuf buf, State state) {
return buf.toString(CharsetUtil.UTF_8);
public Decoder<Object> getDecoder(int paramNum, State state) {
return StringCodec.INSTANCE.getValueDecoder();
}
@Override
@ -62,9 +61,4 @@ public class SlotsDecoder implements MultiDecoder<Object> {
return parts;
}
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
}
}

@ -18,10 +18,9 @@ package org.redisson.client.protocol.decoder;
import java.util.Arrays;
import java.util.List;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.handler.State;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import org.redisson.client.protocol.Decoder;
/**
*
@ -31,8 +30,8 @@ import io.netty.util.CharsetUtil;
public class StringListReplayDecoder implements MultiDecoder<List<String>> {
@Override
public Object decode(ByteBuf buf, State state) {
return buf.toString(CharsetUtil.UTF_8);
public Decoder<Object> getDecoder(int paramNum, State state) {
return StringCodec.INSTANCE.getValueDecoder();
}
@Override
@ -40,9 +39,4 @@ public class StringListReplayDecoder implements MultiDecoder<List<String>> {
return Arrays.asList(Arrays.copyOf(parts.toArray(), parts.size(), String[].class));
}
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
}
}

@ -15,15 +15,12 @@
*/
package org.redisson.client.protocol.pubsub;
import java.io.IOException;
import java.util.List;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.decoder.MultiDecoder;
import io.netty.buffer.ByteBuf;
public class PubSubMessageDecoder implements MultiDecoder<Object> {
private final Decoder<Object> decoder;
@ -34,8 +31,8 @@ public class PubSubMessageDecoder implements MultiDecoder<Object> {
}
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
return decoder.decode(buf, null);
public Decoder<Object> getDecoder(int paramNum, State state) {
return decoder;
}
@Override
@ -43,9 +40,4 @@ public class PubSubMessageDecoder implements MultiDecoder<Object> {
return new PubSubMessage(parts.get(1).toString(), parts.get(2));
}
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
}
}

@ -15,15 +15,12 @@
*/
package org.redisson.client.protocol.pubsub;
import java.io.IOException;
import java.util.List;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.decoder.MultiDecoder;
import io.netty.buffer.ByteBuf;
public class PubSubPatternMessageDecoder implements MultiDecoder<Object> {
private final Decoder<Object> decoder;
@ -34,8 +31,8 @@ public class PubSubPatternMessageDecoder implements MultiDecoder<Object> {
}
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
return decoder.decode(buf, null);
public Decoder<Object> getDecoder(int paramNum, State state) {
return decoder;
}
@Override
@ -43,9 +40,4 @@ public class PubSubPatternMessageDecoder implements MultiDecoder<Object> {
return new PubSubPatternMessage(parts.get(1).toString(), parts.get(2).toString(), parts.get(3));
}
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
}
}

@ -15,9 +15,11 @@
*/
package org.redisson.client.protocol.pubsub;
import java.io.IOException;
import java.util.List;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.decoder.MultiDecoder;
import io.netty.buffer.ByteBuf;
@ -26,10 +28,16 @@ import io.netty.util.CharsetUtil;
public class PubSubStatusDecoder implements MultiDecoder<Object> {
@Override
public Object decode(ByteBuf buf, State state) {
String status = buf.toString(CharsetUtil.UTF_8);
buf.skipBytes(2);
return status;
public Decoder<Object> getDecoder(int paramNum, State state) {
return new Decoder<Object>() {
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
String status = buf.toString(CharsetUtil.UTF_8);
buf.skipBytes(2);
return status;
}
};
}
@Override
@ -37,9 +45,4 @@ public class PubSubStatusDecoder implements MultiDecoder<Object> {
return new PubSubStatusMessage(PubSubType.valueOf(parts.get(0).toString().toUpperCase()), parts.get(1).toString());
}
@Override
public boolean isApplicable(int paramNum, State state) {
return true;
}
}

@ -19,10 +19,9 @@ import java.util.Collection;
import java.util.List;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.decoder.MultiDecoder;
import io.netty.buffer.ByteBuf;
public class ListDrainToDecoder<V> implements MultiDecoder<Integer> {
private Collection<Object> list;
@ -31,11 +30,6 @@ public class ListDrainToDecoder<V> implements MultiDecoder<Integer> {
this.list = list;
}
@Override
public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException();
}
@Override
public Integer decode(List<Object> parts, State state) {
list.addAll(parts);
@ -43,8 +37,8 @@ public class ListDrainToDecoder<V> implements MultiDecoder<Integer> {
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
public Decoder<Object> getDecoder(int paramNum, State state) {
return null;
}
}

@ -22,6 +22,7 @@ import java.util.List;
import org.redisson.client.codec.LongCodec;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.decoder.MultiDecoder;
import io.netty.buffer.ByteBuf;
@ -48,13 +49,8 @@ public class MapCacheGetAllDecoder implements MultiDecoder<List<Object>> {
}
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
return LongCodec.INSTANCE.getValueDecoder().decode(buf, state);
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
public Decoder<Object> getDecoder(int paramNum, State state) {
return null;
}
@Override

@ -15,17 +15,15 @@
*/
package org.redisson.connection.decoder;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.decoder.MultiDecoder;
import io.netty.buffer.ByteBuf;
/**
*
* @author Nikita Koksharov
@ -48,13 +46,8 @@ public class MapGetAllDecoder implements MultiDecoder<Map<Object, Object>> {
}
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public boolean isApplicable(int paramNum, State state) {
return false;
public Decoder<Object> getDecoder(int paramNum, State state) {
return null;
}
@Override

Loading…
Cancel
Save