/** * Returns the primitive type namespace. * * @return the primitive type namespace */ default Namespace namespace() { return Namespace.builder() .register(Namespaces.BASIC) .register(ServiceConfig.class) .build(); }
/** * Returns the protocol serializer. * * @return the protocol serializer */ protected Serializer serializer() { Serializer serializer = this.serializer; if (serializer == null) { synchronized (this) { serializer = this.serializer; if (serializer == null) { NamespaceConfig config = this.config.getNamespaceConfig(); if (config == null) { serializer = Serializer.using(Namespaces.BASIC); } else { serializer = Serializer.using(Namespace.builder() .register(Namespaces.BASIC) .nextId(Namespaces.BEGIN_USER_CUSTOM_ID) .register(new Namespace(config)) .build()); } this.serializer = serializer; } } } return serializer; }
/** * Deserializes given InputStream to an Object using Kryo instance in pool. * * @param stream input stream * @param <T> deserialized Object type * @return deserialized Object */ public <T> T deserialize(final InputStream stream) { return deserialize(stream, DEFAULT_BUFFER_SIZE); }
/** * Builds a {@link Namespace} instance. * * @param friendlyName friendly name for the namespace * @return KryoNamespace */ public Namespace build(String friendlyName) { if (!types.isEmpty()) { blocks.add(new RegistrationBlock(this.blockHeadId, types)); } return new Namespace(blocks, classLoader, registrationRequired, compatible, friendlyName).populate(1); }
/** * Deserializes given byte buffer to Object using Kryo instance in pool. * * @param buffer input with serialized bytes * @param <T> deserialized Object type * @return deserialized Object */ public <T> T deserialize(final ByteBuffer buffer) { ByteBufferInput in = new ByteBufferInput(buffer); Kryo kryo = borrow(); try { @SuppressWarnings("unchecked") T obj = (T) kryo.readClassAndObject(in); return obj; } finally { release(kryo); } }
serializerBuilder.withNamespace(new Namespace(namespaceConfig));
/** * Serializes given object to OutputStream using Kryo instance in pool. * * @param obj Object to serialize * @param stream to write to */ public void serialize(final Object obj, final OutputStream stream) { serialize(obj, stream, DEFAULT_BUFFER_SIZE); }
public Namespace(NamespaceConfig config) { this(buildRegistrationBlocks(config), Thread.currentThread().getContextClassLoader(), config.isRegistrationRequired(), config.isCompatible(), config.getName()); }
serializerBuilder.withNamespace(new Namespace(namespaceConfig));
/** * Serializes given object to byte array using Kryo instance in pool. * <p> * Note: Serialized bytes must be smaller than {@link #MAX_BUFFER_SIZE}. * * @param obj Object to serialize * @return serialized bytes */ public byte[] serialize(final Object obj) { return serialize(obj, DEFAULT_BUFFER_SIZE); }
/** * Builds a {@link Namespace} instance. * * @param friendlyName friendly name for the namespace * @return KryoNamespace */ public Namespace build(String friendlyName) { if (!types.isEmpty()) { blocks.add(new RegistrationBlock(this.blockHeadId, types)); } return new Namespace(blocks, classLoader, registrationRequired, compatible, friendlyName).populate(1); }
/** * Deserializes given InputStream to an Object using Kryo instance in pool. * * @param stream input stream * @param <T> deserialized Object type * @param bufferSize size of the buffer in front of the stream * @return deserialized Object */ public <T> T deserialize(final InputStream stream, final int bufferSize) { ByteBufferInput in = new ByteBufferInput(stream, bufferSize); Kryo kryo = borrow(); try { @SuppressWarnings("unchecked") T obj = (T) kryo.readClassAndObject(in); return obj; } finally { release(kryo); } }
public Namespace(NamespaceConfig config) { this(buildRegistrationBlocks(config), Thread.currentThread().getContextClassLoader(), config.isRegistrationRequired(), config.isCompatible(), config.getName()); }
@Override public Namespace namespace() { return Namespace.builder() .nextId(Namespaces.BEGIN_USER_CUSTOM_ID + 200) .register(PrimaryBackupPartitionGroupConfig.class) .register(MemberGroupStrategy.class) .build(); }
serializerBuilder.withNamespace(new Namespace(namespaceConfig));
@Override public <T> T decode(byte[] bytes) { return namespace.deserialize(bytes); } };
@Override public <T> byte[] encode(T object) { return namespace.serialize(object); }
/** * Serializes given object to byte buffer using Kryo instance in pool. * * @param obj Object to serialize * @param buffer to write to */ public void serialize(final Object obj, final ByteBuffer buffer) { ByteBufferOutput out = new ByteBufferOutput(buffer); Kryo kryo = borrow(); try { kryo.writeClassAndObject(out, obj); out.flush(); } finally { release(kryo); } }
@Override public Namespace namespace() { return Namespace.builder() .register(PrimitiveType.super.namespace()) .nextId(Namespaces.BEGIN_USER_CUSTOM_ID) .register(Versioned.class) .register(ArrayList.class) .register(Maps.immutableEntry("", "").getClass()) .register(IteratorBatch.class) .build(); }
serializerBuilder.withNamespace(new Namespace(namespaceConfig));