class Rex::Java::Serialization::Model::BlockDataLong
This class provides a block data (long) representation
Attributes
contents[RW]
@!attribute contents
@return [String] the contents of the block
length[RW]
@!attribute length
@return [Integer] the length of the block
Public Class Methods
new(stream = nil, contents = '')
click to toggle source
@param stream [Rex::Java::Serialization::Model::Stream] the stream where it belongs to @param contents [String] the contents of the block
Calls superclass method
# File lib/rex/java/serialization/model/block_data_long.rb, line 18 def initialize(stream = nil, contents = '') super(stream) self.contents = contents self.length = contents.length end
Public Instance Methods
decode(io)
click to toggle source
Deserializes a Rex::Java::Serialization::Model::BlockDataLong
@param io [IO] the io to read from @return [self] if deserialization succeeds @raise [Rex::Java::Serialization::DecodeError] if deserialization doesn't succeed
# File lib/rex/java/serialization/model/block_data_long.rb, line 29 def decode(io) raw_length = io.read(4) if raw_length.nil? || raw_length.length != 4 raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize BlockDataLong' end self.length = raw_length.unpack('N')[0] if length == 0 self.contents = '' else self.contents = io.read(length) if contents.nil? || contents.length != length raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize BlockData' end end self end
encode()
click to toggle source
Serializes the Rex::Java::Serialization::Model::BlockDataLong
@return [String]
# File lib/rex/java/serialization/model/block_data_long.rb, line 51 def encode encoded = [length].pack('N') encoded << contents encoded end
to_s()
click to toggle source
Creates a print-friendly string representation
@return [String]
# File lib/rex/java/serialization/model/block_data_long.rb, line 61 def to_s contents_hex = [] contents.each_byte {|byte| contents_hex << "0x#{byte.to_s(16)}" } "[ #{contents_hex.join(', ')} ]" end