Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added initial byteBuffer conversions

  • Loading branch information...
commit 4892fc8e5db2b6b77884c61f2eba8d1fdcc487c1 1 parent 8e360e6
zznate authored
View
20 src/main/java/me/prettyprint/cassandra/serializers/AbstractSerializer.java
@@ -1,6 +1,8 @@
package me.prettyprint.cassandra.serializers;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
@@ -24,9 +26,27 @@
@Override
public abstract byte[] toBytes(T obj);
+
+ public ByteBuffer toByteBuffer(T obj) {
+ return ByteBuffer.wrap(toBytes(obj));
+ }
+
+ public ByteBuffer toByteBuffer(T obj, ByteBuffer byteBuffer, int offset, int length) {
+ byteBuffer.put(toBytes(obj), offset, length);
+ return byteBuffer;
+ }
@Override
public abstract T fromBytes(byte[] bytes);
+
+ public T fromByteBuffer(ByteBuffer byteBuffer) {
+ return fromBytes(byteBuffer.array());
+ }
+
+ public T fromByteBuffer(ByteBuffer byteBuffer, int offset, int length) {
+ return fromBytes(Arrays.copyOfRange(byteBuffer.array(), offset, length));
+ }
+
@Override
public Set<byte[]> toBytesSet(List<T> list) {
View
5 src/main/java/me/prettyprint/hector/api/Serializer.java
@@ -1,5 +1,6 @@
package me.prettyprint.hector.api;
+import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -29,6 +30,8 @@
* @return
*/
public byte[] toBytes(T obj);
+
+ public ByteBuffer toByteBuffer(T obj);
/**
* Extract an object of type T from the bytes.
@@ -36,6 +39,8 @@
* @return
*/
public T fromBytes(byte[] bytes);
+
+ public T fromByteBuffer(ByteBuffer byteBuffer);
public Set<byte[]> toBytesSet(List<T> list);
Please sign in to comment.
Something went wrong with that request. Please try again.