Class: Dommy::Bridge::Bytes

Inherits:
Array
  • Object
show all
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

ArrayBuffer

Instance Method Summary collapse

Constructor Details

#initialize(bytes = []) ⇒ Bytes

Returns a new instance of Bytes.



80
81
82
83
# File 'lib/dommy/bridge.rb', line 80

def initialize(bytes = [])
  super()
  concat(Array(bytes).map { |b| b.to_i & 0xFF })
end

Instance Method Details

#pack_bytesObject



86
# File 'lib/dommy/bridge.rb', line 86

def pack_bytes = pack("C*")