当前位置: 首页>>代码示例>>Java>>正文


Java MessageUnpacker类代码示例

本文整理汇总了Java中org.msgpack.core.MessageUnpacker的典型用法代码示例。如果您正苦于以下问题:Java MessageUnpacker类的具体用法?Java MessageUnpacker怎么用?Java MessageUnpacker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MessageUnpacker类属于org.msgpack.core包,在下文中一共展示了MessageUnpacker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: unpackNS

import org.msgpack.core.MessageUnpacker; //导入依赖的package包/类
private static List<String> unpackNS(MessageUnpacker unpack, int remaining) throws IOException {
    List<String> list = new ArrayList<>(remaining);
    while ( remaining-- > 0 ) {
        String num;
        switch ( unpack.getNextFormat().getValueType() ) {
        case INTEGER:
            num = ""+unpack.unpackBigInteger();
            break;
        case FLOAT:
            num = ""+unpack.unpackDouble();
            break;
        default:
            String name = unpack.getNextFormat().getValueType().name();
            String typeName = name.substring(0, 1) + name.substring(1).toLowerCase();
            throw new MessageTypeException(String.format("Expected Number, but got %s", typeName));
        }
        list.add(num);
    }
    return list;
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:21,代码来源:AttributeValuePacker.java

示例2: unpackAttribute

import org.msgpack.core.MessageUnpacker; //导入依赖的package包/类
private Attribute unpackAttribute(String attributeName, MessageUnpacker unpacker) throws Exception {
    if ( ! unpacker.hasNext() ) {
        throw new IllegalArgumentException("Premature end of message pack stream");
    }
    Value value = unpacker.unpackValue();
    if ( value.isBinaryValue() ) {
        return new Attribute().withName(attributeName).withValue(value.asBinaryValue().asByteArray());
    } else if ( value.isFloatValue() ) {
        return new Attribute().withName(attributeName).withValue(value.asFloatValue().toDouble());
    } else if ( value.isIntegerValue() ) {
        IntegerValue intVal = value.asIntegerValue();
        if ( intVal.isInLongRange() ) {
            return new Attribute().withName(attributeName).withValue(intVal.asLong());
        } else {
            return new Attribute().withName(attributeName).withValue(intVal.asBigInteger());
        }
    } else if ( value.isStringValue() ) {
        return new Attribute().withName(attributeName).withValue(value.asStringValue().asString());
    } else {
        throw new UnsupportedOperationException("Message pack stream contained '"+value.getValueType()+"' type, but that type is not supported");
    }
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:23,代码来源:GenericConvertMarker.java

示例3: deserialize

import org.msgpack.core.MessageUnpacker; //导入依赖的package包/类
@Override
public <T> T deserialize( ModuleDescriptor module, ValueType valueType, InputStream state )
{
    try( MessageUnpacker unpacker = MessagePack.newDefaultUnpacker( state ) )
    {
        if( !unpacker.hasNext() )
        {
            return null;
        }
        ImmutableValue value = unpacker.unpackValue();
        return doDeserialize( module, valueType, value );
    }
    catch( IOException ex )
    {
        throw new SerializationException( "Unable to deserialize " + valueType, ex );
    }
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:18,代码来源:MessagePackDeserializer.java

示例4: mergeFrom

import org.msgpack.core.MessageUnpacker; //导入依赖的package包/类
/**
 * Merges the {@code message} with the byte array using the given {@code schema}.
 */
public static <T> void mergeFrom(byte[] data, int offset, int length, T message, Schema<T> schema, boolean numeric)
        throws IOException
{

    ArrayBufferInput bios = new ArrayBufferInput(data, offset, length);

    MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(bios);

    try
    {
        mergeFrom(unpacker, message, schema, numeric);
    }
    finally
    {
        unpacker.close();
    }
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:21,代码来源:MsgpackIOUtil.java

示例5: unpackL

import org.msgpack.core.MessageUnpacker; //导入依赖的package包/类
private static List<AttributeValue> unpackL(MessageUnpacker unpack, int remaining) throws IOException {
    List<AttributeValue> list = new ArrayList<>(remaining);
    while ( remaining-- > 0 ) {
        list.add(unpack(unpack));
    }
    return list;
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:8,代码来源:AttributeValuePacker.java

示例6: unpackBS

import org.msgpack.core.MessageUnpacker; //导入依赖的package包/类
private static List<ByteBuffer> unpackBS(MessageUnpacker unpack, int remaining) throws IOException {
    List<ByteBuffer> list = new ArrayList<>(remaining);
    while ( remaining-- > 0 ) {
        list.add(unpackByteBuffer(unpack));
    }
    return list;
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:8,代码来源:AttributeValuePacker.java

示例7: unpackSS

import org.msgpack.core.MessageUnpacker; //导入依赖的package包/类
private static List<String> unpackSS(MessageUnpacker unpack, int remaining) throws IOException {
    List<String> list = new ArrayList<>(remaining);
    while ( remaining-- > 0 ) {
        list.add(unpack.unpackString());
    }
    return list;
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:8,代码来源:AttributeValuePacker.java

示例8: decodeMessagePackEventStream

import org.msgpack.core.MessageUnpacker; //导入依赖的package包/类
private List<EventEntry> decodeMessagePackEventStream(final RawValue value) {
  final MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(value.asByteArray());
  final List<EventEntry> entries = new LinkedList<>();
  try {
    while (unpacker.hasNext()) {
      entries.add(decodeEntry(unpacker.unpackValue()));
    }
  } catch (final IOException e) {
    // An unpacker with array bytes should never fail……
    throw error("Failed unpacking.", value, e);
  }
  return entries;
}
 
开发者ID:okumin,项目名称:influent,代码行数:14,代码来源:MsgpackForwardRequestDecoder.java

示例9: toUniformObjectFromUnpacker

import org.msgpack.core.MessageUnpacker; //导入依赖的package包/类
public JUniformObject toUniformObjectFromUnpacker(MessageUnpacker unpacker) {
	if (unpacker == null) {
		return JUniformObject.OBJECT_NIL;
	}
	Value value;
	try {
		value = unpacker.unpackValue();
	} catch (IOException ex) {
		return JUniformObject.OBJECT_NIL;
	}
	return this.toUniformObjectFromObject(value);
}
 
开发者ID:actionk,项目名称:JUniform,代码行数:13,代码来源:JUniformPackerMessagePack.java

示例10: readSpanId

import org.msgpack.core.MessageUnpacker; //导入依赖的package包/类
static SpanId readSpanId(MessageUnpacker unpacker) throws IOException {
  int alen = unpacker.unpackBinaryHeader();
  if (alen != SPAN_ID_BYTE_LENGTH) {
    throw new IOException("Invalid length given for spanID array.  " +
        "Expected " + SPAN_ID_BYTE_LENGTH + "; got " + alen);
  }
  byte[] payload = new byte[SPAN_ID_BYTE_LENGTH];
  unpacker.readPayload(payload);
  return new SpanId(
      ((payload[ 7] & 0xffL) <<  0) |
      ((payload[ 6] & 0xffL) <<  8) |
      ((payload[ 5] & 0xffL) << 16) |
      ((payload[ 4] & 0xffL) << 24) |
      ((payload[ 3] & 0xffL) << 32) |
      ((payload[ 2] & 0xffL) << 40) |
      ((payload[ 1] & 0xffL) << 48) |
      ((payload[ 0] & 0xffL) << 56),
      ((payload[15] & 0xffL) <<  0) |
      ((payload[14] & 0xffL) <<  8) |
      ((payload[13] & 0xffL) << 16) |
      ((payload[12] & 0xffL) << 24) |
      ((payload[11] & 0xffL) << 32) |
      ((payload[10] & 0xffL) << 40) |
      ((payload[ 9] & 0xffL) << 48) |
      ((payload[ 8] & 0xffL) << 56)
    );
}
 
开发者ID:apache,项目名称:incubator-htrace,代码行数:28,代码来源:PackedBuffer.java

示例11: testPackSpans

import org.msgpack.core.MessageUnpacker; //导入依赖的package包/类
@Test(timeout = 60000)
public void testPackSpans() throws Exception {
  Random rand = new Random(123);
  byte[] arr = new byte[16384];
  ByteBuffer bb = ByteBuffer.wrap(arr);
  bb.limit(bb.capacity());
  PackedBuffer buf = new PackedBuffer(bb);
  final int NUM_TEST_SPANS = 5;
  Span[] spans = new Span[NUM_TEST_SPANS];
  for (int i = 0; i < NUM_TEST_SPANS; i++) {
    spans[i] = TestUtil.randomSpan(rand);
  }
  for (int i = 0; i < NUM_TEST_SPANS; i++) {
    buf.writeSpan(spans[i]);
  }
  LOG.info("wrote " + buf.toHexString());
  MessagePack msgpack = new MessagePack(PackedBuffer.MSGPACK_CONF);
  MessageUnpacker unpacker = msgpack.newUnpacker(arr, 0, bb.position());
  Span[] respans = new Span[NUM_TEST_SPANS];
  for (int i = 0; i < NUM_TEST_SPANS; i++) {
    respans[i] = PackedBuffer.readSpan(unpacker);
  }
  for (int i = 0; i < NUM_TEST_SPANS; i++) {
    Assert.assertEquals("Failed to read back span " + i,
        spans[i].toJson(), respans[i].toJson());
  }
}
 
开发者ID:apache,项目名称:incubator-htrace,代码行数:28,代码来源:TestPackedBuffer.java

示例12: testWithoutAckResponse

import org.msgpack.core.MessageUnpacker; //导入依赖的package包/类
@Test
public void testWithoutAckResponse()
        throws Throwable
{
    Exception exception = new ConfigurableTestServer().run(
            new ConfigurableTestServer.WithClientSocket() {
                @Override
                public void run(SocketChannel clientSocketChannel)
                        throws Exception
                {
                    MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(clientSocketChannel.socket().getChannel());
                    assertEquals(3, unpacker.unpackArrayHeader());
                    assertEquals("foo.bar", unpacker.unpackString());
                    ImmutableRawValue rawValue = unpacker.unpackValue().asRawValue();
                    Map<Value, Value> map = unpacker.unpackValue().asMapValue().map();
                    assertEquals(1, map.size());
                    assertEquals(rawValue.asByteArray().length, map.get(KEY_OPTION_SIZE).asIntegerValue().asInt());
                    unpacker.close();
                }
            },
            new ConfigurableTestServer.WithServerPort()
            {
                @Override
                public void run(int serverPort)
                        throws Exception
                {
                    Fluency fluency = Fluency.defaultFluency(serverPort);
                    fluency.emit("foo.bar", new HashMap<String, Object>());
                    fluency.close();
                }
            }, 5000);
    assertNull(exception);
}
 
开发者ID:komamitsu,项目名称:fluency,代码行数:34,代码来源:FluencyTest.java

示例13: testWithAckResponseButNotReceiveToken

import org.msgpack.core.MessageUnpacker; //导入依赖的package包/类
@Test
public void testWithAckResponseButNotReceiveToken()
        throws Throwable
{
    Exception exception = new ConfigurableTestServer().run(
            new ConfigurableTestServer.WithClientSocket() {
                @Override
                public void run(SocketChannel clientSocketChannel)
                        throws Exception
                {
                    MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(clientSocketChannel.socket().getChannel());
                    assertEquals(3, unpacker.unpackArrayHeader());
                    assertEquals("foo.bar", unpacker.unpackString());
                    ImmutableRawValue rawValue = unpacker.unpackValue().asRawValue();
                    Map<Value, Value> map = unpacker.unpackValue().asMapValue().map();
                    assertEquals(2, map.size());
                    assertEquals(rawValue.asByteArray().length, map.get(KEY_OPTION_SIZE).asIntegerValue().asInt());
                    assertNotNull(map.get(KEY_OPTION_CHUNK).asRawValue().asString());
                    unpacker.close();
                }
            },
            new ConfigurableTestServer.WithServerPort()
            {
                @Override
                public void run(int serverPort)
                        throws Exception
                {
                    Fluency fluency = Fluency.defaultFluency(serverPort, new Fluency.Config().setAckResponseMode(true));
                    fluency.emit("foo.bar", new HashMap<String, Object>());
                    fluency.close();
                }
            }, 5000);
    assertEquals(exception.getClass(), TimeoutException.class);
}
 
开发者ID:komamitsu,项目名称:fluency,代码行数:35,代码来源:FluencyTest.java

示例14: close

import org.msgpack.core.MessageUnpacker; //导入依赖的package包/类
@Override
public void close() throws IOException {
    try {
        MessageUnpacker messageUnpacker = getMessageUnpacker();
        messageUnpacker.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        isClosed = true;
    }
}
 
开发者ID:komamitsu,项目名称:jackson-dataformat-msgpack,代码行数:14,代码来源:MessagePackParser.java

示例15: getMessageUnpacker

import org.msgpack.core.MessageUnpacker; //导入依赖的package包/类
private MessageUnpacker getMessageUnpacker() {
    MessageUnpacker messageUnpacker = messageUnpackerHolder.get();
    if (messageUnpacker == null) {
        throw new IllegalStateException("messageUnpacker is null");
    }
    return messageUnpacker;
}
 
开发者ID:komamitsu,项目名称:jackson-dataformat-msgpack,代码行数:8,代码来源:MessagePackParser.java


注:本文中的org.msgpack.core.MessageUnpacker类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。