|
15 | 15 | */ |
16 | 16 | package com.github.sonus21.rqueue.spring.boot.integration; |
17 | 17 |
|
| 18 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 19 | +import com.fasterxml.jackson.databind.ObjectMapper; |
18 | 20 | import com.github.sonus21.rqueue.converter.MessageConverterProvider; |
19 | 21 | import java.io.IOException; |
20 | 22 | import java.util.Base64; |
21 | | -import org.msgpack.core.MessageBufferPacker; |
22 | | -import org.msgpack.core.MessagePack; |
23 | | -import org.msgpack.core.MessageUnpacker; |
| 23 | +import org.msgpack.jackson.dataformat.MessagePackFactory; |
24 | 24 | import org.springframework.messaging.Message; |
25 | 25 | import org.springframework.messaging.MessageHeaders; |
26 | 26 | import org.springframework.messaging.converter.MessageConversionException; |
@@ -77,36 +77,21 @@ public Message<?> toMessage(Object payload, MessageHeaders headers) { |
77 | 77 |
|
78 | 78 | private static final class MsgPackCodec { |
79 | 79 |
|
| 80 | + private static final ObjectMapper MAPPER = new ObjectMapper(new MessagePackFactory()); |
| 81 | + |
80 | 82 | private MsgPackCodec() {} |
81 | 83 |
|
82 | 84 | static byte[] encode(MessagePackageListenerTest.ListenerPayload payload) { |
83 | | - try (MessageBufferPacker packer = MessagePack.newDefaultBufferPacker()) { |
84 | | - packer.packMapHeader(2); |
85 | | - packer.packString("backend"); |
86 | | - packer.packString(payload.getBackend()); |
87 | | - packer.packString("body"); |
88 | | - packer.packString(payload.getBody()); |
89 | | - return packer.toByteArray(); |
90 | | - } catch (IOException e) { |
| 85 | + try { |
| 86 | + return MAPPER.writeValueAsBytes(payload); |
| 87 | + } catch (JsonProcessingException e) { |
91 | 88 | throw new MessageConversionException("MsgPack encoding failed", e); |
92 | 89 | } |
93 | 90 | } |
94 | 91 |
|
95 | 92 | static MessagePackageListenerTest.ListenerPayload decode(byte[] bytes) { |
96 | | - try (MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(bytes)) { |
97 | | - int entries = unpacker.unpackMapHeader(); |
98 | | - String backend = null; |
99 | | - String body = null; |
100 | | - for (int i = 0; i < entries; i++) { |
101 | | - String key = unpacker.unpackString(); |
102 | | - String value = unpacker.unpackString(); |
103 | | - if ("backend".equals(key)) { |
104 | | - backend = value; |
105 | | - } else if ("body".equals(key)) { |
106 | | - body = value; |
107 | | - } |
108 | | - } |
109 | | - return new MessagePackageListenerTest.ListenerPayload(backend, body); |
| 93 | + try { |
| 94 | + return MAPPER.readValue(bytes, MessagePackageListenerTest.ListenerPayload.class); |
110 | 95 | } catch (IOException e) { |
111 | 96 | throw new MessageConversionException("MsgPack decoding failed", e); |
112 | 97 | } |
|
0 commit comments