Class: Dommy::Bridge::Bytes
- Inherits:
-
Array
- Object
- Array
- Dommy::Bridge::Bytes
- Defined in:
- lib/dommy/bridge.rb
Overview
A byte buffer that crosses the JS boundary as a Uint8Array (rather than a
plain Array). Wrap a host method's byte-array result in this so JS sees a
real typed array — e.g. TextEncoder#encode, Blob#arrayBuffer. The
reverse direction (a JS ArrayBuffer/TypedArray argument) arrives as a
Bytes too. It subclasses Array so plain-Array callers (and == [..]
comparisons) keep working; only the bridge treats it specially.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(bytes = []) ⇒ Bytes
constructor
A new instance of Bytes.
- #pack_bytes ⇒ Object
Constructor Details
#initialize(bytes = []) ⇒ Bytes
Returns a new instance of Bytes.
91 92 93 94 |
# File 'lib/dommy/bridge.rb', line 91 def initialize(bytes = []) super() concat(Array(bytes).map { |b| b.to_i & 0xFF }) end |
Instance Method Details
#pack_bytes ⇒ Object
97 |
# File 'lib/dommy/bridge.rb', line 97 def pack_bytes = pack("C*") |