List of usage examples for io.netty.buffer ByteBuf writeByte
public abstract ByteBuf writeByte(int value);
From source file:com.gemstone.gemfire.internal.redis.Coder.java
License:Apache License
public static final ByteBuf getBulkStringResponse(ByteBufAllocator alloc, byte[] value) { ByteBuf response = alloc.buffer(value.length + 20); response.writeByte(BULK_STRING_ID); response.writeBytes(intToBytes(value.length)); response.writeBytes(CRLFar);/*from ww w .j a va 2 s . com*/ response.writeBytes(value); response.writeBytes(CRLFar); return response; }
From source file:com.gemstone.gemfire.internal.redis.Coder.java
License:Apache License
public static final ByteBuf getBulkStringResponse(ByteBufAllocator alloc, double value) { ByteBuf response = alloc.buffer(); byte[] doub = doubleToBytes(value); response.writeByte(BULK_STRING_ID); response.writeBytes(intToBytes(doub.length)); response.writeBytes(CRLFar);/* w w w . jav a 2 s .c o m*/ response.writeBytes(doub); response.writeBytes(CRLFar); return response; }
From source file:com.gemstone.gemfire.internal.redis.Coder.java
License:Apache License
public static final ByteBuf getBulkStringResponse(ByteBufAllocator alloc, String value) { byte[] valueAr = stringToBytes(value); int length = valueAr == null ? 0 : valueAr.length; ByteBuf response = alloc.buffer(length + 20); response.writeByte(BULK_STRING_ID); response.writeBytes(intToBytes(length)); response.writeBytes(CRLFar);//from w w w . ja v a 2 s .c o m response.writeBytes(valueAr); response.writeBytes(CRLFar); return response; }
From source file:com.gemstone.gemfire.internal.redis.Coder.java
License:Apache License
public static final ByteBuf getBulkStringArrayResponse(ByteBufAllocator alloc, List<String> items) { Iterator<String> it = items.iterator(); ByteBuf response = alloc.buffer(); response.writeByte(ARRAY_ID); response.writeBytes(intToBytes(items.size())); response.writeBytes(CRLFar);//from w w w . j a v a 2 s .c o m while (it.hasNext()) { String next = it.next(); response.writeByte(BULK_STRING_ID); response.writeBytes(intToBytes(next.length())); response.writeBytes(CRLFar); response.writeBytes(stringToBytes(next)); response.writeBytes(CRLFar); } return response; }
From source file:com.gemstone.gemfire.internal.redis.Coder.java
License:Apache License
public static final ByteBuf getBulkStringArrayResponse(ByteBufAllocator alloc, Collection<ByteArrayWrapper> items) { Iterator<ByteArrayWrapper> it = items.iterator(); ByteBuf response = alloc.buffer(); response.writeByte(ARRAY_ID); response.writeBytes(intToBytes(items.size())); response.writeBytes(CRLFar);/*from w ww .j a v a 2 s . c om*/ while (it.hasNext()) { ByteArrayWrapper nextWrapper = it.next(); if (nextWrapper != null) { response.writeByte(BULK_STRING_ID); response.writeBytes(intToBytes(nextWrapper.length())); response.writeBytes(CRLFar); response.writeBytes(nextWrapper.toBytes()); response.writeBytes(CRLFar); } else response.writeBytes(getNilResponse(alloc)); } return response; }
From source file:com.gemstone.gemfire.internal.redis.Coder.java
License:Apache License
public static final ByteBuf getKeyValArrayResponse(ByteBufAllocator alloc, Collection<Entry<ByteArrayWrapper, ByteArrayWrapper>> items) { Iterator<Map.Entry<ByteArrayWrapper, ByteArrayWrapper>> it = items.iterator(); ByteBuf response = alloc.buffer(); response.writeByte(ARRAY_ID); int size = 0; ByteBuf tmp = alloc.buffer();/*from w ww. jav a2s .co m*/ while (it.hasNext()) { Map.Entry<ByteArrayWrapper, ByteArrayWrapper> next = it.next(); byte[] key; byte[] nextByteArray; try { key = next.getKey().toBytes(); nextByteArray = next.getValue().toBytes(); } catch (EntryDestroyedException e) { continue; } tmp.writeByte(BULK_STRING_ID); // Add key tmp.writeBytes(intToBytes(key.length)); tmp.writeBytes(CRLFar); tmp.writeBytes(key); tmp.writeBytes(CRLFar); tmp.writeByte(BULK_STRING_ID); // Add value tmp.writeBytes(intToBytes(nextByteArray.length)); tmp.writeBytes(CRLFar); tmp.writeBytes(nextByteArray); tmp.writeBytes(CRLFar); size++; } response.writeBytes(intToBytes(size * 2)); response.writeBytes(CRLFar); response.writeBytes(tmp); tmp.release(); return response; }
From source file:com.gemstone.gemfire.internal.redis.Coder.java
License:Apache License
public static final ByteBuf getScanResponse(ByteBufAllocator alloc, List<?> items) { ByteBuf response = alloc.buffer(); response.writeByte(ARRAY_ID); response.writeBytes(intToBytes(2));//from www . j ava 2 s. c o m response.writeBytes(CRLFar); response.writeByte(BULK_STRING_ID); byte[] cursor = stringToBytes((String) items.get(0)); response.writeBytes(intToBytes(cursor.length)); response.writeBytes(CRLFar); response.writeBytes(cursor); response.writeBytes(CRLFar); items = items.subList(1, items.size()); Iterator<?> it = items.iterator(); response.writeByte(ARRAY_ID); response.writeBytes(intToBytes(items.size())); response.writeBytes(CRLFar); while (it.hasNext()) { Object nextObject = it.next(); if (nextObject instanceof String) { String next = (String) nextObject; response.writeByte(BULK_STRING_ID); response.writeBytes(intToBytes(next.length())); response.writeBytes(CRLFar); response.writeBytes(stringToBytes(next)); response.writeBytes(CRLFar); } else if (nextObject instanceof ByteArrayWrapper) { byte[] next = ((ByteArrayWrapper) nextObject).toBytes(); response.writeByte(BULK_STRING_ID); response.writeBytes(intToBytes(next.length)); response.writeBytes(CRLFar); response.writeBytes(next); response.writeBytes(CRLFar); } } return response; }
From source file:com.gemstone.gemfire.internal.redis.Coder.java
License:Apache License
public static final ByteBuf getSimpleStringResponse(ByteBufAllocator alloc, String string) { byte[] simpAr = stringToBytes(string); ByteBuf response = alloc.buffer(simpAr.length + 20); response.writeByte(SIMPLE_STRING_ID); response.writeBytes(simpAr);//from w ww . jav a 2 s.c o m response.writeBytes(CRLFar); return response; }
From source file:com.gemstone.gemfire.internal.redis.Coder.java
License:Apache License
public static final ByteBuf getErrorResponse(ByteBufAllocator alloc, String error) { byte[] errorAr = stringToBytes(error); ByteBuf response = alloc.buffer(errorAr.length + 25); response.writeByte(ERROR_ID); response.writeBytes(err);//from w ww . ja v a2s . c om response.writeBytes(errorAr); response.writeBytes(CRLFar); return response; }
From source file:com.gemstone.gemfire.internal.redis.Coder.java
License:Apache License
public static final ByteBuf getNoAuthResponse(ByteBufAllocator alloc, String error) { byte[] errorAr = stringToBytes(error); ByteBuf response = alloc.buffer(errorAr.length + 25); response.writeByte(ERROR_ID); response.writeBytes(noAuth);//from www .j av a 2 s .co m response.writeBytes(errorAr); response.writeBytes(CRLFar); return response; }