Class: Tina4Ultipa::Codec::Reader
- Inherits:
-
Object
- Object
- Tina4Ultipa::Codec::Reader
- Defined in:
- lib/tina4_ultipa/codec.rb
Overview
Walks a self-describing binary blob, reading little-endian fixed-width ints, length-prefixed strings, and TypedValueEntry composites. Mirrors Python _Reader.
Instance Attribute Summary collapse
-
#d ⇒ Object
Returns the value of attribute d.
-
#p ⇒ Object
Returns the value of attribute p.
Instance Method Summary collapse
-
#initialize(data) ⇒ Reader
constructor
A new instance of Reader.
-
#props ⇒ Object
uint16 count of (uint16 keyLen + key + TypedValueEntry) property pairs.
-
#str ⇒ Object
uint16 length prefix + that many UTF-8 bytes.
-
#tve ⇒ Object
A TypedValueEntry: type u8, isNull u8, len u32, data -> decoded value (nil if null).
- #u16 ⇒ Object
- #u32 ⇒ Object
- #u64 ⇒ Object
- #u8 ⇒ Object
Constructor Details
#initialize(data) ⇒ Reader
Returns a new instance of Reader.
203 204 205 206 |
# File 'lib/tina4_ultipa/codec.rb', line 203 def initialize(data) @d = (data || "".b).dup.force_encoding("BINARY") @p = 0 end |
Instance Attribute Details
#d ⇒ Object
Returns the value of attribute d.
201 202 203 |
# File 'lib/tina4_ultipa/codec.rb', line 201 def d @d end |
#p ⇒ Object
Returns the value of attribute p.
201 202 203 |
# File 'lib/tina4_ultipa/codec.rb', line 201 def p @p end |
Instance Method Details
#props ⇒ Object
uint16 count of (uint16 keyLen + key + TypedValueEntry) property pairs.
251 252 253 254 255 256 257 258 |
# File 'lib/tina4_ultipa/codec.rb', line 251 def props out = {} u16.times do key = str out[key] = tve end out end |
#str ⇒ Object
uint16 length prefix + that many UTF-8 bytes.
233 234 235 236 237 238 |
# File 'lib/tina4_ultipa/codec.rb', line 233 def str n = u16 v = @d.byteslice(@p, n).dup.force_encoding("UTF-8") @p += n v end |
#tve ⇒ Object
A TypedValueEntry: type u8, isNull u8, len u32, data -> decoded value (nil if null).
241 242 243 244 245 246 247 248 |
# File 'lib/tina4_ultipa/codec.rb', line 241 def tve t = u8 is_null = u8 n = u32 data = @d.byteslice(@p, n) @p += n is_null.zero? ? Codec.scalar(t, data) : nil end |
#u16 ⇒ Object
214 215 216 217 218 |
# File 'lib/tina4_ultipa/codec.rb', line 214 def u16 v = @d.byteslice(@p, 2).unpack1("S<") @p += 2 v end |
#u32 ⇒ Object
220 221 222 223 224 |
# File 'lib/tina4_ultipa/codec.rb', line 220 def u32 v = @d.byteslice(@p, 4).unpack1("L<") @p += 4 v end |
#u64 ⇒ Object
226 227 228 229 230 |
# File 'lib/tina4_ultipa/codec.rb', line 226 def u64 v = @d.byteslice(@p, 8).unpack1("Q<") @p += 8 v end |
#u8 ⇒ Object
208 209 210 211 212 |
# File 'lib/tina4_ultipa/codec.rb', line 208 def u8 v = @d.getbyte(@p) @p += 1 v end |