lib/fit4ruby/FitDefinitionFieldBase.rb in fit4ruby-3.7.0 vs lib/fit4ruby/FitDefinitionFieldBase.rb in fit4ruby-3.8.0
- old
+ new
@@ -1,11 +1,11 @@
#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = FitDefinitionFieldBase.rb -- Fit4Ruby - FIT file processing library for Ruby
#
-# Copyright (c) 2014, 2017 by Chris Schlaeger <cs@taskjuggler.org>
+# Copyright (c) 2014, 2017, 2020 by Chris Schlaeger <cs@taskjuggler.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
@@ -28,25 +28,34 @@
entry[2]
end
def set_type(fit_type)
idx = FIT_TYPE_DEFS.index { |x| x[0] == fit_type }
- raise "Unknown type #{fit_type}" unless idx
+ raise ArgumentError, "Unknown type #{fit_type}" unless idx
self.base_type_number = idx
self.byte_count = FIT_TYPE_DEFS[idx][3]
end
def type(fit_type = false)
FIT_TYPE_DEFS[checked_base_type_number][fit_type ? 0 : 1]
end
+ def set_length(count)
+ if (byte_count = FIT_TYPE_DEFS[self.base_type_number][3] * count) > 255
+ raise ArgumentError,
+ "FitDefinitionField byte count too large (#{byte_count})"
+ end
+ self.byte_count = byte_count
+ end
+
def is_array?
if total_bytes > base_type_bytes
if total_bytes % base_type_bytes != 0
- Log.error "Total bytes (#{total_bytes}) must be multiple of " +
- "base type bytes (#{base_type_bytes}) of type " +
- "#{base_type_number.snapshot} in Global FIT " +
- "Message #{name}."
+ raise RuntimeError,
+ "Total bytes (#{total_bytes}) must be multiple of " +
+ "base type bytes (#{base_type_bytes}) of type " +
+ "#{base_type_number.snapshot} in Global FIT " +
+ "Message #{name}."
end
return true
end
false
end