import org.msgpack.core.MessagePack; import org.msgpack.core.MessagePacker; import org.msgpack.core.MessageUnpacker; import org.msgpack.value.Value; import org.msgpack.value.ValueType; public class MsgPackExample { public static void main(String[] args) { try { MessagePacker packer = MessagePack.newDefaultPacker(System.out); packer.packInt(42); packer.packString("Hello, World!"); MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(System.in); int intValue = unpacker.unpackInt(); Value stringValue = unpacker.unpackValue(); System.out.println("Unpacked int value: " + intValue); if (stringValue.getValueType() == ValueType.STRING) { System.out.println("Unpacked string value: " + stringValue.asStringValue()); } packer.close(); unpacker.close(); } catch (Exception e) { e.printStackTrace(); } } }


上一篇:
下一篇:
切换中文