Class: XDR::Opaque
Instance Method Summary
collapse
#valid?
#from_xdr, #to_xdr, #valid?
Constructor Details
#initialize(length) ⇒ Opaque
Returns a new instance of Opaque.
7
8
9
10
|
# File 'lib/xdr/opaque.rb', line 7
def initialize(length)
@length = length
@padding = padding_for length
end
|
Instance Method Details
#read(io) ⇒ Object
12
13
14
15
16
|
# File 'lib/xdr/opaque.rb', line 12
def read(io)
read_bytes(io, @length).tap { read_zeros(io, @padding) }
end
|
#write(val, io) ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/xdr/opaque.rb', line 18
def write(val, io)
length = val.bytesize
if val.length != @length
raise XDR::WriteError, "Value length is #{length}, must be #{@length}"
end
io.write val
io.write "\x00" * @padding
end
|