Skip to content

Instantly share code, notes, and snippets.

@andruby
Created December 30, 2011 17:50
Show Gist options
  • Select an option

  • Save andruby/1540784 to your computer and use it in GitHub Desktop.

Select an option

Save andruby/1540784 to your computer and use it in GitHub Desktop.
ruby-inline c version of unpack for L,S and d.
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