com.aliyun.openservices.eas.predict.queue_client.DataFrame Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eas-sdk Show documentation
Show all versions of eas-sdk Show documentation
SDK for PAI-EAS online inference services
package com.aliyun.openservices.eas.predict.queue_client;
import com.aliyun.openservices.eas.predict.proto.QueueServiceProtos.DataFrameProto;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import shade.protobuf.InvalidProtocolBufferException;
import java.nio.ByteBuffer;
import java.util.Map;
public class DataFrame {
private static Log log = LogFactory.getLog(DataFrame.class);
private DataFrameProto.Builder data_frame = DataFrameProto.newBuilder();
private Exception error;
public DataFrame() {
}
public DataFrame(DataFrameProto df) {
data_frame.setIndex(df.getIndex());
data_frame.putAllTags(df.getTagsMap());
data_frame.setData(df.getData());
data_frame.setMessage(df.getMessage());
error = null;
}
public DataFrame(Exception ex) {
error = ex;
}
public Exception getError() {
return error;
}
public void setError(Exception error) {
this.error = error;
}
public void setTags(String key, String val) {
data_frame.putTags(key, val);
}
public void setAllTags(Map map) {
data_frame.putAllTags(map);
}
public long getIndex() {
return data_frame.getIndex();
}
public void setIndex(long index) {
data_frame.setIndex(index);
}
public Map getTags() {
return data_frame.getTagsMap();
}
public byte[] getData() {
return data_frame.getData().toByteArray();
}
public String getMessage() {
return data_frame.getMessage();
}
public void setMessage(String message) {
data_frame.setMessage(message);
}
public DataFrameProto getDataFrameProto() {
return data_frame.build();
}
public byte[] encode() {
return data_frame.build().toByteArray();
}
public DataFrame decode(byte[] dfProtoBytes) {
try {
DataFrameProto df = DataFrameProto.parseFrom(dfProtoBytes);
this.data_frame.clear();
this.data_frame.mergeFrom(df);
} catch (InvalidProtocolBufferException e) {
log.error("Invalid Protocol Buffer", e);
}
return this;
}
public DataFrame decode(ByteBuffer dfProtoByteBuffer) {
byte[] dfProtoBytes = new byte[dfProtoByteBuffer.remaining()];
dfProtoByteBuffer.get(dfProtoBytes);
return decode(dfProtoBytes);
}
}