Package org.capnproto

Class MessageBuilder


  • public final class MessageBuilder
    extends Object
    • Constructor Detail

      • MessageBuilder

        public MessageBuilder()
      • MessageBuilder

        public MessageBuilder​(int firstSegmentWords)
      • MessageBuilder

        public MessageBuilder​(Allocator allocator)
        Constructs a new MessageBuilder from an Allocator.
      • MessageBuilder

        public MessageBuilder​(Allocator allocator,
                              ByteBuffer firstSegment)
        Constructs a new MessageBuilder from an Allocator and a given first segment buffer. This is useful for reusing the first segment buffer between messages, to avoid repeated allocations. You MUST ensure that firstSegment contains only zeroes before calling this method. If you are reusing firstSegment from another message, then it suffices to call clearFirstSegment() on that message.
      • MessageBuilder

        public MessageBuilder​(ByteBuffer firstSegment)
        Like the previous constructor, but uses a DefaultAllocator. You MUST ensure that firstSegment contains only zeroes before calling this method. If you are reusing firstSegment from another message, then it suffices to call clearFirstSegment() on that message.
    • Method Detail

      • unsafeConstructFromMessageReader

        public static MessageBuilder unsafeConstructFromMessageReader​(MessageReader messageReader)
        Constructs a MessageBuilder from a MessageReader without copying the segments. This method should only be used on trusted data. Otherwise you may observe infinite loops or large memory allocations or index-out-of-bounds errors.
      • setRoot

        public <T,​U> void setRoot​(SetPointerBuilder<T,​U> factory,
                                        U reader)
      • getSegmentsForOutput

        public final ByteBuffer[] getSegmentsForOutput()
      • clearFirstSegment

        public final void clearFirstSegment()
        Sets the first segment buffer to contain all zeros so that it can be reused in another message. (See the MessageBuilder(Allocator, ByteBuffer) constructor above.) After calling this method, the message will be corrupted. Therefore, you need to make sure to write the message (via getSegmentsForOutput()) before calling this.