Package com.esotericsoftware.kryo

Examples of com.esotericsoftware.kryo.Context


  public ByteArrayCompressor (Serializer serializer, int bufferSize) {
    super(serializer, bufferSize);
  }

  public void compress (ByteBuffer inputBuffer, Object object, ByteBuffer outputBuffer) {
    Context context = Kryo.getContext();
    int inputLength = inputBuffer.remaining();
    byte[] inputBytes = context.getBuffer(Math.max(inputLength, bufferSize)).array();
    inputBuffer.get(inputBytes, 0, inputLength);
    compress(inputBytes, inputLength, outputBuffer);
  }
View Full Code Here


   * @param outputBuffer A non-direct buffer.
   */
  abstract public void compress (byte[] inputBytes, int inputLength, ByteBuffer outputBuffer);

  public void decompress (ByteBuffer inputBuffer, Class type, ByteBuffer outputBuffer) {
    Context context = Kryo.getContext();
    int inputLength = inputBuffer.remaining();
    byte[] inputBytes = context.getBuffer(Math.max(inputLength, bufferSize)).array();
    inputBuffer.get(inputBytes, 0, inputLength);
    decompress(inputBytes, inputLength, outputBuffer);
  }
View Full Code Here

  public <T> T readObjectData (ByteBuffer buffer, Class<T> type) {
    return readObjectData(newInstance(kryo, type), buffer, type);
  }

  protected <T> T readObjectData (T object, ByteBuffer buffer, Class<T> type) {
    Context context = Kryo.getContext();
    CachedField[] fields = (CachedField[])context.getTemp(this, "schema");
    if (fields == null) {
      int length = IntSerializer.get(buffer, true);
      if (TRACE) trace("kryo", "Reading " + length + " field names.");
      String[] names = new String[length];
      for (int i = 0; i < length; i++)
        names[i] = StringSerializer.get(buffer);

      fields = new CachedField[length];
      CachedField[] allFields = this.fields;
      outer: //
      for (int i = 0, n = names.length; i < n; i++) {
        String schemaName = names[i];
        for (int ii = 0, nn = allFields.length; ii < nn; ii++) {
          if (allFields[ii].field.getName().equals(schemaName)) {
            fields[i] = allFields[ii];
            continue outer;
          }
        }
        if (TRACE) trace("kryo", "Ignoring obsolete field: " + schemaName);
      }
      context.putTemp(this, "schema", fields);
    }

    for (int i = 0, n = fields.length; i < n; i++) {
      int dataLength = IntSerializer.get(buffer, true);
View Full Code Here

  public ReferenceFieldSerializer (Kryo kryo, Class type) {
    super(kryo, type);
  }

  public void writeObjectData (ByteBuffer buffer, Object object) {
    Context context = Kryo.getContext();
    References references = (References)context.getTemp("references");
    if (references == null) {
      // Use non-temporary storage to avoid repeated allocation.
      references = (References)context.get("references");
      if (references == null)
        context.put("references", references = new References());
      else
        references.reset();
      context.putTemp("references", references);
    }
    Integer reference = references.objectToReference.get(object);
    if (reference != null) {
      IntSerializer.put(buffer, reference, true);
      if (TRACE) trace("kryo", "Wrote object reference " + reference + ": " + object);
View Full Code Here

    super.writeObjectData(buffer, object);
  }

  public <T> T readObjectData (ByteBuffer buffer, Class<T> type) {
    Context context = Kryo.getContext();
    References references = (References)context.getTemp("references");
    if (references == null) {
      // Use non-temporary storage to avoid repeated allocation.
      references = (References)context.get("references");
      if (references == null)
        context.put("references", references = new References());
      else
        references.reset();
      context.putTemp("references", references);
    }

    int reference = IntSerializer.get(buffer, true);
    if (reference != 0) {
      T object = (T)references.referenceToObject.get(reference);
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryo.Context

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.