List of usage examples for io.netty.buffer ByteBuf readByte
public abstract byte readByte();
From source file:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java
License:Open Source License
public static int readInt(ByteBuf in) { byte b0 = in.readByte(); byte b1 = in.readByte(); return (b0 & 0xff) | ((b1 & 0xff) << 8); }
From source file:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java
License:Open Source License
public static Timestamp readTimestamp(ByteBuf in) { byte length = in.readByte(); int year = readInt(in); byte month = readByte(in); byte date = readByte(in); int hour = readByte(in); int minute = readByte(in); int second = readByte(in); if (length == 11) { long nanos = readUB4(in) * 1000; Calendar cal = getLocalCalendar(); cal.set(year, --month, date, hour, minute, second); Timestamp time = new Timestamp(cal.getTimeInMillis()); time.setNanos((int) nanos); return time; } else {/*from w w w . java2 s. c o m*/ Calendar cal = getLocalCalendar(); cal.set(year, --month, date, hour, minute, second); return new Timestamp(cal.getTimeInMillis()); } }
From source file:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java
License:Open Source License
public static byte readByte(ByteBuf in) { byte b0 = in.readByte(); return b0; }
From source file:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java
License:Open Source License
public static long readUB4(ByteBuf in) { long l = in.readByte() & 0xff; l |= (in.readByte() & 0xff) << 8; l |= (in.readByte() & 0xff) << 16; l |= (in.readByte() & 0xff) << 24; return l;/*w ww. j av a 2 s . c o m*/ }
From source file:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java
License:Open Source License
/** public static byte[] readBytesWithNull(ByteBuf in) { final byte[] b = this.data;/*from www .j ava2 s. c o m*/ if (position >= length) { return EMPTY_BYTES; } int offset = -1; for (int i = position; i < length; i++) { if (b[i] == 0) { offset = i; break; } } switch (offset) { case -1: byte[] ab1 = new byte[length - position]; System.arraycopy(b, position, ab1, 0, ab1.length); position = length; return ab1; case 0: position++; return EMPTY_BYTES; default: byte[] ab2 = new byte[offset - position]; System.arraycopy(b, position, ab2, 0, ab2.length); position = offset + 1; return ab2; } } */ public static byte[] readBytesWithLength(ByteBuf in) { int length = (int) in.readByte(); if (length == NULL_LENGTH) { return null; } if (length <= 0) { return EMPTY_BYTES; } byte[] ab = new byte[length]; in.readBytes(ab, 0, length); return ab; }
From source file:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java
License:Open Source License
public static long readPackedInteger(ByteBuf in, int size) { byte b0 = in.readByte(); int length = b0 & 0xff; long val; int count = 1; switch (length) { case 251:// w w w .java 2 s .c o m val = NULL_LENGTH; break; case 252: val = (b0 & 0xff) | ((in.readByte() & 0xff) << 8) | ((in.readByte() & 0xff) << 16); count = 3; break; case 253: val = (b0 & 0xff) | ((in.readByte() & 0xff) << 8) | ((in.readByte() & 0xff) << 16) | ((in.readByte() & 0xff) << 24); count = 4; break; case 254: val = (b0 & 0xff) | ((in.readByte() & 0xff) << 8) | ((in.readByte() & 0xff) << 16) | ((in.readByte() & 0xff) << 24) | ((in.readByte() & 0xff) << 32) | ((in.readByte() & 0xff) << 40) | ((in.readByte() & 0xff) << 48) | ((in.readByte() & 0xff) << 56) | ((in.readByte() & 0xff) << 64); count = 9; break; default: val = length; } if (size > count) readBytes(in, size - count); return val; }
From source file:com.antsdb.saltedfish.server.mysql.util.BufferUtils.java
License:Open Source License
public static long readLength(ByteBuf in) { int length = in.readByte() & 0xff; switch (length) { case 251:/*from w w w .j a v a 2s.c om*/ return NULL_LENGTH; case 252: return readInt(in); case 253: return readLongInt(in); case 254: return readLongLong(in); default: return length; } }
From source file:com.basho.riak.client.core.netty.HealthCheckDecoder.java
License:Apache License
@Override protected void decode(ChannelHandlerContext chc, ByteBuf in, List<Object> list) throws Exception { // Make sure we have 4 bytes if (in.readableBytes() >= 4) { in.markReaderIndex();//from ww w. j a v a 2s. c o m int length = in.readInt(); // See if we have the full frame. if (in.readableBytes() < length) { in.resetReaderIndex(); } else { byte code = in.readByte(); byte[] protobuf = new byte[length - 1]; in.readBytes(protobuf); chc.channel().pipeline().remove(this); if (code == RiakMessageCodes.MSG_ErrorResp) { logger.debug("Received MSG_ErrorResp reply to healthcheck"); future.setException((riakErrorToException(protobuf))); } else { logger.debug("Healthcheck op successful; returned code {}", code); future.setMessage(new RiakMessage(code, protobuf)); } } } }
From source file:com.basho.riak.client.core.netty.RiakMessageCodec.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { // Make sure we have 4 bytes if (in.readableBytes() >= 4) { in.markReaderIndex();//from w w w.j a v a 2 s . c om int length = in.readInt(); // See if we have the full frame. if (in.readableBytes() < length) { in.resetReaderIndex(); return; } else { byte code = in.readByte(); byte[] array = new byte[length - 1]; in.readBytes(array); out.add(new RiakMessage(code, array)); } } }
From source file:com.basho.riak.client.core.netty.RiakSecurityDecoder.java
License:Apache License
@Override protected void decode(ChannelHandlerContext chc, ByteBuf in, List<Object> out) throws Exception { // Make sure we have 4 bytes if (in.readableBytes() >= 4) { in.markReaderIndex();//from ww w. j a v a 2 s . c om int length = in.readInt(); // See if we have the full frame. if (in.readableBytes() < length) { in.resetReaderIndex(); } else { byte code = in.readByte(); byte[] protobuf = new byte[length - 1]; in.readBytes(protobuf); switch (state) { case TLS_WAIT: switch (code) { case RiakMessageCodes.MSG_StartTls: logger.debug("Received MSG_RpbStartTls reply"); // change state this.state = State.SSL_WAIT; // insert SSLHandler SslHandler sslHandler = new SslHandler(sslEngine); // get promise Future<Channel> hsFuture = sslHandler.handshakeFuture(); // register callback hsFuture.addListener(new SslListener()); // Add handler chc.channel().pipeline().addFirst(Constants.SSL_HANDLER, sslHandler); break; case RiakMessageCodes.MSG_ErrorResp: logger.debug("Received MSG_ErrorResp reply to startTls"); promise.tryFailure((riakErrorToException(protobuf))); break; default: promise.tryFailure( new RiakResponseException(0, "Invalid return code during StartTLS; " + code)); } break; case AUTH_WAIT: chc.channel().pipeline().remove(this); switch (code) { case RiakMessageCodes.MSG_AuthResp: logger.debug("Received MSG_RpbAuthResp reply"); promise.trySuccess(null); break; case RiakMessageCodes.MSG_ErrorResp: logger.debug("Received MSG_ErrorResp reply to auth"); promise.tryFailure(riakErrorToException(protobuf)); break; default: promise.tryFailure( new RiakResponseException(0, "Invalid return code during Auth; " + code)); } break; default: // WTF? logger.error("Received message while not in TLS_WAIT or AUTH_WAIT"); promise.tryFailure( new IllegalStateException("Received message while not in TLS_WAIT or AUTH_WAIT")); } } } }