Class: Async::Utilization::Schema
- Inherits:
-
Object
- Object
- Async::Utilization::Schema
- Defined in:
- lib/async/utilization/schema.rb
Overview
Defines a schema for shared memory serialization.
The schema defines the layout and types for serializing utilization metrics to shared memory. It’s only needed when using Observer for shared memory storage - the Registry itself doesn’t require a schema.
Defined Under Namespace
Classes: Field
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
- #The fields in this schema.(fields) ⇒ Object readonly
Class Method Summary collapse
-
.build(fields) ⇒ Object
Build a schema from raw fields.
Instance Method Summary collapse
-
#[](field) ⇒ Object
Get field information for a given field.
-
#initialize(fields) ⇒ Schema
constructor
Initialize a new schema.
-
#to_a ⇒ Object
Convert schema to array format for shared memory.
Constructor Details
#initialize(fields) ⇒ Schema
Initialize a new schema.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/async/utilization/schema.rb', line 49 def initialize(fields) @fields = fields.freeze # Build an offsets cache mapping field names to Field objects for fast lookup @offsets = {} @fields.each do |field| @offsets[field.name] = field end @offsets.freeze end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
61 62 63 |
# File 'lib/async/utilization/schema.rb', line 61 def fields @fields end |
#The fields in this schema.(fields) ⇒ Object (readonly)
61 |
# File 'lib/async/utilization/schema.rb', line 61 attr :fields |
Class Method Details
.build(fields) ⇒ Object
Build a schema from raw fields.
Factory method that takes a hash of field names to types and creates Field instances with calculated offsets.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/async/utilization/schema.rb', line 34 def self.build(fields) field_instances = [] offset = 0 fields.each do |key, type| field_instances << Field.new(name: key.to_sym, type: type, offset: offset) offset += IO::Buffer.size_of(type) end new(field_instances) end |
Instance Method Details
#[](field) ⇒ Object
Get field information for a given field.
67 68 69 |
# File 'lib/async/utilization/schema.rb', line 67 def [](field) @offsets[field.to_sym] end |
#to_a ⇒ Object
Convert schema to array format for shared memory.
74 75 76 77 78 |
# File 'lib/async/utilization/schema.rb', line 74 def to_a @fields.map do |field| [field.name, field.type, field.offset] end end |