class Rex::Java::Serialization::Model::Field
This class provides a field description representation (fieldDesc). It's used for both primitive descriptions (primitiveDesc) and object descriptions (objectDesc).
Attributes
@!attribute #field_type @return [Rex::Java::Serialization::Model::Utf] The type of the field on object types.
@!attribute name @return [Rex::Java::Serialization::Model::Utf] The name of the field.
@!attribute type @return [String] The type of the field.
Public Class Methods
@param stream [Rex::Java::Serialization::Model::Stream] the stream where it belongs to
# File lib/rex/java/serialization/model/field.rb, line 23 def initialize(stream = nil) super(stream) self.type = '' self.name = nil self.field_type = nil end
Public Instance Methods
Deserializes a Rex::Java::Serialization::Model::Field
@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/field.rb, line 35 def decode(io) code = io.read(1) unless code && is_valid?(code) raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize Field' end self.type = TYPE_CODES[code] self.name = Utf.decode(io, stream) if is_object? self.field_type = decode_field_type(io) end self end
Serializes the Rex::Java::Serialization::Model::Field
@return [String] if serialization succeeds @raise [Rex::Java::Serialization::EncodeError] if serialization doesn't succeed
# File lib/rex/java/serialization/model/field.rb, line 56 def encode unless name.kind_of?(Rex::Java::Serialization::Model::Utf) raise Rex::Java::Serialization::EncodeError, 'Failed to serialize Field' end unless is_type_valid? raise Rex::Java::Serialization::EncodeError, 'Failed to serialize Field' end encoded = '' encoded << TYPE_CODES.key(type) encoded << name.encode if is_object? encoded << encode_field_type end encoded end
Whether the field type is an object one.
@return [Boolean]
# File lib/rex/java/serialization/model/field.rb, line 101 def is_object? if OBJECT_TYPE_CODES.values.include?(type) return true end false end
Whether the field type is a primitive one.
@return [Boolean]
# File lib/rex/java/serialization/model/field.rb, line 90 def is_primitive? if PRIMITIVE_TYPE_CODES.values.include?(type) return true end false end
Whether the field type is valid.
@return [Boolean]
# File lib/rex/java/serialization/model/field.rb, line 79 def is_type_valid? if TYPE_CODES.values.include?(type) return true end false end
Creates a print-friendly string representation
@return [String]
# File lib/rex/java/serialization/model/field.rb, line 112 def to_s str = "#{name} " if is_primitive? str << "(#{type})" else str << "(#{field_type})" end str end
Private Instance Methods
Deserializes the `field_type` value.
@param io [IO] the io to read from @return [Java::Serialization::Model::Utf] @raise [Rex::Java::Serialization::DecodeError] if unserialization doesn't succeed
# File lib/rex/java/serialization/model/field.rb, line 158 def decode_field_type(io) allowed_contents = [Utf, Reference] type = decode_content(io, stream) unless allowed_contents.include?(type.class) raise Rex::Java::Serialization::DecodeError, 'Failed to unserialize Field field_type' end type end
Serializes the `field_type` attribute.
@return [String] @raise [Rex::Java::Serialization::EncodeError] if serialization fails
# File lib/rex/java/serialization/model/field.rb, line 141 def encode_field_type allowed_contents = [Utf, Reference] unless allowed_contents.include?(field_type.class) raise Rex::Java::Serialization::EncodeError, 'Failed to serialize Field' end encoded = encode_content(field_type) encoded end
Whether the type opcode is a valid one.
@param code [String] A type opcode @return [Boolean]
# File lib/rex/java/serialization/model/field.rb, line 129 def is_valid?(code) if TYPE_CODES.keys.include?(code) return true end false end