Package com.esotericsoftware.kryo

Examples of com.esotericsoftware.kryo.Serializer


        if (TRACE) trace("kryo", "Read field: " + cachedField + " (" + getType().getName() + ")");

        Object value;

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


  public void write (Kryo kryo, Output output, Collection object) {
    Collection collection = (Collection)object;
    int length = collection.size();
    output.writeInt(length, true);
    if (length == 0) return;
    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.readInt(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

        output.writeInt(((TaggedCachedField)fields[i]).tag, true);

        Object value = cachedField.get(object);

        Serializer serializer = cachedField.serializer;
        if (cachedField.valueClass == null) {
          if (value == null) {
            kryo.writeClass(output, null);
            continue;
          }
          Registration registration = kryo.writeClass(output, value.getClass());
          if (serializer == null) serializer = registration.getSerializer();
          if (cachedField.generics != null) serializer.setGenerics(kryo, cachedField.generics);
          kryo.writeObject(output, value, serializer);
        } else {
          if (serializer == null) cachedField.serializer = serializer = kryo.getSerializer(cachedField.valueClass);
          if (cachedField.generics != null) serializer.setGenerics(kryo, cachedField.generics);
          if (cachedField.canBeNull)
            kryo.writeObjectOrNull(output, value, serializer);
          else {
            if (value == null) {
              throw new KryoException("Field value is null but canBeNull is false: " + cachedField + " ("
View Full Code Here

        if (TRACE) trace("kryo", "Read field: " + cachedField + " (" + getType().getName() + ")");

        Object value;

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

    }
  }

  static public class EnumSetSerializer extends Serializer<EnumSet> {
    public void write (Kryo kryo, Output output, EnumSet object) {
      Serializer serializer;
      if (object.isEmpty()) {
        EnumSet tmp = EnumSet.complementOf(object);
        if (tmp.isEmpty()) throw new KryoException("An EnumSet must have a defined Enum to be serialized.");
        serializer = kryo.writeClass(output, tmp.iterator().next().getClass()).getSerializer();
      } else {
        serializer = kryo.writeClass(output, object.iterator().next().getClass()).getSerializer();
      }
      output.writeInt(object.size(), true);
      for (Object element : object)
        serializer.write(kryo, output, element);
    }
View Full Code Here

    }

    public EnumSet read (Kryo kryo, Input input, Class<EnumSet> type) {
      Registration registration = kryo.readClass(input);
      EnumSet object = EnumSet.noneOf(registration.getType());
      Serializer serializer = registration.getSerializer();
      int length = input.readInt(true);
      for (int i = 0; i < length; i++)
        object.add(serializer.read(kryo, input, null));
      return object;
    }
View Full Code Here

        if (accessIndex != -1)
          value = ((FieldAccess)access).get(object, accessIndex);
        else
          value = field.get(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 + " ("
View Full Code Here

      try {
        if (TRACE) trace("kryo", "Read field: " + this + " (" + type.getName() + ")");
        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

  public void write (Kryo kryo, Output output, Collection object) {
    Collection collection = (Collection)object;
    int length = collection.size();
    output.writeInt(length, true);
    if (length == 0) return;
    Serializer serializer = this.serializer;
    if (genericType != null) {
      if (serializer == null) serializer = kryo.getSerializer(genericType);
      genericType = null;
    }
    if (serializer != null) {
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.