本文整理汇总了Java中org.msgpack.core.MessagePacker类的典型用法代码示例。如果您正苦于以下问题:Java MessagePacker类的具体用法?Java MessagePacker怎么用?Java MessagePacker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessagePacker类属于org.msgpack.core包,在下文中一共展示了MessagePacker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import org.msgpack.core.MessagePacker; //导入依赖的package包/类
void write(MessagePacker packer) throws IOException {
Visitor visitor = new Visitor(packer);
packer.packArrayHeader(3);
packer.packString(this.type);
if (this.data != null) {
packer.packMapHeader(this.data.size());
for (Map.Entry<String, Object> entry : this.data.entrySet()) {
packer.packString(entry.getKey());
visitor.visit(entry.getValue());
}
} else {
packer.packNil();
}
packer.packString(this.nodeId);
packer.close();
}
示例2: toMarkerThrows
import org.msgpack.core.MessagePacker; //导入依赖的package包/类
private String toMarkerThrows(Map<String, Object> attributes, boolean hasHashKey) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
MessagePacker packer = MessagePack.newDefaultPacker(out);
packer.packArrayHeader(size(hasHashKey));
if ( ! hasHashKey ) {
pack(packer, attributes, _hkName);
}
if ( null == _otherKeyNames ) {
packer.flush();
return BASE64_ENCODER.encodeToString(out.toByteArray());
}
for ( String keyName : _otherKeyNames ) {
pack(packer, attributes, keyName);
}
packer.flush();
return BASE64_ENCODER.encodeToString(out.toByteArray());
}
示例3: _writeSimpleObjectToPacker
import org.msgpack.core.MessagePacker; //导入依赖的package包/类
private void _writeSimpleObjectToPacker(Object object, MessagePacker packer) throws IOException {
if (object == null) {
packer.packNil();
} else if (object instanceof Byte) {
packer.packByte((Byte)object);
} else if (object instanceof Boolean) {
packer.packBoolean((Boolean)object);
} else if (object instanceof Double) {
packer.packDouble((Double)object);
} else if (object instanceof Float) {
packer.packFloat((Float)object);
} else if (object instanceof Integer) {
packer.packInt((Integer)object);
} else if (object instanceof Long) {
packer.packLong((Long)object);
} else if (object instanceof Short) {
packer.packShort((Short)object);
} else if (object instanceof String) {
packer.packString((String)object);
} else {
packer.packNil();
}
}
示例4: flush
import org.msgpack.core.MessagePacker; //导入依赖的package包/类
@Override
public void flush() throws IOException {
if (rootStackItem != null) {
if (rootStackItem instanceof StackItemForObject) {
packObject((StackItemForObject) rootStackItem);
}
else if (rootStackItem instanceof StackItemForArray) {
packArray((StackItemForArray) rootStackItem);
}
else {
throw new IllegalStateException("Unexpected rootStackItem: " + rootStackItem);
}
MessagePacker messagePacker = getMessagePacker();
messagePacker.flush();
}
}
示例5: writeTo
import org.msgpack.core.MessagePacker; //导入依赖的package包/类
/**
* Serializes the {@code message} into an {@link MessageBufferOutput} using the given {@code schema}.
*/
public static <T> void writeTo(MessageBufferOutput out, T message, Schema<T> schema, boolean numeric)
throws IOException
{
MessagePacker packer = MessagePack.newDefaultPacker(out);
try
{
writeTo(packer, message, schema, numeric);
}
finally
{
packer.flush();
}
}
示例6: writeListTo
import org.msgpack.core.MessagePacker; //导入依赖的package包/类
/**
* Serializes the {@code messages} into the stream using the given schema.
*/
public static <T> void writeListTo(OutputStream out, List<T> messages,
Schema<T> schema, boolean numeric) throws IOException
{
MessagePacker packer = MessagePack.newDefaultPacker(out);
try
{
writeListTo(packer, messages, schema, numeric);
}
finally
{
packer.flush();
}
}
示例7: packBigNumber
import org.msgpack.core.MessagePacker; //导入依赖的package包/类
public MessagePacker packBigNumber(BigInteger bn) throws IOException {
byte sign = 0;
if (bn.compareTo(new BigInteger("0")) < 0) {
sign = '-';
bn = bn.abs();
} else {
sign = '+';
}
byte[] data = Arrays.prepend(bn.toByteArray(), sign);
this.packExtensionTypeHeader((byte) 0, data.length);
this.addPayload(data);
return this;
}
示例8: packEcGroup
import org.msgpack.core.MessagePacker; //导入依赖的package包/类
/**
* Packs id of EcGroup used.
* Fixed at id=713
*/
public MessagePacker packEcGroup() throws IOException {
MessageBufferPacker packer = MessagePack.newDefaultBufferPacker();
packer.packInt(713);
byte[] data = packer.toByteArray();
this.packExtensionTypeHeader((byte) 1, data.length);
this.addPayload(data);
return this;
}
示例9: packEcPoint
import org.msgpack.core.MessagePacker; //导入依赖的package包/类
/**
* Packs id of EcGroup used and EcPoint data.
* EcGroup id fixed at 713
*/
public MessagePacker packEcPoint(ECPoint point) throws IOException {
byte[] data = ecPointToByteArray(point);
this.packExtensionTypeHeader((byte) 2, data.length);
this.addPayload(data);
return this;
}
示例10: packNumber
import org.msgpack.core.MessagePacker; //导入依赖的package包/类
private static void packNumber(MessagePacker pack, String num) throws IOException {
BigDecimal dec = new BigDecimal(num);
try {
pack.packBigInteger(dec.toBigIntegerExact());
} catch ( ArithmeticException ex ) {
pack.packDouble(dec.doubleValue());
}
}
示例11: serialize
import org.msgpack.core.MessagePacker; //导入依赖的package包/类
@Override
public void serialize( Options options, OutputStream output, @Optional Object object )
{
try( MessagePacker packer = MessagePack.newDefaultPacker( output ) )
{
Value value = doSerialize( options, object, true );
packer.packValue( value );
packer.flush();
}
catch( IOException ex )
{
throw new SerializationException( "Unable to serialize " + object, ex );
}
}
示例12: fromUniformObject
import org.msgpack.core.MessagePacker; //导入依赖的package包/类
@Override
public Object fromUniformObject(JUniformObject object) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
MessagePacker packer = _msgpack.newPacker(out);
try {
this._writeJUniformObjectToPacker(object, packer);
packer.close();
} catch (IOException ex) {
return null;
}
return out.toByteArray();
}
示例13: PackedBuffer
import org.msgpack.core.MessagePacker; //导入依赖的package包/类
/**
* Create a new PackedBuffer.
*
* @param bb The ByteBuffer to use to create the packed buffer.
*/
PackedBuffer(ByteBuffer bb) {
this.bb = bb;
this.out = new PackedBufferOutput();
this.temp = new byte[SPAN_ID_BYTE_LENGTH];
this.packer = new MessagePacker(out, MSGPACK_CONF);
}
示例14: packObject
import org.msgpack.core.MessagePacker; //导入依赖的package包/类
private void packObject(StackItemForObject stackItem) throws IOException {
List<String> keys = stackItem.getKeys();
List<Object> values = stackItem.getValues();
MessagePacker messagePacker = getMessagePacker();
messagePacker.packMapHeader(keys.size());
for (int i = 0; i < keys.size(); i++) {
messagePacker.packString(keys.get(i));
Object v = values.get(i);
packValue(v);
}
}
示例15: packArray
import org.msgpack.core.MessagePacker; //导入依赖的package包/类
private void packArray(StackItemForArray stackItem) throws IOException {
List<Object> values = stackItem.getValues();
MessagePacker messagePacker = getMessagePacker();
messagePacker.packArrayHeader(values.size());
for (int i = 0; i < values.size(); i++) {
Object v = values.get(i);
packValue(v);
}
}