/** * Creates a ActiveMQBuffer wrapping an underlying NIO ByteBuffer * * <p>The position on this buffer won't affect the position on the inner buffer * * @param underlying the underlying NIO ByteBuffer * @return a ActiveMQBuffer wrapping the underlying NIO ByteBuffer */ public static ActiveMQBuffer wrappedBuffer(final ByteBuffer underlying) { ActiveMQBuffer buff = new ChannelBufferWrapper(Unpooled.wrappedBuffer(underlying)); buff.clear(); return buff; }
/** * Creates a <em>self-expanding</em> ActiveMQBuffer filled with the given byte array * * @param bytes the created buffer will be initially filled with this byte array * @return a self-expanding ActiveMQBuffer filled with the given byte array */ public static ActiveMQBuffer dynamicBuffer(final byte[] bytes) { ActiveMQBuffer buff = dynamicBuffer(bytes.length); buff.writeBytes(bytes); return buff; }
/** * Encodes this TransportConfiguration into a buffer. * * <p>Note that this is only used internally ActiveMQ Artemis. * * @param buffer the buffer to encode into */ public void encode(final ActiveMQBuffer buffer) { buffer.writeString(name); buffer.writeString(factoryClassName); buffer.writeInt(params == null ? 0 : params.size()); if (params != null) { encodeMap(buffer, params); } if (extraProps != null) { encodeMap(buffer, extraProps); } }
/** * Decodes this TransportConfiguration from a buffer. * * <p>Note this is only used internally by ActiveMQ * * @param buffer the buffer to decode from */ public void decode(final ActiveMQBuffer buffer) { name = buffer.readString(); factoryClassName = buffer.readString(); int num = buffer.readInt(); if (params == null) { if (num > 0) { params = new HashMap<>(); } } else { params.clear(); } for (int i = 0; i < num; i++) { String key = buffer.readString(); byte type = buffer.readByte(); Object val; switch (type) { case TYPE_BOOLEAN: { val = buffer.readBoolean(); break; } case TYPE_INT: { val = buffer.readInt(); break; } case TYPE_LONG: { val = buffer.readLong(); break; } case TYPE_STRING: { val = buffer.readString(); break; } default: { throw ActiveMQClientMessageBundle.BUNDLE.invalidType(type); } } params.put(key, val); } }
private void encodeMap(final ActiveMQBuffer buffer, final Map<String, Object> map) { for (Map.Entry<String, Object> entry : map.entrySet()) { buffer.writeString(entry.getKey()); Object val = entry.getValue(); if (val instanceof Boolean) { buffer.writeByte(TransportConfiguration.TYPE_BOOLEAN); buffer.writeBoolean((Boolean) val); } else if (val instanceof Integer) { buffer.writeByte(TransportConfiguration.TYPE_INT); buffer.writeInt((Integer) val); } else if (val instanceof Long) { buffer.writeByte(TransportConfiguration.TYPE_LONG); buffer.writeLong((Long) val); } else if (val instanceof String) { buffer.writeByte(TransportConfiguration.TYPE_STRING); buffer.writeString((String) val); } else { throw ActiveMQClientMessageBundle.BUNDLE.invalidEncodeType(val); } } }