view src/main/java/alice/datasegment/ReceiveRemoteData.java @ 443:2f2623484b77 dispose

change protocol
author sugi
date Sat, 18 Oct 2014 19:30:13 +0900
parents aefbe41fcf12
children
line wrap: on
line source

package alice.datasegment;

import java.io.IOException;

import org.msgpack.type.Value;
import alice.codesegment.SingletonMessage;

public class ReceiveRemoteData implements ReceiverData {
    public byte[] val; // serialized with MessagePack. need decode

    public ReceiveRemoteData() {}

    public ReceiveRemoteData(byte[] val) {
        this.val = val;
    }

    public String asString() {
        return asClass(String.class);
    }

    public int asInteger() {
        Integer num = asClass(Integer.class);
        return num!=null ? num : 0;
    }

    public Float asFloat() {
        Float num = asClass(Float.class);
        return num!=null ? num : 0.0f;
    }

    public <T> T asClass(Class<T> clazz) {
        try {
            return SingletonMessage.getInstance().read(val, clazz);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;

    }

    public Value getVal() {
        return asClass(Value.class);
    }

    public Object getObj() {
        return val;
    }

}