Sha256: a4c38ee4dc302d56526dbfd3f2bcc3a027db665fec391fe306e5dc65d8033945

Contents?: true

Size: 1.85 KB

Versions: 3

Compression:

Stored size: 1.85 KB

Contents

# -*- coding: binary -*-

module Rex
  module Java
    module Serialization
      module Model
        # This class provides a Java classDesc representation
        class ClassDesc < Element

          include Rex::Java::Serialization::Model::Contents

          attr_accessor :description

          # @param stream [Rex::Java::Serialization::Model::Stream] the stream where it belongs to
          def initialize(stream = nil)
            super(stream)
            self.description = nil
          end

          # Deserializes a Rex::Java::Serialization::Model::ClassDesc
          #
          # @param io [IO] the io to read from
          # @return [self] if deserialization succeeds
          # @raise [RuntimeError] if deserialization doesn't succeed
          def decode(io)
            content = decode_content(io, stream)
            allowed_contents = [NullReference, NewClassDesc, Reference]

            unless allowed_contents.include?(content.class)
              raise ::RuntimeError, 'ClassDesc unserialize failed'
            end

            self.description = content
            self
          end

          # Serializes the Rex::Java::Serialization::Model::ClassDesc
          #
          # @return [String] if serialization succeeds
          # @raise [RuntimeError] if serialization doesn't succeed
          def encode
            encoded = ''
            allowed_contents = [NullReference, NewClassDesc, Reference]

            unless allowed_contents.include?(description.class)
              raise ::RuntimeError, 'Failed to serialize ClassDesc'
            end

            encoded << encode_content(description)

            encoded
          end

          # Creates a print-friendly string representation
          #
          # @return [String]
          def to_s
            print_content(description)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rex-2.0.8 lib/rex/java/serialization/model/class_desc.rb
rex-2.0.7 lib/rex/java/serialization/model/class_desc.rb
rex-2.0.5 lib/rex/java/serialization/model/class_desc.rb