org.gwtproject.rpc.serialization.api.impl.AbstractSerializationStreamWriter Maven / Gradle / Ivy
package org.gwtproject.rpc.serialization.api.impl;
import org.gwtproject.rpc.serialization.api.SerializationException;
import org.gwtproject.rpc.serialization.api.SerializationStreamWriter;
import java.util.*;
/**
* Base class for the client and server serialization streams. This class
* handles the basic serialization and deserialization formatting for primitive
* types since these are common between the client and the server. It also
* handles Object- and String-tracking for building graph references.
*/
public abstract class AbstractSerializationStreamWriter extends
AbstractSerializationStream implements SerializationStreamWriter {
private static final double TWO_PWR_16_DBL = 0x10000;
private static final double TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
/**
* Return a pair of doubles { low, high } that add up to the given number,
* such that "low" is always between 0 and 2^32-1 inclusive and "high" is
* always between -2^63 and 2^63-2^32 inclusive and is a multiple of 2^32.
*/
public static double[] getAsDoubleArray(long value) {
int lowBits = (int) (value & 0xffffffff);
int highBits = (int) (value >> 32);
return makeLongComponents(lowBits, highBits);
}
// Equivalent to getAsDoubleArray((long) highBits << 32 | lowBits);
protected static double[] makeLongComponents(int lowBits, int highBits) {
double high = highBits * TWO_PWR_32_DBL;
double low = lowBits;
if (lowBits < 0) {
low += TWO_PWR_32_DBL;
}
return new double[] {low, high};
}
private int objectCount;
private Map
© 2015 - 2024 Weber Informatics LLC | Privacy Policy