Sha256: 36176b0ca38e56e929edba7604d7cf69a59236dcd7cffcf3c33cd273cc11ebdf
Contents?: true
Size: 778 Bytes
Versions: 8
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_bytes(io, padding) } end end
Version data entries
8 entries across 8 versions & 2 rubygems