@Override public MapMetaData<Integer> read(Kryo kryo, Input input, Class<MapMetaData<Integer>> type) { try { thatMapMetaData = mapMetaData.recv(input); int thatMapSegNum = thatMapMetaData.getSegNum(); List<Map<String, Integer>> mapDataList = new ArrayList<>(thatMapSegNum); thatMapMetaData.setMapDataList(mapDataList); for (int i = 0; i < thatMapSegNum; i++) { int dataNum = thatMapMetaData.getDataNum(i); Map<String, Integer> mapData = new HashMap<>(dataNum); mapDataList.add(mapData); for (int j = 0; j < dataNum; j++) { String key = input.readString(); Integer val = input.readInt(); mapData.put(key, val); } } } catch (IOException e) { LOG.error("double array read exception", e); System.exit(1); } return thatMapMetaData; }
public ArrayMetaData<long[]> read(Kryo kryo, Input input, Class<ArrayMetaData<long[]>> type) { try { long[] arrData = arrayMetaData.getArrData(); thatArrMetaData = arrayMetaData.recv(input); int arrSegNum = thatArrMetaData.getSegNum(); for (int i = 0; i < arrSegNum; i++) { int from = thatArrMetaData.getFrom(i); int to = thatArrMetaData.getTo(i); for (int j = from; j < to; j++) { arrData[j] = operator.apply(arrData[j], input.readLong()); } } thatArrMetaData.setArrData(arrData); } catch (IOException e) { LOG.error("double array read exception", e); System.exit(1); } return thatArrMetaData; }
public ArrayMetaData<short[]> read(Kryo kryo, Input input, Class<ArrayMetaData<short[]>> type) { try { short[] arrData = arrayMetaData.getArrData(); thatArrMetaData = arrayMetaData.recv(input); int arrSegNum = thatArrMetaData.getSegNum(); for (int i = 0; i < arrSegNum; i++) { int from = thatArrMetaData.getFrom(i); int to = thatArrMetaData.getTo(i); for (int j = from; j < to; j++) { arrData[j] = operator.apply(arrData[j], input.readShort()); } } thatArrMetaData.setArrData(arrData); } catch (IOException e) { LOG.error("double array read exception", e); System.exit(1); } return thatArrMetaData; }
@Override protected GoogleAccountsService createService(final Kryo kryo, final Input input, final String id, final String originalUrl, final String artifactId) { final String requestId = kryo.readObject(input, String.class); final String relayState = kryo.readObject(input, String.class); try { return (GoogleAccountsService) CONSTRUCTOR.newInstance( id, originalUrl, artifactId, relayState, requestId, privateKey, publicKey, alternateUsername); } catch (final Exception e) { throw new IllegalStateException("Error creating SamlService", e); } }
@Override public MapMetaData<Short> read(Kryo kryo, Input input, Class<MapMetaData<Short>> type) { try { thatMapMetaData = mapMetaData.recv(input); int thatMapSegNum = thatMapMetaData.getSegNum(); List<Map<String, Short>> mapDataList = new ArrayList<>(thatMapSegNum); thatMapMetaData.setMapDataList(mapDataList); for (int i = 0; i < thatMapSegNum; i++) { int dataNum = thatMapMetaData.getDataNum(i); Map<String, Short> mapData = new HashMap<>(dataNum); mapDataList.add(mapData); for (int j = 0; j < dataNum; j++) { String key = input.readString(); Short val = input.readShort(); mapData.put(key, val); } } } catch (IOException e) { LOG.error("double array read exception", e); System.exit(1); } return thatMapMetaData; }
@Override public Instructions.ExtensionInstructionWrapper read(Kryo kryo, Input input, Class<Instructions.ExtensionInstructionWrapper> type) { ExtensionTreatmentType exType = (ExtensionTreatmentType) kryo.readClassAndObject(input); DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input); DriverService driverService = DefaultServiceDirectory.getService(DriverService.class); DriverHandler handler = new DefaultDriverHandler( new DefaultDriverData(driverService.getDriver(deviceId), deviceId)); ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class); ExtensionTreatment instruction = resolver.getExtensionInstruction(exType); byte[] bytes = (byte[]) kryo.readClassAndObject(input); instruction.deserialize(bytes); return Instructions.extension(instruction, deviceId); }
@Override protected GoogleAccountsService createService(final Kryo kryo, final Input input, final String id, final String originalUrl, final String artifactId) { final String requestId = kryo.readObject(input, String.class); final String relayState = kryo.readObject(input, String.class); try { return (GoogleAccountsService) CONSTRUCTOR.newInstance( id, originalUrl, artifactId, relayState, requestId, this.privateKey, this.publicKey, this.alternateUsername); } catch (final Exception e) { throw new IllegalStateException("Error creating SamlService", e); } }
@Override public Bmv2DeviceContext read(Kryo kryo, Input input, Class<Bmv2DeviceContext> type) { String jsonStr = kryo.readObject(input, String.class); String interpreterClassName = kryo.readObject(input, String.class); Bmv2Configuration configuration = parse(Json.parse(jsonStr).asObject()); ClassLoader loader = interpreterClassLoaders.get(interpreterClassName); if (loader == null) { throw new IllegalStateException("No class loader registered for interpreter: " + interpreterClassName); } try { Bmv2Interpreter interpreter = (Bmv2Interpreter) loader.loadClass(interpreterClassName).newInstance(); return new Bmv2DeviceContext(configuration, interpreter); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new RuntimeException("Unable to load interpreter class", e); } }
@Override public ExtensionCriterion read(Kryo kryo, Input input, Class<ExtensionCriterion> type) { ExtensionSelectorType exType = (ExtensionSelectorType) kryo.readClassAndObject(input); DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input); DriverService driverService = DefaultServiceDirectory.getService(DriverService.class); DriverHandler handler = new DefaultDriverHandler( new DefaultDriverData(driverService.getDriver(deviceId), deviceId)); ExtensionSelectorResolver resolver = handler.behaviour(ExtensionSelectorResolver.class); ExtensionSelector selector = resolver.getExtensionSelector(exType); byte[] bytes = (byte[]) kryo.readClassAndObject(input); selector.deserialize(bytes); return Criteria.extension(selector, deviceId); }
@Override public Object decode(ByteBuf buf, State state) throws IOException { Kryo kryo = null; try { kryo = kryoPool.get(); return kryo.readClassAndObject(new Input(new ByteBufInputStream(buf))); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RedissonKryoCodecException(e); } finally { if (kryo != null) { kryoPool.yield(kryo); } } }
@Override public T read(Kryo kryo, Input input, Class<T> type) { int length = input.readVarInt(true); boolean ordered = input.readBoolean(); Class cls = kryo.readClass(input).getType(); T array = create(ordered, length, cls); kryo.reference(array); Class elementClass = null; Serializer serializer = null; if (genericType != null) { elementClass = genericType; serializer = kryo.getSerializer(genericType); genericType = null; } if (serializer != null) { for (int i = 0; i < length; i++) array.add(kryo.readObjectOrNull(input, elementClass, serializer)); } else { for (int i = 0; i < length; i++) array.add(kryo.readClassAndObject(input)); } return array; }
public ArrayMetaData<byte[]> read(Kryo kryo, Input input, Class<ArrayMetaData<byte[]>> type) { try { byte[] arrData = arrayMetaData.getArrData(); thatArrMetaData = arrayMetaData.recv(input); int arrSegNum = thatArrMetaData.getSegNum(); for (int i = 0; i < arrSegNum; i++) { int from = thatArrMetaData.getFrom(i); int to = thatArrMetaData.getTo(i); for (int j = from; j < to; j++) { arrData[j] = input.readByte(); } } thatArrMetaData.setArrData(arrData); } catch (IOException e) { LOG.error("double array read exception", e); System.exit(1); } return thatArrMetaData; }
public ArrayMetaData<String[]> read(Kryo kryo, Input input, Class<ArrayMetaData<String[]>> type) { try { String[] arrData = arrayMetaData.getArrData(); thatArrMetaData = arrayMetaData.recv(input); int arrSegNum = thatArrMetaData.getSegNum(); for (int i = 0; i < arrSegNum; i++) { int from = thatArrMetaData.getFrom(i); int to = thatArrMetaData.getTo(i); for (int j = from; j < to; j++) { arrData[j] = input.readString(); } } thatArrMetaData.setArrData(arrData); } catch (IOException e) { LOG.error("double array read exception", e); System.exit(1); } return thatArrMetaData; }
@Override public final void read (Kryo kryo, Input input) { pushHeader(kryo, this); input.readInt(true); //if this class ever evolves, version can be used for backward compatibility Class dataType = kryo.readClass(input).getType(); gdxMajorVersion = input.readInt(true); gdxMinorVersion = input.readInt(true); gdxRevisionVersion = input.readInt(true); writtenVersion = input.readInt(true); minimumReadVersion = input.readInt(true); minimumReadVersionString = input.readString(); useCompactColor = input.readBoolean(); includePixmapDrawingParams = input.readBoolean(); readExtra(kryo, input); if (dataType != null && minimumReadVersion <= currentReadWriteVersion){ data = (T)kryo.readObject(input, dataType); } popHeader(kryo); }
public ArrayMetaData<String[]> read(Kryo kryo, Input input, Class<ArrayMetaData<String[]>> type) { try { String[] arrData = arrayMetaData.getArrData(); thatArrMetaData = arrayMetaData.recv(input); int arrSegNum = thatArrMetaData.getSegNum(); for (int i = 0; i < arrSegNum; i++) { int from = thatArrMetaData.getFrom(i); int to = thatArrMetaData.getTo(i); for (int j = from; j < to; j++) { arrData[j] = operator.apply(arrData[j], input.readString()); } } thatArrMetaData.setArrData(arrData); } catch (IOException e) { LOG.error("double array read exception", e); System.exit(1); } return thatArrMetaData; }
@Override public IpPrefix read(Kryo kryo, Input input, Class<IpPrefix> type) { int octLen = input.readInt(); checkArgument(octLen <= IpAddress.INET6_BYTE_LENGTH); byte[] octs = new byte[octLen]; input.readBytes(octs); int prefLen = input.readInt(); // Use the address size to decide whether it is IPv4 or IPv6 address if (octLen == IpAddress.INET_BYTE_LENGTH) { return IpPrefix.valueOf(IpAddress.Version.INET, octs, prefLen); } if (octLen == IpAddress.INET6_BYTE_LENGTH) { return IpPrefix.valueOf(IpAddress.Version.INET6, octs, prefLen); } return null; // Shouldn't be reached }
public ArrayMetaData<long[]> read(Kryo kryo, Input input, Class<ArrayMetaData<long[]>> type) { try { long[] arrData = arrayMetaData.getArrData(); thatArrMetaData = arrayMetaData.recv(input); int arrSegNum = thatArrMetaData.getSegNum(); for (int i = 0; i < arrSegNum; i++) { int from = thatArrMetaData.getFrom(i); int to = thatArrMetaData.getTo(i); for (int j = from; j < to; j++) { arrData[j] = input.readLong(); } } thatArrMetaData.setArrData(arrData); } catch (IOException e) { LOG.error("double array read exception", e); System.exit(1); } return thatArrMetaData; }
public T[] readFromBytes(Object origin, Input input, int slaveNum) { T[] originArr = (T[])origin; Kryo kryo = KryoUtils.getKryo(); for (int i = 0; i < slaveNum; i++) { if (i == 0) { for (int j = 0; j < originArr.length; j++) { originArr[j] = (T)serializer.read(kryo, input, type); } } else { for (int j = 0; j < originArr.length; j++) { T readed = (T)serializer.read(kryo, input, type); originArr[j] = operator.apply(originArr[j], readed); } } } return originArr; }
public ArrayMetaData<short[]> read(Kryo kryo, Input input, Class<ArrayMetaData<short[]>> type) { try { short[] arrData = arrayMetaData.getArrData(); thatArrMetaData = arrayMetaData.recv(input); int arrSegNum = thatArrMetaData.getSegNum(); for (int i = 0; i < arrSegNum; i++) { int from = thatArrMetaData.getFrom(i); int to = thatArrMetaData.getTo(i); for (int j = from; j < to; j++) { arrData[j] = input.readShort(); } } thatArrMetaData.setArrData(arrData); } catch (IOException e) { LOG.error("double array read exception", e); System.exit(1); } return thatArrMetaData; }
public ArrayMetaData<byte[]> read(Kryo kryo, Input input, Class<ArrayMetaData<byte[]>> type) { try { byte[] arrData = arrayMetaData.getArrData(); thatArrMetaData = arrayMetaData.recv(input); int arrSegNum = thatArrMetaData.getSegNum(); for (int i = 0; i < arrSegNum; i++) { int from = thatArrMetaData.getFrom(i); int to = thatArrMetaData.getTo(i); for (int j = from; j < to; j++) { arrData[j] = operator.apply(arrData[j], input.readByte()); } } thatArrMetaData.setArrData(arrData); } catch (IOException e) { LOG.error("double array read exception", e); System.exit(1); } return thatArrMetaData; }
@Override public MapMetaData<Long> read(Kryo kryo, Input input, Class<MapMetaData<Long>> type) { try { thatMapMetaData = mapMetaData.recv(input); int thatMapSegNum = thatMapMetaData.getSegNum(); List<Map<String, Long>> mapDataList = new ArrayList<>(thatMapSegNum); thatMapMetaData.setMapDataList(mapDataList); for (int i = 0; i < thatMapSegNum; i++) { int dataNum = thatMapMetaData.getDataNum(i); Map<String, Long> mapData = new HashMap<>(dataNum); mapDataList.add(mapData); for (int j = 0; j < dataNum; j++) { String key = input.readString(); Long val = input.readLong(); mapData.put(key, val); } } } catch (IOException e) { LOG.error("double array read exception", e); System.exit(1); } return thatMapMetaData; }
public ArrayMetaData<double[]> read(Kryo kryo, Input input, Class<ArrayMetaData<double[]>> type) { try { double[] arrData = arrayMetaData.getArrData(); thatArrMetaData = arrayMetaData.recv(input); int arrSegNum = thatArrMetaData.getSegNum(); for (int i = 0; i < arrSegNum; i++) { int from = thatArrMetaData.getFrom(i); int to = thatArrMetaData.getTo(i); for (int j = from; j < to; j++) { arrData[j] = input.readDouble(); } } thatArrMetaData.setArrData(arrData); } catch (IOException e) { LOG.error("double array read exception", e); System.exit(1); } return thatArrMetaData; }
@Override public Queue read(Kryo kryo, Input input, Class<Queue> type) { int length = input.readVarInt(true); Registration registration = kryo.readClass(input); Class cls = registration == null ? Object.class : registration.getType(); Queue queue = new Queue(length, cls); kryo.reference(queue); Class elementClass = null; Serializer serializer = null; if (genericType != null) { elementClass = genericType; serializer = kryo.getSerializer(genericType); genericType = null; } if (serializer != null) { for (int i = 0; i < length; i++) queue.addLast(kryo.readObjectOrNull(input, elementClass, serializer)); } else { for (int i = 0; i < length; i++) queue.addLast(kryo.readClassAndObject(input)); } return queue; }
@Override public DefaultLink read(Kryo kryo, Input input, Class<DefaultLink> type) { ProviderId providerId = (ProviderId) kryo.readClassAndObject(input); ConnectPoint src = (ConnectPoint) kryo.readClassAndObject(input); ConnectPoint dst = (ConnectPoint) kryo.readClassAndObject(input); Type linkType = (Type) kryo.readClassAndObject(input); State state = (State) kryo.readClassAndObject(input); boolean isDurable = input.readBoolean(); return DefaultLink.builder() .providerId(providerId) .src(src) .dst(dst) .type(linkType) .state(state) .isExpected(isDurable) .build(); }
public ArrayMetaData<float[]> read(Kryo kryo, Input input, Class<ArrayMetaData<float[]>> type) { try { float[] arrData = arrayMetaData.getArrData(); thatArrMetaData = arrayMetaData.recv(input); int arrSegNum = thatArrMetaData.getSegNum(); for (int i = 0; i < arrSegNum; i++) { int from = thatArrMetaData.getFrom(i); int to = thatArrMetaData.getTo(i); for (int j = from; j < to; j++) { arrData[j] = input.readFloat(); } } thatArrMetaData.setArrData(arrData); } catch (IOException e) { LOG.error("double array read exception", e); System.exit(1); } return thatArrMetaData; }
@Override public SensorMeasurement read(Kryo kryo, Input input, Class<SensorMeasurement> clazz) { int magicNumber = input.readInt(); assert (magicNumber == MAGIC_NUMBER); boolean is2D = (input.readByte() == 0x01) ? true : false; int coilId = input.readInt(); double x = input.readDouble(); double y = (is2D) ? input.readDouble() : 0; int varId = input.readInt(); double value = input.readDouble(); if (is2D) { return new SensorMeasurement2D(coilId, x, y, varId, value); } else { return new SensorMeasurement1D(coilId, x, varId, value); } }
@Override public Object apply(byte[] buffer) { try { checkHeader(buffer, KryoValueEncoder.IDENTITY_NUMBER); ByteArrayInputStream in = new ByteArrayInputStream(buffer, 4, buffer.length - 4); Input input = new Input(in); Kryo kryo = KryoValueEncoder.kryoThreadLocal.get(); return kryo.readClassAndObject(input); } catch (Exception e) { throw new CacheEncodeException("Kryo decode error: " + e.getMessage(), e); } }
public MapMetaData<Float> read(Kryo kryo, Input input, Class<MapMetaData<Float>> type) { try { thatMapMetaData = mapMetaData.recv(input); int thatMapSegNum = thatMapMetaData.getSegNum(); List<Map<String, Float>> thatMapListData = new ArrayList<>(thatMapSegNum); List<Integer> thatDataNums = new ArrayList<>(thatMapSegNum); for (int i = 0; i < thatMapSegNum; i++) { Map<String, Float> thisMapData = mapMetaData.getMapDataList().get(i); int dataNum = thatMapMetaData.getDataNum(i); for (int j = 0; j < dataNum; j++) { String key = input.readString(); Float val = input.readFloat(); Float thisVal = thisMapData.get(key); if (thisVal == null) { thisMapData.put(key, val); } else { thisMapData.put(key, operator.apply(thisVal, val)); } } thatMapListData.add(thisMapData); thatDataNums.add(thisMapData.size()); } thatMapMetaData.setMapDataList(thatMapListData); thatMapMetaData.setDataNums(thatDataNums); } catch (IOException e) { LOG.error("double array read exception", e); System.exit(1); } return thatMapMetaData; }
public static int[] convertUpdateIndexUseKryo(ByteString neededColIndexes) { Input input = new Input(neededColIndexes.toByteArray()); Kryo kryo = new Kryo(); kryo.register(Integer.class); int size = kryo.readObject(input, Integer.class); int[] ret = new int[size]; for (int i = 0; i < size; i++) { ret[i] = kryo.readObject(input, Integer.class); } return ret; }
@Override public ImmutableByteSequence read(Kryo kryo, Input input, Class<ImmutableByteSequence> type) { int length = input.readInt(); byte[] data = new byte[length]; input.read(data); return ImmutableByteSequence.copyFrom(data); }
@Override public ProviderId read(Kryo kryo, Input input, Class<ProviderId> type) { String scheme = input.readString(); String id = input.readString(); boolean isAncillary = input.readBoolean(); return new ProviderId(scheme, id, isAncillary); }
/** * Read object by reflection. * * @param <T> the type parameter * @param kryo the kryo * @param input the input * @param type the type * @return the t */ private static <T> T readObjectByReflection(final Kryo kryo, final Input input, final Class<? extends T> type) { try { final String className = kryo.readObject(input, String.class); final Class<T> clazz = (Class<T>) Class.forName(className); return kryo.readObject(input, clazz); } catch (final Exception e) { throw new RuntimeException(e); } }
@Override public HostLocation read(Kryo kryo, Input input, Class<HostLocation> type) { DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input); PortNumber portNumber = (PortNumber) kryo.readClassAndObject(input); long time = input.readLong(); return new HostLocation(deviceId, portNumber, time); }
@Override protected SamlService createService(final Kryo kryo, final Input input, final String id, final String originalUrl, final String artifactId) { final String requestId = kryo.readObject(input, String.class); try { return (SamlService) CONSTRUCTOR.newInstance(id, originalUrl, artifactId, new SimpleHttpClientFactoryBean().getObject(), requestId); } catch (final Exception e) { throw new IllegalStateException("Error creating SamlService", e); } }
@Override public FormattedDate read(Kryo kryo, Input input, Class<FormattedDate> aClass) { final Long time = this.longSerializer.read(kryo, input, Long.class); final String format = this.stringSerializer.read(kryo, input, String.class); final Locale locale = this.localeSerializer.read(kryo, input, Locale.class); return new FormattedDate(new Date(time), format, locale); }
@Override public RegisteredService read(final Kryo kryo, final Input input, final Class<RegisteredService> type) { final String id = kryo.readObject(input, String.class); final AbstractRegisteredService svc = new RegisteredServiceImpl(); svc.setServiceId(id); return svc; }
@Override public T read(final Kryo kryo, final Input input, final Class<T> type) { return createService(kryo, input, kryo.readObject(input, String.class), kryo.readObject(input, String.class), kryo.readObject(input, String.class)); }
@Override public ImmutableSet<Object> read(final Kryo kryo, final Input input, final Class<ImmutableSet<Object>> type) { final int size = input.readInt(true); final ImmutableSet.Builder builder = ImmutableSet.builder(); for (int i = 0; i < size; ++i) { builder.add(kryo.readClassAndObject(input)); } final ImmutableSet<Object> result = builder.build(); kryo.reference(result); return result; }