Package com.esotericsoftware.kryo

Examples of com.esotericsoftware.kryo.Serializer


    kryo.register(InvokeMethod.class);

    FieldSerializer serializer = (FieldSerializer)kryo.register(InvokeMethodResult.class).getSerializer();
    serializer.getField("objectID").setClass(int.class, new IntSerializer(true));

    kryo.register(InvocationHandler.class, new Serializer() {
      public void writeObjectData (ByteBuffer buffer, Object object) {
        RemoteInvocationHandler handler = (RemoteInvocationHandler)Proxy.getInvocationHandler(object);
        IntSerializer.put(buffer, handler.objectID, true);
      }
View Full Code Here


          break;
        }
      }

      for (int i = 0, n = cachedMethod.serializers.length; i < n; i++) {
        Serializer serializer = cachedMethod.serializers[i];
        if (serializer != null)
          serializer.writeObject(buffer, args[i]);
        else
          kryo.writeClassAndObject(buffer, args[i]);
      }

      if (method.getReturnType() != void.class) buffer.put(responseID);
View Full Code Here

      }
      method = cachedMethod.method;

      args = new Object[cachedMethod.serializers.length];
      for (int i = 0, n = args.length; i < n; i++) {
        Serializer serializer = cachedMethod.serializers[i];
        if (serializer != null)
          args[i] = serializer.readObject(buffer, method.getParameterTypes()[i]);
        else
          args[i] = kryo.readClassAndObject(buffer);
      }

      if (method.getReturnType() != void.class) responseID = buffer.get();
View Full Code Here

      Method getMethod = property.getReadMethod();
      Method setMethod = property.getWriteMethod();
      if (getMethod == null || setMethod == null) continue; // Require both a getter and setter.

      // Always use the same serializer for this property if the properties' class is final.
      Serializer serializer = null;
      Class returnType = getMethod.getReturnType();
      if (kryo.isFinal(returnType)) serializer = kryo.getRegistration(returnType).getSerializer();

      CachedProperty cachedProperty = new CachedProperty();
      cachedProperty.name = name;
View Full Code Here

    for (int i = 0, n = properties.length; i < n; i++) {
      CachedProperty property = properties[i];
      try {
        if (TRACE) trace("kryo", "Write property: " + property + " (" + type.getName() + ")");
        Object value = property.get(object);
        Serializer serializer = property.serializer;
        if (serializer != null)
          kryo.writeObjectOrNull(output, value, serializer);
        else
          kryo.writeClassAndObject(output, value);
      } catch (IllegalAccessException ex) {
View Full Code Here

    for (int i = 0, n = properties.length; i < n; i++) {
      CachedProperty property = properties[i];
      try {
        if (TRACE) trace("kryo", "Read property: " + property + " (" + object.getClass() + ")");
        Object value;
        Serializer serializer = property.serializer;
        if (serializer != null)
          value = kryo.readObjectOrNull(input, property.setMethodType, serializer);
        else
          value = kryo.readClassAndObject(input);
        property.set(object, value);
View Full Code Here

  }

  public void write (Kryo kryo, Output output, Collection collection) {
    int length = collection.size();
    output.writeVarInt(length, true);
    Serializer serializer = this.serializer;
    if (genericType != null) {
      if (serializer == null) serializer = kryo.getSerializer(genericType);
      genericType = null;
    }
    if (serializer != null) {
View Full Code Here

    Collection collection = create(kryo, input, type);
    kryo.reference(collection);
    int length = input.readVarInt(true);
    if (collection instanceof ArrayList) ((ArrayList)collection).ensureCapacity(length);
    Class elementClass = this.elementClass;
    Serializer serializer = this.serializer;
    if (genericType != null) {
      if (serializer == null) {
        elementClass = genericType;
        serializer = kryo.getSerializer(genericType);
      }
View Full Code Here

      if (TRACE)
        trace("kryo", "Write field: " + this + " (" + object.getClass().getName() + ")" + " pos=" + output.position());

      Object value = getField(object);

      Serializer serializer = this.serializer;
      if (valueClass == null) {
        // The concrete type of the field is unknown, write the class first.
        if (value == null) {
          kryo.writeClass(output, null);
          return;
        }
        Registration registration = kryo.writeClass(output, value.getClass());
        if (serializer == null) serializer = registration.getSerializer();
        // if (generics != null)
        serializer.setGenerics(kryo, generics);
        kryo.writeObject(output, value, serializer);
      } else {
        // The concrete type of the field is known, always use the same serializer.
        if (serializer == null) this.serializer = serializer = kryo.getSerializer(valueClass);
        // if (generics != null)
        serializer.setGenerics(kryo, generics);
        if (canBeNull) {
          kryo.writeObjectOrNull(output, value, serializer);
        } else {
          if (value == null) {
            throw new KryoException("Field value is null but canBeNull is false: " + this + " (" + object.getClass().getName() + ")");
View Full Code Here

    try {
      if (TRACE) trace("kryo", "Read field: " + this + " (" + type.getName() + ")" + " pos=" + input.position());
      Object value;

      Class concreteType = valueClass;
      Serializer serializer = this.serializer;
      if (concreteType == null) {
        Registration registration = kryo.readClass(input);
        if (registration == null)
          value = null;
        else {
          if (serializer == null) serializer = registration.getSerializer();
          // if (generics != null)
          serializer.setGenerics(kryo, generics);
          value = kryo.readObject(input, registration.getType(), serializer);
        }
      } else {
        if (serializer == null) this.serializer = serializer = kryo.getSerializer(valueClass);
        // if (generics != null)
        serializer.setGenerics(kryo, generics);
        if (canBeNull)
          value = kryo.readObjectOrNull(input, concreteType, serializer);
        else
          value = kryo.readObject(input, concreteType, serializer);
      }
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryo.Serializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.