Package com.esotericsoftware.kryo

Examples of com.esotericsoftware.kryo.Serializer


    }

    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


        return;
      }
      output.writeVarInt(object.length + 1, true);
      Class elementClass = object.getClass().getComponentType();
      if (elementsAreSameType || Modifier.isFinal(elementClass.getModifiers())) {
        Serializer elementSerializer = kryo.getSerializer(elementClass);
//        if(generics!=null)
          elementSerializer.setGenerics(kryo, generics);
        for (int i = 0, n = object.length; i < n; i++) {
          if (elementsCanBeNull)
            kryo.writeObjectOrNull(output, object[i], elementSerializer);
          else
            kryo.writeObject(output, object[i], elementSerializer);
        }
      } else {
//        Generics genericsScope = null;
//        Class componentType = type;
//        while(componentType.getComponentType() != null) {
//          componentType = componentType.getComponentType();
//        }
//        TypeVariable[] typeVars = type.getComponentType().getTypeParameters();
//        if(typeVars != null && generics != null) {
//          if(TRACE) trace("kryo", "Creating a new GenericsScope for " + type.getName() + " with type vars: " + Arrays.toString(typeVars));
//          genericsScope = new Generics();
//          int i = 0;
//          for(TypeVariable typeVar: typeVars) {
//            genericsScope.add(typeVar.getName(), generics[i]);
//            i++;
//          }
//          kryo.pushGenericsScope(type, genericsScope);
//        }
//       
        for (int i = 0, n = object.length; i < n; i++) {
          // Propagate generics?
          if (object[i] != null) {
            Serializer serializer = kryo.getSerializer(object[i].getClass());
            serializer.setGenerics(kryo, generics);
          }
          kryo.writeClassAndObject(output, object[i]);
        }
       
//        if(genericsScope != null)
View Full Code Here

      if (length == NULL) return null;
      Object[] object = (Object[])Array.newInstance(type.getComponentType(), length - 1);
      kryo.reference(object);
      Class elementClass = object.getClass().getComponentType();
      if (elementsAreSameType || Modifier.isFinal(elementClass.getModifiers())) {
        Serializer elementSerializer = kryo.getSerializer(elementClass);
//        if(generics!=null)
          elementSerializer.setGenerics(kryo, generics);
        for (int i = 0, n = object.length; i < n; i++) {
          if (elementsCanBeNull)
            object[i] = kryo.readObjectOrNull(input, elementClass, elementSerializer);
          else
            object[i] = kryo.readObject(input, elementClass, elementSerializer);
View Full Code Here

  public void write (Kryo kryo, Output output, Map map) {
    int length = map.size();
    output.writeInt(length, true);
    if (length == 0) return;

    Serializer keySerializer = this.keySerializer;
    if (keyGenericType != null) {
      if (keySerializer == null) keySerializer = kryo.getSerializer(keyGenericType);
      keyGenericType = null;
    }
    Serializer valueSerializer = this.valueSerializer;
    if (valueGenericType != null) {
      if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueGenericType);
      valueGenericType = null;
    }
View Full Code Here

  public Map read (Kryo kryo, Input input, Class<Map> type) {
    Map map = create(kryo, input, type);
    int length = input.readInt(true);
    if (length == 0) return map;

    Serializer keySerializer = this.keySerializer;
    if (keyGenericType != null) {
      if (keySerializer == null) keySerializer = kryo.getSerializer(keyGenericType);
      keyGenericType = null;
    }
    Serializer valueSerializer = this.valueSerializer;
    if (valueGenericType != null) {
      if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueGenericType);
      valueGenericType = null;
    }
    kryo.reference(map);
View Full Code Here

      try {
        if (TRACE) trace("kryo", "Write field: " + cachedField + " (" + object.getClass().getName() + ")");

        Object value = cachedField.get(object);

        Serializer serializer = cachedField.serializer;
        if (cachedField.valueClass == null) {
          // The concrete type of the field is unknown, write the class first.
          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 {
          // The concrete type of the field is known, always use the same serializer.
          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 + " (" + type.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(cachedField.valueClass);
          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

        return;
      }
      output.writeInt(object.length + 1, true);
      Class elementClass = object.getClass().getComponentType();
      if (elementsAreSameType || Modifier.isFinal(elementClass.getModifiers())) {
        Serializer elementSerializer = kryo.getSerializer(elementClass);
        for (int i = 0, n = object.length; i < n; i++) {
          if (elementsCanBeNull)
            kryo.writeObjectOrNull(output, object[i], elementSerializer);
          else
            kryo.writeObject(output, object[i], elementSerializer);
View Full Code Here

      if (length == NULL) return null;
      Object[] object = (Object[])Array.newInstance(type.getComponentType(), length - 1);
      kryo.reference(object);
      Class elementClass = object.getClass().getComponentType();
      if (elementsAreSameType || Modifier.isFinal(elementClass.getModifiers())) {
        Serializer elementSerializer = kryo.getSerializer(elementClass);
        for (int i = 0, n = object.length; i < n; i++) {
          if (elementsCanBeNull)
            object[i] = kryo.readObjectOrNull(input, elementClass, elementSerializer);
          else
            object[i] = kryo.readObject(input, elementClass, elementSerializer);
View Full Code Here

          kryo.writeClass(outputChunked, null);
          outputChunked.endChunks();
          continue;
        }

        Serializer serializer = cachedField.serializer;
        if (cachedField.valueClass == null) {
          Registration registration = kryo.writeClass(outputChunked, value.getClass());
          if (serializer == null) serializer = registration.getSerializer();
          if (cachedField.generics != null) serializer.setGenerics(kryo, cachedField.generics);
          kryo.writeObject(outputChunked, 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(outputChunked, value, serializer);
          else {
            if (value == null) {
              throw new KryoException("Field value is null but canBeNull is false: " + cachedField + " ("
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.