Eliminate some unnecessary byte copy / convertion

This commit is contained in:
Norman Maurer 2012-03-11 20:53:55 +01:00
parent 143ba76176
commit 2b32c3fb59
3 changed files with 8 additions and 8 deletions

View File

@ -22,16 +22,16 @@ import java.io.IOException;
public class ErrorReply extends Reply {
public static final char MARKER = '-';
private static final byte[] ERR = "ERR ".getBytes();
public final String error;
public final ChannelBuffer error;
public ErrorReply(String error) {
public ErrorReply(ChannelBuffer error) {
this.error = error;
}
public void write(ChannelBuffer os) throws IOException {
os.writeByte(MARKER);
os.writeBytes(ERR);
os.writeBytes(error.getBytes("UTF-8"));
os.writeBytes(error);
os.writeBytes(Command.CRLF);
}
}

View File

@ -92,12 +92,12 @@ public class RedisDecoder extends ReplayingDecoder<State> {
int code = is.readByte();
switch (code) {
case StatusReply.MARKER: {
String status = is.readBytes(is.bytesBefore(ChannelBufferIndexFinder.CRLF)).toString(UTF_8);
ChannelBuffer status = is.readBytes(is.bytesBefore(ChannelBufferIndexFinder.CRLF));
is.skipBytes(2);
return new StatusReply(status);
}
case ErrorReply.MARKER: {
String error = is.readBytes(is.bytesBefore(ChannelBufferIndexFinder.CRLF)).toString(UTF_8);
ChannelBuffer error = is.readBytes(is.bytesBefore(ChannelBufferIndexFinder.CRLF));
is.skipBytes(2);
return new ErrorReply(error);
}

View File

@ -21,15 +21,15 @@ import java.io.IOException;
public class StatusReply extends Reply {
public static final char MARKER = '+';
public final String status;
public final ChannelBuffer status;
public StatusReply(String status) {
public StatusReply(ChannelBuffer status) {
this.status = status;
}
public void write(ChannelBuffer os) throws IOException {
os.writeByte(MARKER);
os.writeBytes(status.getBytes("UTF-8"));
os.writeBytes(status);
os.writeBytes(Command.CRLF);
}
}