Search in sources :

Example 1 with EzyEntityCodec

use of com.tvd12.ezyfox.codec.EzyEntityCodec in project calabash by youngmonkeys.

the class LocalMapPersistExample method test.

@SuppressWarnings("rawtypes")
public void test() {
    EzyEntityCodec entityCodec = newEntityCodec();
    SimpleSettings settings = new SimpleSettings();
    SimpleMapPersistSetting mapPersistSetting = new SimpleMapPersistSetting();
    SimpleMapSetting mapSetting = new SimpleMapSetting();
    mapSetting.setMapName(CollectionNames.PERSON);
    mapSetting.setPersistSetting(mapPersistSetting);
    settings.addMapSetting(mapSetting);
    EzyBeanContext beanContext = newBeanContext();
    SimpleEntityMapPersistFactory.Builder mapPersistFactoryBuilder = SimpleEntityMapPersistFactory.builder();
    List mapPersistenceList = beanContext.getSingletons(MapPersistence.class);
    for (Object mapPersist : mapPersistenceList) {
        String mapName = MapPersistenceAnnotations.getMapName(mapPersist);
        mapPersistFactoryBuilder.addMapPersist(mapName, (EntityMapPersist) mapPersist);
    }
    BytesMapPersistFactory bytesMapPersistFactory = EntityBytesMapPersistFactory.builder().entityCodec(entityCodec).entityMapPersistFactory(mapPersistFactoryBuilder.build()).build();
    Calabash calabash = CalabashServerContext.builder().settings(settings).bytesMapPersistFactory(bytesMapPersistFactory).build();
    ByteArray keyBytes = new ByteArray(entityCodec.serialize(1L));
    byte[] values = entityCodec.serialize(new Person(9L, "bar", 29));
    BytesMap bytesMap = calabash.getBytesMap(CollectionNames.PERSON);
    bytesMap.put(keyBytes, values);
}
Also used : SimpleSettings(com.tvd12.calabash.server.core.setting.SimpleSettings) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) BytesMap(com.tvd12.calabash.core.BytesMap) SimpleMapSetting(com.tvd12.calabash.server.core.setting.SimpleMapSetting) ByteArray(com.tvd12.calabash.core.util.ByteArray) List(java.util.List) SimpleMapPersistSetting(com.tvd12.calabash.persist.setting.SimpleMapPersistSetting) Calabash(com.tvd12.calabash.Calabash) SimpleEntityMapPersistFactory(com.tvd12.calabash.persist.factory.SimpleEntityMapPersistFactory) EntityBytesMapPersistFactory(com.tvd12.calabash.persist.factory.EntityBytesMapPersistFactory) BytesMapPersistFactory(com.tvd12.calabash.persist.factory.BytesMapPersistFactory)

Example 2 with EzyEntityCodec

use of com.tvd12.ezyfox.codec.EzyEntityCodec in project calabash by youngmonkeys.

the class LocalMapPersistExample method newEntityCodec.

protected EzyEntityCodec newEntityCodec() {
    EzyBindingContext bindingContext = EzyBindingContext.builder().scan("com.tvd12.calabash.server.core.test.localmappersit").build();
    EzyMessageSerializer messageSerializer = new MsgPackSimpleSerializer();
    EzyMessageDeserializer messageDeserializer = new MsgPackSimpleDeserializer();
    return EzyBindingEntityCodec.builder().marshaller(bindingContext.newMarshaller()).unmarshaller(bindingContext.newUnmarshaller()).messageSerializer(messageSerializer).messageDeserializer(messageDeserializer).build();
}
Also used : EzyBindingContext(com.tvd12.ezyfox.binding.EzyBindingContext)

Example 3 with EzyEntityCodec

use of com.tvd12.ezyfox.codec.EzyEntityCodec in project ezyfox-examples by tvd12.

the class MsgpackExample method main.

public static void main(String[] args) {
    final EzyBindingContext bindingContext = EzyBindingContext.builder().scan("com.tvd12.ezyfox.example.msgpack").build();
    final EzyEntityCodec codec = EzyBindingEntityCodec.builder().marshaller(bindingContext.newMarshaller()).unmarshaller(bindingContext.newUnmarshaller()).messageSerializer(new MsgPackSimpleSerializer()).messageDeserializer(new MsgPackSimpleDeserializer()).build();
    final Transfer transfer = new Transfer(300, 100);
    final byte[] serializedBytes = codec.serialize(transfer);
    System.out.println(serializedBytes.length);
    System.out.println(Arrays.toString(serializedBytes));
    System.out.println(EzyPrints.printHex(serializedBytes));
    final Transfer deserializedObj = codec.deserialize(serializedBytes, Transfer.class);
    System.out.println(deserializedObj);
}
Also used : EzyBindingContext(com.tvd12.ezyfox.binding.EzyBindingContext) MsgPackSimpleSerializer(com.tvd12.ezyfox.codec.MsgPackSimpleSerializer) MsgPackSimpleDeserializer(com.tvd12.ezyfox.codec.MsgPackSimpleDeserializer) EzyEntityCodec(com.tvd12.ezyfox.codec.EzyEntityCodec)

Aggregations

EzyBindingContext (com.tvd12.ezyfox.binding.EzyBindingContext)2 Calabash (com.tvd12.calabash.Calabash)1 BytesMap (com.tvd12.calabash.core.BytesMap)1 ByteArray (com.tvd12.calabash.core.util.ByteArray)1 BytesMapPersistFactory (com.tvd12.calabash.persist.factory.BytesMapPersistFactory)1 EntityBytesMapPersistFactory (com.tvd12.calabash.persist.factory.EntityBytesMapPersistFactory)1 SimpleEntityMapPersistFactory (com.tvd12.calabash.persist.factory.SimpleEntityMapPersistFactory)1 SimpleMapPersistSetting (com.tvd12.calabash.persist.setting.SimpleMapPersistSetting)1 SimpleMapSetting (com.tvd12.calabash.server.core.setting.SimpleMapSetting)1 SimpleSettings (com.tvd12.calabash.server.core.setting.SimpleSettings)1 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)1 EzyEntityCodec (com.tvd12.ezyfox.codec.EzyEntityCodec)1 MsgPackSimpleDeserializer (com.tvd12.ezyfox.codec.MsgPackSimpleDeserializer)1 MsgPackSimpleSerializer (com.tvd12.ezyfox.codec.MsgPackSimpleSerializer)1 List (java.util.List)1