Class: Kobako::Wire::Handle

Inherits:
Data
  • Object
show all
Defined in:
lib/kobako/wire/handle.rb

Overview

Wire-level value object for an ext-0x01 Capability Handle.

SPEC pins the binary layout to fixext 4 with a 4-byte big-endian u32 payload (Wire Codec → Ext Types → ext 0x01). ID 0 is reserved as the invalid sentinel; the maximum valid ID is 0x7fff_ffff (2^31 - 1).

This is intentionally a thin value object built on Data.define so equality, hash, and immutability are inherited. The runtime-facing Kobako::Handle class lives at a higher layer and may add behaviour (HandleTable bookkeeping, reset semantics). The codec only needs to carry the opaque integer ID across the wire.

Constant Summary collapse

MIN_ID =
1
MAX_ID =
0x7fff_ffff

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:) ⇒ Handle

MIN_ID / MAX_ID live on the Handle class (defined below this block), not in this block’s binding — Data.define’s block scope resolves bare constants against the enclosing Wire module, so MIN_ID would raise NameError. Use self.class::CONST to reach the constants attached to the Handle class itself. Do not “simplify” this back to bare MIN_ID/MAX_ID.

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
# File 'lib/kobako/wire/handle.rb', line 23

def initialize(id:)
  min = self.class::MIN_ID
  max = self.class::MAX_ID
  raise ArgumentError, "Handle id must be Integer" unless id.is_a?(Integer)
  raise ArgumentError, "Handle id #{id} out of range [#{min}, #{max}]" unless id.between?(min, max)

  super
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



16
17
18
# File 'lib/kobako/wire/handle.rb', line 16

def id
  @id
end