Sha256: b115cb32d3a7d3ebe7ea955f92626ab14afc726538f2cea5f335a2636db59d30
Contents?: true
Size: 778 Bytes
Versions: 3
Compression:
Stored size: 778 Bytes
Contents
class XDR::VarOpaque include XDR::Concerns::ConvertsToXDR include XDR::Concerns::StringConverter singleton_class.send(:alias_method, :[], :new) def initialize(length=XDR::MAX_SIZE) @length = length end def write(val, io) length = val.bytesize if length > @length raise XDR::WriteError, "Value length #{length} exceeds max #{@length}" end XDR::Int.write(length, io) io.write val io.write "\x00" * padding_for(length) end def read(io) length = XDR::Int.read(io) if length > @length raise XDR::ReadError, "VarOpaque length #{length}" end padding = padding_for length # read and return length bytes # throw away padding bytes read_bytes(io, length).tap{ read_zeros(io, padding) } end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
xdr-3.0.2 | lib/xdr/var_opaque.rb |
xdr-3.0.1 | lib/xdr/var_opaque.rb |
xdr-3.0.0 | lib/xdr/var_opaque.rb |