org.msgpack.unpacker.Unpacker Java Examples

The following examples show how to use org.msgpack.unpacker.Unpacker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParamUnpacker.java    From CNNdroid with MIT License 6 votes vote down vote up
private Unpacker read_parameters_MessagePack_Init(String name) {
    MessagePack msgpack = new MessagePack();
    File f = new File(name);
    byte[] nbytes = null;

    try {
        FileInputStream fin = new FileInputStream(f);
        nbytes = new byte[(int)f.length()];
        fin.read(nbytes);
        fin.close();

    } catch (Exception e) {
        Log.d("MessagePack_Init:", e.getMessage());
        return null;
    }

    ByteArrayInputStream in = new ByteArrayInputStream(nbytes);
    org.msgpack.unpacker.Unpacker unpack = msgpack.createUnpacker(in);
    return unpack;
}
 
Example #2
Source File: ParamUnpacker.java    From CNNdroid with MIT License 5 votes vote down vote up
public Object[] unpackerFunction(String paramFilePath, Class[] classTypes) {

        Object[] objects = new Object[2];
        try {
            Unpacker unpacker = read_parameters_MessagePack_Init(paramFilePath);
            objects[0] = unpacker.read(classTypes[0]);
            objects[1] = unpacker.read(classTypes[1]);
            unpacker.close();
            unpacker = null;
        } catch (Exception e) {
            Log.d("MessagePack Exception:", e.getMessage());
            return null;
        }
        return objects;
    }
 
Example #3
Source File: ParamUnpacker.java    From CNNdroid with MIT License 5 votes vote down vote up
public Object unpackerFunction(String paramFilePath, Class classType) {
    Object convParams;

    try {
        Unpacker unpacker = read_parameters_MessagePack_Init(paramFilePath);
        convParams = unpacker.read(classType);
        unpacker.close();
    } catch (Exception e) {
        Log.d("MessagePack_Init:", e.getMessage());
        return null;
    }

    return convParams;
}
 
Example #4
Source File: ObjectTemplate.java    From jvm-serializer with Apache License 2.0 5 votes vote down vote up
@Override
public Object read(Unpacker u, Object to, boolean required) throws IOException {
    if (!required && u.trySkipNil()) {
        return null;
    }

    return toObject(u.readValue());
}
 
Example #5
Source File: ObjectTemplate.java    From jvm-serializer with Apache License 2.0 5 votes vote down vote up
@Override
public Object read(Unpacker u, Object to, boolean required) throws IOException {
    if (!required && u.trySkipNil()) {
        return null;
    }

    return toObject(u.readValue());
}
 
Example #6
Source File: MsgpackParser.java    From transit-java with Apache License 2.0 5 votes vote down vote up
public MsgpackParser(Unpacker mp,
                     Map<String, ReadHandler<?,?>> handlers,
                     DefaultReadHandler defaultHandler,
                     MapReader<?, Map<Object, Object>, Object, Object> mapBuilder,
                     ArrayReader<?, List<Object>, Object> listBuilder) {
    super(handlers, defaultHandler, mapBuilder, listBuilder);
    this.mp = mp;
}
 
Example #7
Source File: MessagePackStreamDecoder.java    From msgpack-rpc-java with Apache License 2.0 5 votes vote down vote up
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel,
        ChannelBuffer source) throws Exception {
    // TODO #MN will modify the body with MessagePackBufferUnpacker.
    ByteBuffer buffer = source.toByteBuffer();
    if (!buffer.hasRemaining()) {
        return null;
    }
    source.markReaderIndex();

    byte[] bytes = buffer.array(); // FIXME buffer must has array
    int offset = buffer.arrayOffset() + buffer.position();
    int length = buffer.arrayOffset() + buffer.limit();
    ByteArrayInputStream stream = new ByteArrayInputStream(bytes, offset,
            length);
    int startAvailable = stream.available();
    try{
        Unpacker unpacker = msgpack.createUnpacker(stream);
        Value v = unpacker.readValue();
        source.skipBytes(startAvailable - stream.available());
        return v;
    }catch( EOFException e ){
        // not enough buffers.
        // So retry reading
        source.resetReaderIndex();
        return null;
    }
}
 
Example #8
Source File: ResponseMessage.java    From msgpack-rpc-java with Apache License 2.0 4 votes vote down vote up
public void readFrom(Unpacker u) throws IOException {
    throw new UnsupportedOperationException();
}
 
Example #9
Source File: RequestMessage.java    From msgpack-rpc-java with Apache License 2.0 4 votes vote down vote up
public void readFrom(Unpacker u) throws IOException {
    throw new UnsupportedOperationException();
}
 
Example #10
Source File: NotifyMessage.java    From msgpack-rpc-java with Apache License 2.0 4 votes vote down vote up
public void readFrom(Unpacker u) throws IOException {
    throw new UnsupportedOperationException();
}
 
Example #11
Source File: RemoteError.java    From msgpack-rpc-java with Apache License 2.0 4 votes vote down vote up
public void readFrom(Unpacker u) throws IOException {
    data = u.readValue();
}
 
Example #12
Source File: NoMethodError.java    From msgpack-rpc-java with Apache License 2.0 4 votes vote down vote up
public void readFrom(Unpacker u) throws IOException {
    throw new UnsupportedOperationException();
}