| 1 |
# mruby-pack (pack / unpack) |
| 2 |
|
| 3 |
mruby-pack provides `Array#pack` and `String#unpack` for mruby. |
| 4 |
|
| 5 |
## Installation |
| 6 |
|
| 7 |
Add the line below into your build configuration: |
| 8 |
|
| 9 |
``` |
| 10 |
conf.gem :core => 'mruby-pack' |
| 11 |
``` |
| 12 |
|
| 13 |
There is no dependency on other mrbgems. |
| 14 |
|
| 15 |
## Supported template string |
| 16 |
|
| 17 |
- A : arbitrary binary string (space padded, count is width) |
| 18 |
- a : arbitrary binary string (null padded, count is width) |
| 19 |
- B : bit string (descending) |
| 20 |
- b : bit string (ascending) |
| 21 |
- C : 8-bit unsigned (unsigned char) |
| 22 |
- c : 8-bit signed (signed char) |
| 23 |
- D, d: 64-bit float, native format |
| 24 |
- E : 64-bit float, little endian byte order |
| 25 |
- e : 32-bit float, little endian byte order |
| 26 |
- F, f: 32-bit float, native format |
| 27 |
- G : 64-bit float, network (big-endian) byte order |
| 28 |
- g : 32-bit float, network (big-endian) byte order |
| 29 |
- H : hex string (high nibble first) |
| 30 |
- h : hex string (low nibble first) |
| 31 |
- I : unsigned integer, native endian (`unsigned int` in C) |
| 32 |
- i : signed integer, native endian (`int` in C) |
| 33 |
- J : unsigned integer, native endian (`uintptr_t` in C) |
| 34 |
- j : signed integer, native endian (`intptr_t` in C) |
| 35 |
- L : 32-bit unsigned, native endian (`uint32_t`) |
| 36 |
- l : 32-bit signed, native endian (`int32_t`) |
| 37 |
- m : base64 encoded string (see RFC 2045, count is width) |
| 38 |
- N : 32-bit unsigned, network (big-endian) byte order |
| 39 |
- n : 16-bit unsigned, network (big-endian) byte order |
| 40 |
- Q : 64-bit unsigned, native endian (`uint64_t`) |
| 41 |
- q : 64-bit signed, native endian (`int64_t`) |
| 42 |
- S : 16-bit unsigned, native endian (`uint16_t`) |
| 43 |
- s : 16-bit signed, native endian (`int16_t`) |
| 44 |
- U : UTF-8 character |
| 45 |
- V : 32-bit unsigned, VAX (little-endian) byte order |
| 46 |
- v : 16-bit unsigned, VAX (little-endian) byte order |
| 47 |
- x : null byte |
| 48 |
- Z : same as "a", except that null is added with * |
| 49 |
|
| 50 |
## License |
| 51 |
|
| 52 |
Copyright (c) 2012 Internet Initiative Japan Inc. |
| 53 |
Copyright (c) 2017 mruby developers |
| 54 |
|
| 55 |
Permission is hereby granted, free of charge, to any person obtaining a |
| 56 |
copy of this software and associated documentation files (the "Software"), |
| 57 |
to deal in the Software without restriction, including without limitation |
| 58 |
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 59 |
and/or sell copies of the Software, and to permit persons to whom the |
| 60 |
Software is furnished to do so, subject to the following conditions: |
| 61 |
|
| 62 |
The above copyright notice and this permission notice shall be included in |
| 63 |
all copies or substantial portions of the Software. |
| 64 |
|
| 65 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 66 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 67 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 68 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 69 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 70 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 71 |
DEALINGS IN THE SOFTWARE. |