/*
Round trip the objects in a FastBlobStateEngine, so they appear in the type deserialization state.
489371
private FastBlobStateEngine getDeserializedStateEngineWithObjects(A... objects) throws IOException {
        FastBlobStateEngine stateEngine = new FastBlobStateEngine(new ExampleSerializerFactory());

        for(A object : objects) {
            stateEngine.add("A", object);
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dataOutputStream = new DataOutputStream(baos);

        stateEngine.prepareForWrite();

        FastBlobWriter writer = new FastBlobWriter(stateEngine);
        writer.writeSnapshot(dataOutputStream);

        FastBlobReader reader = new FastBlobReader(stateEngine);
        reader.readSnapshot(new ByteArrayInputStream(baos.toByteArray()));

        return stateEngine;
    }
624251
@Override
	public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
		model = new PrefsModel();

		parseBindType(roundEnv);

		// Put all @BindSharedPreferences elements in beanElements
		for (Element item : roundEnv.getElementsAnnotatedWith(BindSharedPreferences.class)) {
			AssertKripton.assertTrueOrInvalidKindForAnnotationException(item.getKind() == ElementKind.CLASS, item, BindSharedPreferences.class);

			analyzeSharedPreferences((TypeElement) item);
		}

		return true;
	}
1226359
@Override
	protected void serializeTo(RawDataBuffer out)
    {
        super.serializeTo(out);
        out.writeInt(consumerId.asInt());
        DestinationSerializer.serializeTo(destination, out);
        out.writeNullableUTF(messageSelector);
        out.writeBoolean(noLocal);
    }
1343054
@SuppressWarnings ("unchecked")
  public void deserializeState (@Nonnull final Serializable aState)
  {
    if (!(aState instanceof Map))
      throw new IllegalArgumentException ("Serialized state needs to be of type [java.util.Map]");
    m_aAttributes.putAll ((Map <String, Object>) aState);
  }
323007
function __deserializeBoolean(type, start, options) {
	let end = start;
	let data = type === DATA_TYPE.TRUE;
	return { anchor: end, value: data };
}
1357457
private void writeObject(ObjectOutputStream stream) throws IOException {
    stream.writeInt(_capacity);
    stream.writeInt(_size);
    int count = 0;
    EntryImpl<K, V> entry = _mapFirst;
    while (entry != null) {
      stream.writeObject(entry._key);
      stream.writeObject(entry._value);
      count++;
      entry = entry._after;
    }
    if (count != _size) { throw new IOException("FastMap Corrupted"); }
  }
955209
private void tidySerialization(Class<?> reloadedClass) {
		//		if (true) return;
		try {
			Class<?> clazz = Class.forName("java.io.ObjectStreamClass$Caches");
			Field localDescsField = clazz.getDeclaredField("localDescs");
			localDescsField.setAccessible(true);
			ConcurrentMap cm = (ConcurrentMap) localDescsField.get(null);
			// TODO [serialization] a bit extreme to wipe out everything
			cm.clear();
			// For some reason clearing the reflectors damages serialization - is it not a true cache?
			//			Field reflectorsField = clazz.getDeclaredField("reflectors");
			//			reflectorsField.setAccessible(true);
			//			cm = (ConcurrentMap)reflectorsField.get(null);
			//			cm.clear();
		}
		catch (ClassNotFoundException e) {
			throw new IllegalStateException(e);
		}
		catch (NoSuchFieldException e) {
			throw new IllegalStateException(e);
		}
		catch (SecurityException e) {
			throw new IllegalStateException(e);
		}
		catch (IllegalArgumentException e) {
			throw new IllegalStateException(e);
		}
		catch (IllegalAccessException e) {
			throw new IllegalStateException(e);
		}


		//		private static class Caches {
		//	        /** cache mapping local classes -> descriptors */
		//	        static final ConcurrentMap<WeakClassKey,Reference<?>> localDescs =
		//	            new ConcurrentHashMap<>();
		//
		//	        /** cache mapping field group/local desc pairs -> field reflectors */
		//	        static final ConcurrentMap<FieldReflectorKey,Reference<?>> reflectors =
		//	            new ConcurrentHashMap<>();
		//
		//	        /** queue for WeakReferences to local classes */
		//	        private static final ReferenceQueue<Class<?>> localDescsQueue =
		//	            new ReferenceQueue<>();
		//	        /** queue for WeakReferences to field reflectors keys */
		//	        private static final ReferenceQueue<Class<?>> reflectorsQueue =
		//	            new ReferenceQueue<>();
		//	    }
	}
68565
@Deprecated
    @Override
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public void serializeObject(JsonWriteGenericRecord record, String fieldName, String typeName, Object obj) {
        try {
            if (obj == null) {
                record.getGenerator().writeObjectField(fieldName, null);
                return;
            }
            if (isPrimitive(obj.getClass())) {
                serializePrimitive(record, fieldName, obj);
                return;
            }
            record.getGenerator().writeFieldName(fieldName);
            record.getGenerator().writeStartObject();

            NFTypeSerializer fieldSerializer = getSerializer(typeName);
            JsonWriteGenericRecord fieldRecord = new JsonWriteGenericRecord(record.getGenerator());
            fieldSerializer.serialize(obj, fieldRecord);
            record.getGenerator().writeEndObject();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
144233
private void forwardToLocalNodes(Mutation mutation, MessagingService.Verb verb, byte[] forwardBytes, InetAddress from) throws IOException
    {
        DataInputStream in = new DataInputStream(new FastByteArrayInputStream(forwardBytes));
        int size = in.readInt();

        // tell the recipients who to send their ack to
        MessageOut<Mutation> message = new MessageOut<>(verb, mutation, Mutation.serializer).withParameter(Mutation.FORWARD_FROM, from.getAddress());
        // Send a message to each of the addresses on our Forward List
        for (int i = 0; i < size; i++)
        {
            InetAddress address = CompactEndpointSerializationHelper.deserialize(in);
            int id = in.readInt();
            Tracing.trace("Enqueuing forwarded write to {}", address);
            MessagingService.instance().sendOneWay(message, id, address);
        }
    }
1138284
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
		// Call the default implementation to de-serialize our object
		in.defaultReadObject();
		// init transients
		_validateLastModified = new AtomicBoolean(true);
		_cacheKeyGenMutex = new Semaphore(1);
		_isReportCacheInfo = false;
	}
983382
public void partialDeserialize(TBase<?,?> base, DBObject dbObject, TFieldIdEnum... fieldIds) throws TException {
    try {
      protocol_.setDBOject(dbObject);
      protocol_.setBaseObject( base );
      protocol_.setFieldIdsFilter(base, fieldIds);

      base.read(protocol_);
    } finally {
      protocol_.reset();
    }
  }
468436
@Override
    public BoundingBox deserialize(final JsonElement json, final Type typeOfT,
            final JsonDeserializationContext context) {

        final BoundingBox bbox;

        if (json.isJsonArray()) {
            final JsonArray bboxJsonArray = json.getAsJsonArray();
            bbox = new BoundingBox();
            bbox.setSouth(bboxJsonArray.get(0).getAsDouble());
            bbox.setNorth(bboxJsonArray.get(1).getAsDouble());
            bbox.setWest(bboxJsonArray.get(2).getAsDouble());
            bbox.setEast(bboxJsonArray.get(3).getAsDouble());
        } else {
            throw new JsonParseException("Unexpected data: " + json.toString());
        }

        return bbox;
    }
970823
public static <T extends PersistableTransfer> T deserializeFrom(
            String serialized) {
        if (serialized == null)
            return null;
        ByteArrayInputStream byteStream = new ByteArrayInputStream(
                serialized.getBytes(UTF8));
        try{
            return deserializeFrom(byteStream);
        }finally{
            try { byteStream.close(); } catch(IOException ioe) { } ;
        }
    }
1127022
static StructrTypeDefinition deserialize(final StructrSchemaDefinition root, final String name, final Map<String, Object> source) {

		final Map<String, StructrPropertyDefinition> deserializedProperties = new TreeMap<>();
		final Map<String, StructrMethodDefinition> deserializedMethods      = new TreeMap<>();
		final StructrTypeDefinition typeDefinition                          = StructrTypeDefinition.determineType(root, name, source);
		final Map<String, Object> properties                                = (Map)source.get(JsonSchema.KEY_PROPERTIES);
		final List<String> requiredPropertyNames                            = (List)source.get(JsonSchema.KEY_REQUIRED);
		final Map<String, Object> views                                     = (Map)source.get(JsonSchema.KEY_VIEWS);
		final Map<String, String> viewOrder                                 = (Map)source.get(JsonSchema.KEY_VIEW_ORDER);
		final Map<String, Object> methods                                   = (Map)source.get(JsonSchema.KEY_METHODS);

		if (properties != null) {

			for (final Entry<String, Object> entry : properties.entrySet()) {

				final String propertyName = entry.getKey();
				final Object value        = entry.getValue();

				if (value instanceof Map) {

					final StructrPropertyDefinition property = StructrPropertyDefinition.deserialize(typeDefinition, propertyName, (Map)value);
					if (property != null) {

						deserializedProperties.put(property.getName(), property);
						typeDefinition.getProperties().add(property);
					}

				} else {

					throw new IllegalStateException("Invalid JSON property definition for property " + propertyName + ", expected object.");
				}
			}
		}

		if (requiredPropertyNames != null) {

			for (final String requiredPropertyName : requiredPropertyNames) {

				// set required properties
				final StructrPropertyDefinition property = deserializedProperties.get(requiredPropertyName);
				if (property != null) {

					property.setRequired(true);

				} else {

					throw new IllegalStateException("Required property " + requiredPropertyName + " not defined for type " + typeDefinition.getName() + ".");
				}
			}
		}

		if (views != null) {

			for (final Entry<String, Object> entry : views.entrySet()) {

				final String viewName = entry.getKey();
				final Object value    = entry.getValue();

				if (value instanceof List) {

					final Set<String> viewProperties = new TreeSet<>((List)value);
					typeDefinition.getViews().put(viewName, viewProperties);

				} else {

					throw new IllegalStateException("View definition " + viewName + " must be of type array.");
				}
			}
		}

		if (viewOrder != null) {

			typeDefinition.getViewOrder().putAll(viewOrder);
		}

		if (methods != null) {

			for (final Entry<String, Object> entry : methods.entrySet()) {

				final String methodName = entry.getKey();
				final Object value      = entry.getValue();

				if (value instanceof Map) {

					final StructrMethodDefinition method = StructrMethodDefinition.deserialize(typeDefinition, methodName, (Map)value);
					if (method != null) {

						deserializedMethods.put(method.getName(), method);
						typeDefinition.getMethods().add(method);
					}

				} else if (value instanceof Collection) {

					// more than on method with the same name exists..
					final Collection<Map<String, Object>> methodList = (Collection)value;

					for (final Map<String, Object> map : methodList) {

						final StructrMethodDefinition method = StructrMethodDefinition.deserialize(typeDefinition, methodName, map);
						if (method != null) {

							deserializedMethods.put(method.getName(), method);
							typeDefinition.getMethods().add(method);
						}
					}

				} else {

					throw new IllegalStateException("Method definition " + methodName + " must be of type string or map.");
				}
			}
		}

		final Object isAbstractValue = source.get(JsonSchema.KEY_IS_ABSTRACT);
		if (isAbstractValue != null && Boolean.TRUE.equals(isAbstractValue)) {

			typeDefinition.setIsAbstract();
		}

		final Object isInterfaceValue = source.get(JsonSchema.KEY_IS_INTERFACE);
		if (isInterfaceValue != null && Boolean.TRUE.equals(isInterfaceValue)) {

			typeDefinition.setIsInterface();
		}

		final Object isBuiltinType = source.get(JsonSchema.KEY_IS_BUILTIN_TYPE);
		if (isBuiltinType != null && Boolean.TRUE.equals(isBuiltinType)) {

			typeDefinition.setIsBuiltinType();
		}

		final Object categoryValue = source.get(JsonSchema.KEY_CATEGORY);
		if (categoryValue != null) {

			typeDefinition.setCategory(categoryValue.toString());
		}

		return typeDefinition;
	}
689846
@Override
	protected void unserializeFrom(RawDataBuffer in)
    {
        super.unserializeFrom(in);
        browserId = new IntegerID(in.readInt());
        queue = (Queue)DestinationSerializer.unserializeFrom(in);
        messageSelector = in.readNullableUTF();
    }
1058402
private Object deserialize(TypeInfo type, Object rawValue)
            throws SerDeException {
        Object value = null;

        if (rawValue != null) {
            switch (type.getCategory()) {
                case PRIMITIVE:
                    value = deserializePrimitive((PrimitiveTypeInfo) type, rawValue);
                    break;
                case STRUCT:
                    value = deserializeStruct((StructTypeInfo) type, rawValue);
                    break;
                case MAP:
                    value = deserializeMap((MapTypeInfo) type, rawValue);
                    break;
                case LIST:
                    value = deserializeList((ListTypeInfo) type, rawValue);
                    break;
                case UNION:
                    value = deserializeUnion((UnionTypeInfo) type, rawValue);
                    break;
            }
        }

        return value;
    }
436659
@Bench(dataProvider = "generateData")
    void benchFastIntPush(final List<Integer> intData) {
        fastInt = new FastIntStack();
        for (final Object i : intData) {
            fastInt.push((Integer) i);
        }
    }