Skip to content

Instantly share code, notes, and snippets.

Created September 16, 2013 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/865913d6ef9419ca2cf4 to your computer and use it in GitHub Desktop.
Save anonymous/865913d6ef9419ca2cf4 to your computer and use it in GitHub Desktop.
private final AbstractCompositeSerializerPelopsCompatible<SomeKey> someKeySerialzier = new AbstractCompositeSerializerPelopsCompatible<SomeKey>(SomeKey.class);
@Test
public void testToByteBuffer(){
String SOME_STRING = "someKey------WordAsd";
Long SOME_LONG = 31414141L;
SomeKey key = new SomeKey(SOME_LONG, SOME_STRING );
ByteBuffer fromPelops = Bytes.composite()
.addLong(SOME_LONG)
.addUTF8(SOME_STRING )
.build().getBytes();
ByteBuffer fromCompositeSerializer = someKeySerialzier.toByteBuffer(key);
assertEquals(fromPelops, fromCompositeSerializer);
}
@Test
public void testFromByteBuffer(){
String SOME_STRING = "someKey------WordAsd";
Long SOME_LONG = 31414141L;
ByteBuffer fromPelops = Bytes.composite()
.addLong(SOME_LONG)
.addUTF8(SOME_STRING)
.build().getBytes();
SomeKey indexKey = someKeySerialzier.fromByteBuffer(fromPelops);
assertEquals(SOME_LONG, indexKey.getIntVal());
assertEquals(SOME_STRING, indexKey.getStringVal());
}
//the SomeKey.class
@Data
public class SomeKey {
@Component(ordinal=0) private int intVal;
@Component(ordinal=1) private String stringVal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment