new commands added
parent
3204255277
commit
a50a2f0154
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.redisson.client.protocol;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
public class IntegerCodec implements Codec {
|
||||
|
||||
public static final IntegerCodec INSTANCE = new IntegerCodec();
|
||||
|
||||
@Override
|
||||
public byte[] encode(int paramIndex, Object in) {
|
||||
try {
|
||||
return in.toString().getBytes("UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuf buf) {
|
||||
if (buf == null) {
|
||||
return null;
|
||||
}
|
||||
return Integer.valueOf(buf.toString(CharsetUtil.UTF_8));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package org.redisson.client.protocol;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufInputStream;
|
||||
|
||||
public class JsonCodec implements Codec {
|
||||
|
||||
public static final JsonCodec INSTANCE = new JsonCodec();
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public byte[] encode(int paramIndex, Object in) {
|
||||
try {
|
||||
return mapper.writeValueAsBytes(in);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuf buf) {
|
||||
try {
|
||||
return mapper.readValue(new ByteBufInputStream(buf), Object.class);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package org.redisson.client.protocol;
|
||||
|
||||
public class KeyValueMessage<K, V> {
|
||||
|
||||
private K key;
|
||||
private V value;
|
||||
|
||||
public KeyValueMessage(K key, V value) {
|
||||
super();
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package org.redisson.client.protocol;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.redisson.client.protocol.pubsub.MultiDecoder;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
public class KeyValueObjectDecoder implements MultiDecoder<Object> {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuf buf) {
|
||||
String status = buf.toString(CharsetUtil.UTF_8);
|
||||
buf.skipBytes(2);
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(List<Object> parts) {
|
||||
return new KeyValueMessage(parts.get(0), parts.get(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(int paramNum) {
|
||||
return paramNum == 0;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package org.redisson.client.protocol.decoder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.redisson.client.protocol.pubsub.MultiDecoder;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ObjectListReplayDecoder implements MultiDecoder<List<Object>> {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuf buf) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> decode(List<Object> parts) {
|
||||
return parts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(int paramNum) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package org.redisson.client.protocol.decoder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.redisson.client.protocol.pubsub.MultiDecoder;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ObjectMapReplayDecoder implements MultiDecoder<Map<Object, Object>> {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuf buf) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Object, Object> decode(List<Object> parts) {
|
||||
Map<Object, Object> result = new HashMap<Object, Object>(parts.size()/2);
|
||||
for (int i = 0; i < parts.size(); i++) {
|
||||
if (i % 2 != 0) {
|
||||
result.put(parts.get(i-1).toString(), parts.get(i).toString());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isApplicable(int paramNum) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package org.redisson.client.protocol.decoder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.redisson.client.protocol.pubsub.MultiDecoder;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
public class StringListObjectReplayDecoder implements MultiDecoder<Object> {
|
||||
|
||||
@Override
|
||||
public Object decode(ByteBuf buf) {
|
||||
return buf.toString(CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object decode(List<Object> parts) {
|
||||
return parts;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.redisson.client.protocol.decoder;
|
||||
|
||||
import org.redisson.client.protocol.Decoder;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.util.CharsetUtil;
|
||||
|
||||
public class StringObjectDecoder implements Decoder<Object> {
|
||||
|
||||
@Override
|
||||
public String decode(ByteBuf buf) {
|
||||
String status = buf.readBytes(buf.bytesBefore((byte) '\r')).toString(CharsetUtil.UTF_8);
|
||||
buf.skipBytes(2);
|
||||
return status;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue