Class: Capnp::StreamMessage
- Extended by:
- T::Sig
- Defined in:
- lib/capnp/runtime/message/stream_message.rb
Instance Attribute Summary collapse
-
#segments ⇒ Object
readonly
Returns the value of attribute segments.
Instance Method Summary collapse
-
#initialize(buffer) ⇒ StreamMessage
constructor
A new instance of StreamMessage.
- #segment(id) ⇒ Object
Methods inherited from Message
Constructor Details
#initialize(buffer) ⇒ StreamMessage
Returns a new instance of StreamMessage.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/capnp/runtime/message/stream_message.rb', line 11 def initialize(buffer) # Extract number of segments number_of_segments = buffer.read_u32(0) + 1 # Calculate size of the message header offset = 4 * (number_of_segments + 1) offset += 4 if number_of_segments.even? # Check that the buffer is large enough for all segment sizes raise Capnp::Error.new("Not enough segment sizes provided") if buffer.size <= offset # Create segments segments = (1..number_of_segments).map do |ix| # Get segment size in bytes segment_size = buffer.read_u32(ix * 4) * Capnp::WORD_SIZE # Check that the buffer is large enough for the segment raise Capnp::Error.new("Buffer smaller than provided segment sizes") if buffer.size < offset + segment_size # Create segment slice = buffer.slice(offset, segment_size) segment = Capnp::Segment.new(self, slice) offset += segment_size segment end @segments = T.let(segments, T::Array[Capnp::Segment]) end |
Instance Attribute Details
#segments ⇒ Object (readonly)
Returns the value of attribute segments.
42 43 44 |
# File 'lib/capnp/runtime/message/stream_message.rb', line 42 def segments @segments end |