Module: Palm::WabaIOSupport
- Included in:
- WabaIO, WabaStringIO
- Defined in:
- lib/palm/waba_io.rb
Overview
Wildly unoptimized! 50/50 stolen from SuperWaba’s datastream and shortcuts with pack ;)
Instance Method Summary collapse
- #get_bool ⇒ Object
- #get_byte ⇒ Object
- #get_int ⇒ Object
- #get_short ⇒ Object
- #get_string ⇒ Object
- #write_bool(b) ⇒ Object
- #write_byte(byte) ⇒ Object
- #write_int(integer) ⇒ Object
- #write_short(short) ⇒ Object
- #write_string(string) ⇒ Object
Instance Method Details
#get_bool ⇒ Object
27 28 29 |
# File 'lib/palm/waba_io.rb', line 27 def get_bool read(1)[0] != 0 end |
#get_byte ⇒ Object
15 16 17 |
# File 'lib/palm/waba_io.rb', line 15 def get_byte readchar end |
#get_int ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/palm/waba_io.rb', line 19 def get_int s = read(4) ((s[0] & 0xFF) << 24) | ((s[1] & 0xFF) << 16) | ((s[2] & 0xFF) << 8) | (s[3] & 0xFF) end |
#get_short ⇒ Object
10 11 12 13 |
# File 'lib/palm/waba_io.rb', line 10 def get_short s = read(2) ((s[0] & 0xFF) << 8) | (s[1] & 0xFF) end |
#get_string ⇒ Object
6 7 8 |
# File 'lib/palm/waba_io.rb', line 6 def get_string read(get_short) end |
#write_bool(b) ⇒ Object
52 53 54 |
# File 'lib/palm/waba_io.rb', line 52 def write_bool(b) putc b ? 1 : 0 end |
#write_byte(byte) ⇒ Object
41 42 43 |
# File 'lib/palm/waba_io.rb', line 41 def write_byte(byte) putc byte end |
#write_int(integer) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/palm/waba_io.rb', line 45 def write_int(integer) putc( (integer >> 24) & 0xFF ) putc( (integer >> 16) & 0xFF ) putc( (integer >> 8) & 0xFF ) putc( (integer >> 0) & 0xFF ) end |
#write_short(short) ⇒ Object
36 37 38 39 |
# File 'lib/palm/waba_io.rb', line 36 def write_short(short) putc( (short >> 8) & 0xFF ) putc( (short >> 0) & 0xFF ) end |
#write_string(string) ⇒ Object
31 32 33 34 |
# File 'lib/palm/waba_io.rb', line 31 def write_string(string) write_short(string.length) write string end |