Class: Serialbench::Serializers::Yaml::SyckSerializer

Inherits:
BaseYamlSerializer show all
Defined in:
lib/serialbench/serializers/yaml/syck_serializer.rb

Instance Method Summary collapse

Methods inherited from BaseYamlSerializer

#default_generation_options, format, #stream_parse, #supports_generation?

Methods inherited from BaseSerializer

#get_version, #initialize, #require_library, #stream_parse

Constructor Details

This class inherits a constructor from Serialbench::Serializers::BaseSerializer

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 25

def available?
  require 'syck'
  # Verify that Syck module and methods are actually available
  return false unless defined?(Syck) && Syck.respond_to?(:dump) && Syck.respond_to?(:load)

  # Check for known problematic configurations
  if problematic_environment?
    warn_about_segfault_issue
    return false
  end

  true
rescue LoadError
  false
end

#descriptionObject



79
80
81
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 79

def description
  'Legacy YAML parser (Ruby < 1.9.3)'
end

#featuresObject



75
76
77
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 75

def features
  %w[parsing generation legacy]
end

#generate(object, _options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 56

def generate(object, _options = {})
  return nil unless available?

  begin
    require 'syck'
    Syck.dump(object)
  rescue StandardError => e
    if e.message.include?('Segmentation fault') || e.is_a?(SystemExit)
      handle_segfault_error
      return nil
    end
    raise e
  end
end

#handle_segfault_errorObject



95
96
97
98
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 95

def handle_segfault_error
  puts '❌ ERROR: Syck YAML serializer encountered a segmentation fault'
  puts "   This is a known issue on Ruby #{RUBY_VERSION}. Skipping remaining Syck tests."
end

#nameObject



9
10
11
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 9

def name
  'syck'
end

#parse(yaml_string) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 41

def parse(yaml_string)
  return nil unless available?

  begin
    require 'syck'
    Syck.load(yaml_string)
  rescue StandardError => e
    if e.message.include?('Segmentation fault') || e.is_a?(SystemExit)
      handle_segfault_error
      return nil
    end
    raise e
  end
end

#problematic_environment?Boolean

Returns:

  • (Boolean)


83
84
85
86
87
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 83

def problematic_environment?
  # Ruby 3.1+ has issues with Syck
  (Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1.0')) &&
    (Gem::Version.new(version) >= Gem::Version.new('1.4.0'))
end

#supports_streaming?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 71

def supports_streaming?
  false
end

#versionObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 13

def version
  require 'syck'
  # Try to get version from gem specification
  spec = Gem.loaded_specs['syck']
  return spec.version.to_s if spec

  # Fallback to a default version if no gem spec found
  '1.0.0'
rescue StandardError
  'N/A'
end

#warn_about_segfault_issueObject



89
90
91
92
93
# File 'lib/serialbench/serializers/yaml/syck_serializer.rb', line 89

def warn_about_segfault_issue
  puts "⚠️  WARNING: The Syck YAML serializer is known to cause segmentation faults with Ruby #{RUBY_VERSION}"
  puts '   This is a known issue with the syck gem on newer Ruby versions systems.'
  puts '   Skipping Syck benchmarks to prevent crashes. See README for more details.'
end