Package com.dyuproject.protostuff

Examples of com.dyuproject.protostuff.LinkedBuffer


   */
  @SuppressWarnings("unchecked")
  public byte[] serialize(Object obj, @SuppressWarnings("rawtypes") Class clazz) throws IOException {
    @SuppressWarnings("rawtypes")
    Schema schema = RuntimeSchema.getSchema(clazz);
    final LinkedBuffer buffer = LinkedBuffer.allocate(serBufferSize);
    byte[] protostuff = null;

    try {
      protostuff = ProtostuffIOUtil.toByteArray(obj, schema, buffer);
    } finally {
      buffer.clear();
    }   
    return protostuff;
  }
View Full Code Here


   */
  @SuppressWarnings("unchecked")
  public byte[] serialize(Object obj, @SuppressWarnings("rawtypes") Class clazz) throws IOException {
    @SuppressWarnings("rawtypes")
    Schema schema = RuntimeSchema.getSchema(clazz);
    final LinkedBuffer buffer = localBuffer.get();
    byte[] protostuff = null;

    try {
      protostuff = ProtostuffIOUtil.toByteArray(obj, schema, buffer);
    } finally {
      buffer.clear();
    }   
    return protostuff;
  }
View Full Code Here

    System.out.println("average serialize duration: " + (double)(serializeMon.getTotal() / serializeMon.getCounter())/1000000 + "ms");
  }

  public static byte[] serialize(DummyPojo obj) throws IOException {
     Schema<DummyPojo> schema = RuntimeSchema.getSchema(DummyPojo.class);
     final LinkedBuffer buffer = LinkedBuffer.allocate(serBufferSize);
     byte[] protostuff = null;

     try {
       protostuff = ProtostuffIOUtil.toByteArray(obj, schema, buffer);
     } finally {
       buffer.clear();
     }   

     return protostuff;
  }
View Full Code Here

  public byte[] serialize(Object obj, @SuppressWarnings("rawtypes") Class clazz) throws IOException {
        Stopwatch stopWatch = SimonManager.getStopwatch("serializer.PSSerialize");
    Split split = stopWatch.start();
    @SuppressWarnings("rawtypes")
    Schema schema = RuntimeSchema.getSchema(clazz);
    final LinkedBuffer buffer = LinkedBuffer.allocate(serBufferSize);
    byte[] protostuff = null;

    try {
      protostuff = ProtostuffIOUtil.toByteArray(obj, schema, buffer);
    } finally {
      buffer.clear();
    }   
    split.stop();
    return protostuff;
  }
View Full Code Here

        throws IOException
    {
        @SuppressWarnings( "unchecked" ) // type should be safe since got directly from the obj
        final Class<T> clazz = (Class<T>) obj.getClass();
        final Schema<T> schema = getSchema( clazz );
        final LinkedBuffer buffer = allocate( serBufferSize );
        byte[] protostuff = null;

        try
        {
            protostuff = toByteArray( obj, schema, buffer );
        }
        finally
        {
            buffer.clear();
        }
        return protostuff;
    }
View Full Code Here

    {
        @SuppressWarnings( "unchecked" ) // type should be safe since got directly from the obj
        final Class<T> clazz = (Class<T>) obj.getClass();
        final Schema<T> schema = getSchema( clazz );

        final LinkedBuffer buffer = localBuffer.get();
        byte[] protostuff = null;

        try
        {
            protostuff = toByteArray( obj, schema, buffer );
        }
        finally
        {
            buffer.clear();
        }
        return protostuff;
    }
View Full Code Here

   * @return the byte array
   */
  @SuppressWarnings("unchecked")
    public static final <T> byte[] seriOne(T o) {
      Schema<T> schema = (Schema<T>) RuntimeSchema.getSchema(o.getClass());
      LinkedBuffer buffer = LinkedBuffer.allocate(BUF_SIZE);
      return ProtostuffIOUtil.toByteArray(o, schema, buffer);
  }
View Full Code Here

   * @return the byte array
   */
  @SuppressWarnings("unchecked")
    public static final byte[] seriMulti(Object[] params) {
    ByteArrayOutputStream out = new ByteArrayOutputStream(BUF_SIZE * 2);
    LinkedBuffer buffer = LinkedBuffer.allocate(BUF_SIZE);
    try {
        for (int i = 0; i < params.length; ++i) {
            Schema<Object> schema = (Schema<Object>) RuntimeSchema.getSchema(params[i].getClass());
            ProtostuffIOUtil.writeDelimitedTo(out, params[i], schema, buffer);
            buffer.clear();
        }
    } catch (Exception e) {
            throw new SeriException("Error occured when serialize using protostuff.", e);
        }
    return out.toByteArray();
View Full Code Here

    }

    @Override
    public T deserialize(T t) throws IOException {
      t = (t == null) ? newInstance() : t;
      LinkedBuffer buff = threadLocalBuffer.get();
      ProtobufIOUtil.mergeDelimitedFrom(in, t, t, buff);
      buff.clear();
      return t;
    }
View Full Code Here

      this.out = out;
    }

    @Override
    public void serialize(T t) throws IOException {
      LinkedBuffer buff = threadLocalBuffer.get();
      ProtobufIOUtil.writeDelimitedTo(out, t, t, buff);
      buff.clear();
    }
View Full Code Here

TOP

Related Classes of com.dyuproject.protostuff.LinkedBuffer

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.