public MessagePackGenerator( int features, ObjectCodec codec, OutputStream out, MessagePack.PackerConfig packerConfig, boolean reuseResourceInGenerator) throws IOException { super(features, codec); this.output = out; OutputStreamBufferOutput messageBufferOutput; if (reuseResourceInGenerator) { messageBufferOutput = messageBufferOutputHolder.get(); if (messageBufferOutput == null) { messageBufferOutput = new OutputStreamBufferOutput(out); messageBufferOutputHolder.set(messageBufferOutput); } else { messageBufferOutput.reset(out); } } else { messageBufferOutput = new OutputStreamBufferOutput(out); } this.messagePacker = packerConfig.newPacker(messageBufferOutput); this.packerConfig = packerConfig; this.stack = new LinkedList<StackItem>(); }
/** * Create an MessagePacker that outputs the packed data to the given {@link org.msgpack.core.buffer.MessageBufferOutput}. * This method is available for subclasses to override. Use MessagePack.PackerConfig.newPacker method to instanciate this implementation. * * @param out MessageBufferOutput. Use {@link org.msgpack.core.buffer.OutputStreamBufferOutput}, {@link org.msgpack.core.buffer.ChannelBufferOutput} or * your own implementation of {@link org.msgpack.core.buffer.MessageBufferOutput} interface. */ protected MessagePacker(MessageBufferOutput out, MessagePack.PackerConfig config) { this.out = checkNotNull(out, "MessageBufferOutput is null"); this.smallStringOptimizationThreshold = config.getSmallStringOptimizationThreshold(); this.bufferFlushThreshold = config.getBufferFlushThreshold(); this.str8FormatSupport = config.isStr8FormatSupport(); this.position = 0; this.totalFlushBytes = 0; }
/** * Creates a packer that serializes objects into the specified output. * <p> * {@link org.msgpack.core.buffer.MessageBufferOutput} is an interface that lets applications customize memory * allocation of internal buffer of {@link MessagePacker}. You may prefer {@link #newDefaultBufferPacker()}, * {@link #newDefaultPacker(OutputStream)}, or {@link #newDefaultPacker(WritableByteChannel)} methods instead. * <p> * This method is equivalent to <code>DEFAULT_PACKER_CONFIG.newPacker(out)</code>. * * @param out A MessageBufferOutput that allocates buffer chunks and receives the buffer chunks with packed data filled in them * @return A new MessagePacker instance */ public static MessagePacker newDefaultPacker(MessageBufferOutput out) { return DEFAULT_PACKER_CONFIG.newPacker(out); }
/** * Creates a packer that serializes objects into the specified output stream. * <p> * Note that you don't have to wrap OutputStream in BufferedOutputStream because MessagePacker has buffering * internally. * <p> * This method is equivalent to <code>DEFAULT_PACKER_CONFIG.newPacker(out)</code>. * * @param out The output stream that receives sequence of bytes * @return A new MessagePacker instance */ public static MessagePacker newDefaultPacker(OutputStream out) { return DEFAULT_PACKER_CONFIG.newPacker(out); }
/** * Creates a packer that serializes objects into the specified output stream. * <p> * Note that you don't have to wrap OutputStream in BufferedOutputStream because MessagePacker has buffering * internally. * * @param out The output stream that receives sequence of bytes * @return A new MessagePacker instance */ public MessagePacker newPacker(OutputStream out) { return newPacker(new OutputStreamBufferOutput(out, bufferSize)); }
/** * Creates a packer that serializes objects into byte arrays. * <p> * This method provides an optimized implementation of <code>newDefaultBufferPacker(new ByteArrayOutputStream())</code>. * * This method is equivalent to <code>DEFAULT_PACKER_CONFIG.newBufferPacker()</code>. * * @return A new MessageBufferPacker instance */ public static MessageBufferPacker newDefaultBufferPacker() { return DEFAULT_PACKER_CONFIG.newBufferPacker(); }
/** * Creates a packer that serializes objects into the specified writable channel. * <p> * This method is equivalent to <code>DEFAULT_PACKER_CONFIG.newPacker(channel)</code>. * * @param channel The output channel that receives sequence of bytes * @return A new MessagePacker instance */ public static MessagePacker newDefaultPacker(WritableByteChannel channel) { return DEFAULT_PACKER_CONFIG.newPacker(channel); }
public MessagePackFactory(MessagePackFactory src) { super(src, null); this.packerConfig = src.packerConfig.clone(); this.reuseResourceInGenerator = src.reuseResourceInGenerator; this.reuseResourceInParser = src.reuseResourceInParser; if (src.extTypeCustomDesers != null) { this.extTypeCustomDesers = new ExtensionTypeCustomDeserializers(src.extTypeCustomDesers); } }
/** * When the next payload size exceeds this threshold, MessagePacker will call * {@link org.msgpack.core.buffer.MessageBufferOutput#flush()} before writing more data (default: 8192). */ public PackerConfig withBufferFlushThreshold(int bytes) { PackerConfig copy = clone(); copy.bufferFlushThreshold = bytes; return copy; }
/** * Creates a packer that serializes objects into the specified writable channel. * * @param channel The output channel that receives sequence of bytes * @return A new MessagePacker instance */ public MessagePacker newPacker(WritableByteChannel channel) { return newPacker(new ChannelBufferOutput(channel, bufferSize)); }
@Override public PackerConfig clone() { return new PackerConfig(this); }
/** * Disable str8 format when needed backward compatibility between * different msgpack serializer versions. * default true (str8 supported enabled) */ public PackerConfig withStr8FormatSupport(boolean str8FormatSupport) { PackerConfig copy = clone(); copy.str8FormatSupport = str8FormatSupport; return copy; }
/** * When a packer is created with {@link #newPacker(OutputStream)} or {@link #newPacker(WritableByteChannel)}, the stream will be * buffered with this size of buffer (default: 8192). */ public PackerConfig withBufferSize(int bytes) { PackerConfig copy = clone(); copy.bufferSize = bytes; return copy; }
/** * Use String.getBytes() for converting Java Strings that are shorter than this threshold. * Note that this parameter is subject to change. */ public PackerConfig withSmallStringOptimizationThreshold(int length) { PackerConfig copy = clone(); copy.smallStringOptimizationThreshold = length; return copy; }
public MsgpackWriteSink(WriteSink sink, MessagePack.PackerConfig config) { this(sink, config.isStr8FormatSupport()); }