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.
267 268 269 270 271 272 273 274 275 |
# File 'lib/pocolog/block_stream.rb', line 267 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.
227 228 229 |
# File 'lib/pocolog/block_stream.rb', line 227 def @metadata_yaml end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
224 225 226 |
# File 'lib/pocolog/block_stream.rb', line 224 def name @name end |
#registry_xml ⇒ Object (readonly)
Returns the value of attribute registry_xml.
226 227 228 |
# File 'lib/pocolog/block_stream.rb', line 226 def registry_xml @registry_xml end |
#typename ⇒ Object (readonly)
Returns the value of attribute typename.
225 226 227 |
# File 'lib/pocolog/block_stream.rb', line 225 def typename @typename end |
Class Method Details
.parse(raw_data) ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/pocolog/block_stream.rb', line 243 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
229 230 231 232 233 234 235 236 |
# File 'lib/pocolog/block_stream.rb', line 229 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
238 239 240 241 |
# File 'lib/pocolog/block_stream.rb', line 238 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
291 292 293 294 295 296 297 298 299 |
# File 'lib/pocolog/block_stream.rb', line 291 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
286 287 288 |
# File 'lib/pocolog/block_stream.rb', line 286 def @metadata ||= YAML.safe_load() end |
#type ⇒ Object
277 278 279 280 281 282 283 284 |
# File 'lib/pocolog/block_stream.rb', line 277 def type if @type @type else registry = Typelib::Registry.from_xml(registry_xml) @type = registry.build(typename) end end |