/** * to long. * * @param b byte array. * @return long. */ public static long bytes2long(byte[] b) { return bytes2long(b, 0); }
public byte[] toByteArray() { return Bytes.copyOf(mBuffer, mCount); }
/** * to int. * * @param b byte array. * @return int. */ public static int bytes2int(byte[] b) { return bytes2int(b, 0); }
Bytes.short2bytes(MAGIC, header); Bytes.long2bytes(req.getId(), header, 4); int len = bos.writtenBytes(); checkPayload(channel, len); Bytes.int2bytes(len, header, 12);
int length = header.length; if (header.length < readable) { header = Bytes.copyOf(header, readable); buffer.readBytes(header, length, readable - length); if (header[i] == MAGIC_HIGH && header[i + 1] == MAGIC_LOW) { buffer.readerIndex(buffer.readerIndex() - header.length + i); header = Bytes.copyOf(header, i); break; int len = Bytes.bytes2int(header, 12); checkPayload(channel, len);
/** * to byte array. * * @param v value. * @param b byte array. */ public static void short2bytes(short v, byte[] b) { short2bytes(v, b, 0); }
/** * to byte array. * * @param v value. * @return byte[]. */ public static byte[] int2bytes(int v) { byte[] ret = {0, 0, 0, 0}; int2bytes(v, ret); return ret; }
/** * to byte array. * * @param v value. * @return byte[]. */ public static byte[] long2bytes(long v) { byte[] ret = {0, 0, 0, 0, 0, 0, 0, 0}; long2bytes(v, ret); return ret; }
/** * to base64 string. * * @param b byte array. * @param code base64 code string(0-63 is base64 char,64 is pad char). * @return base64 string. */ public static String bytes2base64(byte[] b, String code) { return bytes2base64(b, 0, b.length, code); }
/** * from base64 string. * * @param str base64 string. * @param offset offset. * @param length length. * @return byte array. */ public static byte[] base642bytes(String str, int offset, int length) { return base642bytes(str, offset, length, C64); }
/** * to int. * * @param b byte array. * @return int. */ public static float bytes2float(byte[] b) { return bytes2float(b, 0); }
/** * to long. * * @param b byte array. * @return double. */ public static double bytes2double(byte[] b) { return bytes2double(b, 0); }
Bytes.short2bytes(MAGIC, header); Bytes.long2bytes(req.getId(), header, 4); int len = bos.writtenBytes(); checkPayload(channel, len); Bytes.int2bytes(len, header, 12);
int length = header.length; if (header.length < readable) { header = Bytes.copyOf(header, readable); buffer.readBytes(header, length, readable - length); if (header[i] == MAGIC_HIGH && header[i + 1] == MAGIC_LOW) { buffer.readerIndex(buffer.readerIndex() - header.length + i); header = Bytes.copyOf(header, i); break; int len = Bytes.bytes2int(header, 12); checkPayload(channel, len);
/** * to byte array. * * @param v value. * @return byte[]. */ public static byte[] short2bytes(short v) { byte[] ret = {0, 0}; short2bytes(v, ret); return ret; }
/** * to byte array. * * @param v value. * @return byte[]. */ public static byte[] int2bytes(int v) { byte[] ret = {0, 0, 0, 0}; int2bytes(v, ret); return ret; }
/** * to byte array. * * @param v value. * @return byte[]. */ public static byte[] long2bytes(long v) { byte[] ret = {0, 0, 0, 0, 0, 0, 0, 0}; long2bytes(v, ret); return ret; }
/** * to base64 string. * * @param b byte array. * @return base64 string. */ public static String bytes2base64(byte[] b) { return bytes2base64(b, 0, b.length, BASE64); }
@Override public Object decode(Object jv) throws IOException { if (jv instanceof String) { return Bytes.base642bytes((String) jv); } return (byte[]) null; } };
/** * to int. * * @param b byte array. * @return int. */ public static float bytes2float(byte[] b) { return bytes2float(b, 0); }