Sha256: 4c53c6018c39ad893f2468143ce65db0bc795702b3f97394ea12ada804214ab7

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

= struct_packing

* http://github.com/TOKITAHiroshi/struct_packing

== DESCRIPTION:

* Read/Write ruby object to byte array with C-like struct declarations.

== INSTALL:

* sudo gem install struct_packing


== SYNOPSIS:
=== Packing object to byte array.
  class PackableOStruct < OpenStruct
    include StructPacking::Packable
    self.byte_format = "int foo; char bar; byte[1] baz;"
  end

  obj = PackableOStruct.new
  obj.foo = 1
  obj.bar = 2
  obj.baz = [8]
  packed_bytes = obj.pack # => "\x01\x00\x00\x00\x02\b"


=== Read object attributes from byte array.
  class UnpackableOStruct < OpenStruct
    include StructPacking::Unpackable
    self.byte_format = "char foo; byte[1] bar; int baz;"
  end

  obj = UnpackableOStruct.from_data [1, 2, 3, 0, 0, 0].pack("C*")
  obj.foo # => 1
  obj.bar # => [2]
  obj.baz # => 3


== LICENSE:

(The MIT License)

Copyright (c) 2013 TOKITA Hiroshi

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
struct_packing-0.0.3 README.rdoc
struct_packing-0.0.2 README.rdoc