com.weavechain.core.encoding.MsgPackContentEncoder Maven / Gradle / Ivy
package com.weavechain.core.encoding;
import com.weavechain.core.data.ConvertUtils;
import com.weavechain.core.data.DataLayout;
import com.weavechain.core.data.DataType;
import com.weavechain.core.data.Records;
import org.apache.commons.codec.binary.Base64;
import org.msgpack.core.MessageBufferPacker;
import org.msgpack.core.MessagePack;
import org.msgpack.core.MessageUnpacker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class MsgPackContentEncoder implements ContentEncoder {
public static final String TYPE = "mpack";
static final Logger logger = LoggerFactory.getLogger(MsgPackContentEncoder.class);
@Override
public String getType() {
return TYPE;
}
@Override
public String encode(Records data, DataLayout layout) {
try {
MessageBufferPacker packer = MessagePack.newDefaultBufferPacker();
packer.packString(data.getTable());
packer.packArrayHeader(data.getItems().size());
for (List