Class: Fontisan::Binary::BaseRecord

Inherits:
BinData::Record
  • Object
show all
Defined in:
lib/fontisan/binary/base_record.rb

Overview

Base class for all BinData record definitions

Provides common configuration for OpenType binary structures:

  • Big-endian byte order (OpenType standard)
  • Common helper methods

All table parsers and binary structures should inherit from this class to ensure consistent behavior across the codebase.

Examples:

Defining a simple structure

class MyTable < Binary::BaseRecord
  uint16 :version
  uint16 :count
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#raw_dataString

Get the raw binary data that was read

Returns:

  • (String)

    Raw binary data



49
50
51
# File 'lib/fontisan/binary/base_record.rb', line 49

def raw_data
  @raw_data || to_binary_s
end

Class Method Details

.read(io) ⇒ Object

Override read to handle nil/empty/String inputs gracefully.

String inputs are wrapped in a StringIO so the rest of the read path always works against an IO-like object.

Parameters:

  • io (String, IO, StringIO, nil)

    binary data or IO source



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fontisan/binary/base_record.rb', line 31

def self.read(io)
  return new if io.nil?

  io = StringIO.new(io) if io.is_a?(String)
  return new if io.is_a?(StringIO) && io.eof?

  # Store the original data for later parsing
  data = io.read
  io.rewind
  instance = super(io)

  instance.raw_data = data
  instance
end

Instance Method Details

#valid?Boolean

Check if the record is valid

Returns:

  • (Boolean)

    True if valid, false otherwise



59
60
61
# File 'lib/fontisan/binary/base_record.rb', line 59

def valid?
  true
end