marcandre-packable 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -70,20 +70,20 @@ Although the standard string formats can still be used, it is possible to pass a
70
70
  These are the options for core types:
71
71
 
72
72
  === Integer
73
- +bytes+:: Number of bytes (default is 4) to use.
74
- +endian+:: Either <tt>:big</tt> (default) or <tt>:small</tt>.
75
- +signed+:: Either +true+ (default) or not. This will make a difference only when unpacking.
73
+ [+bytes+] Number of bytes (default is 4) to use.
74
+ [+endian+] Either <tt>:big</tt> (or :network, default) or <tt>:little</tt>.
75
+ [+signed+] Either +true+ (default) or not. This will make a difference only when unpacking.
76
76
 
77
77
  === Float
78
- +precision+:: Either <tt>:single</tt> (default) or <tt>:double</tt>.
79
- +endian+:: Either <tt>:big</tt> (default) or <tt>:small</tt>.
78
+ [+precision+] Either <tt>:single</tt> (default) or <tt>:double</tt>.
79
+ [+endian+] Either <tt>:big</tt> (or :network, default) or <tt>:little</tt>.
80
80
 
81
81
  === String
82
- +bytes+:: Total length (default is the full length)
83
- +fill+:: The string to use for filling when packing a string shorter than the specified bytes option. Default is a space.
82
+ [+bytes+] Total length (default is the full length)
83
+ [+fill+] The string to use for filling when packing a string shorter than the specified bytes option. Default is a space.
84
84
 
85
85
  === Array
86
- +repeat+:: This option can be used (when packing only) to repeat the current option. A value of <tt>:all</tt> will mean for all remaining elements of the array.
86
+ [+repeat+] This option can be used (when packing only) to repeat the current option. A value of <tt>:all</tt> will mean for all remaining elements of the array.
87
87
 
88
88
  When unpacking, it is necessary to specify the class in addition to any option, like so:
89
89
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- patch: 1
2
+ patch: 2
3
3
  major: 1
4
4
  minor: 1
@@ -20,7 +20,7 @@ module Packable
20
20
 
21
21
  module ClassMethods #:nodoc:
22
22
  def pack_option_to_format(options)
23
- format = {:big => "G", :small => "E"}[options[:endian]]
23
+ format = {:big => "G", :network => "G", :little => "E"}[options[:endian]]
24
24
  format.downcase! if options[:precision] == :single
25
25
  format
26
26
  end
@@ -25,13 +25,13 @@ module Packable
25
25
  val >>= 8
26
26
  byte.chr
27
27
  end
28
- chars.reverse! if options[:endian] == :big
28
+ chars.reverse! unless options[:endian] == :little
29
29
  io << chars.join
30
30
  end
31
31
 
32
32
  module ClassMethods #:nodoc:
33
33
  def unpack_string(s,options)
34
- s = s.reverse if options[:endian != :big]
34
+ s = s.reverse if options[:endian] == :little
35
35
  r = 0
36
36
  s.each_byte {|b| r = (r << 8) + b}
37
37
  r -= 1 << (8 * options[:bytes]) if options[:signed] && (1 == r >> (8 * options[:bytes] - 1))
data/test/packing_test.rb CHANGED
@@ -43,7 +43,8 @@ class TestingPack < Test::Unit::TestCase
43
43
  end
44
44
 
45
45
  def test_integer
46
- assert_equal "\002\001\000", 258.pack(:bytes => 3, :endian => :small)
46
+ assert_equal "\002\001\000", 258.pack(:bytes => 3, :endian => :little)
47
+ assert_equal 258, Integer.unpack("\002\001\000", :bytes => 3, :endian => :little)
47
48
  assert_equal (1<<24)-1, -1.pack(:bytes => 3).unpack(Integer, :bytes => 3, :signed => false)
48
49
  assert_equal -1, -1.pack(:bytes => 3).unpack(Integer, :bytes => 3, :signed => true)
49
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marcandre-packable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Marc-Andr\xC3\xA9 Lafortune"