class RubyTDMS::Segment
Implements the TDMS segment, including a Segment
factory and stream parser. TODO: Refactor the parser out? Too much coupling between Segment
and Document
!
Constants
- FLAG_BIG_ENDIAN
- FLAG_DAQMX_RAW_DATA
- FLAG_INTERLEAVED_DATA
- FLAG_META_DATA
- FLAG_NEW_OBJECT_LIST
- FLAG_RAW_DATA
Attributes
chunk_count[R]
document[R]
length[R]
meta_data_length[R]
meta_data_offset[R]
objects[R]
raw_data_offset[R]
tag[R]
version[R]
Public Class Methods
new(document)
click to toggle source
# File lib/ruby_tdms/segment.rb, line 18 def initialize(document) @document = document @objects = [] end
parse_stream(stream, document)
click to toggle source
# File lib/ruby_tdms/segment.rb, line 25 def parse_stream(stream, document) new(document).tap do |new| new.parse_lead_in stream document.segments << new # TODO: smelly new.parse_meta_data stream if new.meta_data? end end
Public Instance Methods
big_endian?()
click to toggle source
# File lib/ruby_tdms/segment.rb, line 68 def big_endian? flag? FLAG_BIG_ENDIAN end
daqmx_data?()
click to toggle source
# File lib/ruby_tdms/segment.rb, line 58 def daqmx_data? flag? FLAG_DAQMX_RAW_DATA end
flag?(flag)
click to toggle source
Checks if the segment flags have flag
set. @param flag [Fixnum] The flag mask to check, like FLAG_META_DATA
or FLAG_RAW_DATA
. @return [Boolean] Whether the segment has the flag in question set.
# File lib/ruby_tdms/segment.rb, line 43 def flag?(flag) !!(@flags & flag == flag) end
interleaved_data?()
click to toggle source
# File lib/ruby_tdms/segment.rb, line 63 def interleaved_data? flag? FLAG_INTERLEAVED_DATA end
meta_data?()
click to toggle source
# File lib/ruby_tdms/segment.rb, line 48 def meta_data? flag? FLAG_META_DATA end
new_object_list?()
click to toggle source
# File lib/ruby_tdms/segment.rb, line 73 def new_object_list? flag? FLAG_NEW_OBJECT_LIST end
parse_lead_in(stream)
click to toggle source
protected
# File lib/ruby_tdms/segment.rb, line 80 def parse_lead_in(stream) @tag = stream.read 4 @flags = stream.read_u32 @version = stream.read_u32 @length = stream.read_u64 # Overall length of segment minus length of lead-in, aka "Next segment offset" in NI docs. @meta_data_length = stream.read_u64 # Overall length of meta information, aka "Raw data offset" in NI docs. @meta_data_offset = @meta_data_length > 0 ? stream.pos : nil @raw_data_offset = stream.pos + @meta_data_length # Stream offset at which raw data for this segment begins. @raw_data_length = @length == -1 ? stream.length - @raw_data_offset : @length - @meta_data_length # Number of bytes raw data occupies. NI docs say @length == -1 means the entire file, after lead-in and header, is raw data. end
parse_meta_data(stream)
click to toggle source
# File lib/ruby_tdms/segment.rb, line 93 def parse_meta_data(stream) @number_of_objects = stream.read_u32 @number_of_objects.times do object = ObjectParser.parse_stream stream, document, self @objects << object end @chunk_length = raw_channels.map(&:chunk_length).reduce(:+) # Length of an individual data chunk (summation of each object's raw data length) @chunk_count = @raw_data_length / @chunk_length raw_channels.each { |object| object.calculate_offsets } end
raw_channels()
click to toggle source
# File lib/ruby_tdms/segment.rb, line 35 def raw_channels objects.select { |object| object.is_a? Objects::Channel } end
raw_data?()
click to toggle source
# File lib/ruby_tdms/segment.rb, line 53 def raw_data? flag? FLAG_RAW_DATA end