Class: Pocolog::BlockStream::StreamBlock
- Inherits:
-
Object
- Object
- Pocolog::BlockStream::StreamBlock
- Defined in:
- lib/pocolog/block_stream.rb
Overview
Information about a stream declaration block
Instance Attribute Summary collapse
-
#metadata_yaml ⇒ Object
readonly
Returns the value of attribute metadata_yaml.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#registry_xml ⇒ Object
readonly
Returns the value of attribute registry_xml.
-
#typename ⇒ Object
readonly
Returns the value of attribute typename.
Class Method Summary collapse
- .parse(raw_data) ⇒ Object
- .read(raw_data, offset, count) ⇒ Object
- .read_string(raw_data, offset) ⇒ Object
Instance Method Summary collapse
-
#encode ⇒ Object
Return the encoded (on-disk) representation of this stream definition.
-
#initialize(name, typename, registry_xml, metadata_yaml) ⇒ StreamBlock
constructor
A new instance of StreamBlock.
- #metadata ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(name, typename, registry_xml, metadata_yaml) ⇒ StreamBlock
Returns a new instance of StreamBlock
218 219 220 221 222 223 224 225 226 |
# File 'lib/pocolog/block_stream.rb', line 218 def initialize(name, typename, registry_xml, ) @name = name @typename = typename @registry_xml = registry_xml @metadata_yaml = @type = nil @metadata = nil end |
Instance Attribute Details
#metadata_yaml ⇒ Object (readonly)
Returns the value of attribute metadata_yaml
178 179 180 |
# File 'lib/pocolog/block_stream.rb', line 178 def @metadata_yaml end |
#name ⇒ Object (readonly)
Returns the value of attribute name
175 176 177 |
# File 'lib/pocolog/block_stream.rb', line 175 def name @name end |
#registry_xml ⇒ Object (readonly)
Returns the value of attribute registry_xml
177 178 179 |
# File 'lib/pocolog/block_stream.rb', line 177 def registry_xml @registry_xml end |
#typename ⇒ Object (readonly)
Returns the value of attribute typename
176 177 178 |
# File 'lib/pocolog/block_stream.rb', line 176 def typename @typename end |
Class Method Details
.parse(raw_data) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/pocolog/block_stream.rb', line 194 def self.parse(raw_data) name, offset = read_string(raw_data, 1) typename, offset = read_string(raw_data, offset) if raw_data.size > offset registry_xml, offset = read_string(raw_data, offset) else registry_xml = "<?xml version='1.0'?>\n<typelib></typelib>" end if raw_data.size > offset , offset = read_string(raw_data, offset) else = "--- {}\n" end if offset != raw_data.size raise InvalidBlockFound, "#{raw_data.size - offset} bytes unclaimed in "\ 'stream declaration block' end new(name, typename, registry_xml, ) end |
.read(raw_data, offset, count) ⇒ Object
180 181 182 183 184 185 186 187 |
# File 'lib/pocolog/block_stream.rb', line 180 def self.read(raw_data, offset, count) if raw_data.size < offset + count raise NotEnoughData, 'expected stream block header to be at least of size '\ "#{offset + count}, but got only #{raw_data.size}" end raw_data[offset, count] end |
.read_string(raw_data, offset) ⇒ Object
189 190 191 192 |
# File 'lib/pocolog/block_stream.rb', line 189 def self.read_string(raw_data, offset) size = read(raw_data, offset, 4).unpack('V').first [read(raw_data, offset + 4, size), (offset + 4 + size)] end |
Instance Method Details
#encode ⇒ Object
Return the encoded (on-disk) representation of this stream definition
242 243 244 245 246 247 248 249 250 |
# File 'lib/pocolog/block_stream.rb', line 242 def encode # rubocop:disable Metrics/AbcSize [ DATA_STREAM, name.size, name, typename.size, typename, registry_xml.size, registry_xml, .size, ].pack("CVa#{name.size}Va#{typename.size}"\ "Va#{registry_xml.size}Va#{.size}") end |
#metadata ⇒ Object
237 238 239 |
# File 'lib/pocolog/block_stream.rb', line 237 def @metadata ||= YAML.safe_load() end |
#type ⇒ Object
228 229 230 231 232 233 234 235 |
# File 'lib/pocolog/block_stream.rb', line 228 def type if @type @type else registry = Typelib::Registry.from_xml(registry_xml) @type = registry.build(typename) end end |