Created
December 30, 2011 17:50
-
-
Save andruby/1540784 to your computer and use it in GitHub Desktop.
ruby-inline c version of unpack for L,S and d.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inline(:C) do |builder| | |
| builder.c " | |
| VALUE c_unpack_l(char *bytes) { | |
| uint32_t tmp; | |
| memcpy(&tmp, bytes, sizeof(uint32_t)); | |
| return INT2NUM(tmp); | |
| }" | |
| builder.c " | |
| VALUE c_unpack_s(char *bytes) { | |
| uint16_t tmp; | |
| memcpy(&tmp, bytes, sizeof(uint16_t)); | |
| return INT2NUM(tmp); | |
| }" | |
| builder.c " | |
| VALUE c_unpack_d(char *bytes) { | |
| double tmp; | |
| memcpy(&tmp, bytes, sizeof(double)); | |
| return DBL2NUM(tmp); | |
| }" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment