Created
June 23, 2010 20:21
-
-
Save grantr/450487 to your computer and use it in GitHub Desktop.
This file contains 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
# riddle/lib/riddle/client/response.rb | |
# Return the next integer value from the stream | |
def next_int | |
int = next_int_fast(@str, @marker) | |
@marker += 4 | |
int | |
end | |
#TODO should make this independent of endianness (swap makes it only work on little-endian) | |
inline do |builder| | |
builder.c <<-EOC | |
static unsigned long next_int_fast(VALUE str, int mark) | |
{ | |
char *s; | |
unsigned long m = 0; | |
s = RSTRING(str)->ptr + mark; | |
memcpy((char*)(&m), s, 4); | |
m = ((((m)&0xFF)<<24) \ | |
|(((m)>>24)&0xFF) \ | |
|(((m)&0x0000FF00)<<8) \ | |
|(((m)&0x00FF0000)>>8) ); | |
return m; | |
} | |
EOC | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment