# File lib/snmp/pdu.rb, line 35 def decode(data, mib=nil) message_data, remainder = decode_sequence(data) assert_no_remainder(remainder) version, remainder = decode_version(message_data) community, remainder = decode_octet_string(remainder) pdu, remainder = decode_pdu(version, remainder, mib) assert_no_remainder(remainder) Message.new(version, community, pdu) end
# File lib/snmp/pdu.rb, line 57 def decode_pdu(version, data, mib=nil) pdu_tag, pdu_data, remainder = decode_tlv(data) case pdu_tag when GetRequest_PDU_TAG pdu = PDU.decode(GetRequest, pdu_data, mib) when GetNextRequest_PDU_TAG pdu = PDU.decode(GetNextRequest, pdu_data, mib) when Response_PDU_TAG pdu = PDU.decode(Response, pdu_data, mib) when SetRequest_PDU_TAG pdu = PDU.decode(SetRequest, pdu_data, mib) when SNMPv1_Trap_PDU_TAG raise InvalidPduTag, "SNMPv1-trap not valid for #{version.to_s}" if version != :SNMPv1 pdu = SNMPv1_Trap.decode(pdu_data, mib) when GetBulkRequest_PDU_TAG raise InvalidPduTag, "get-bulk not valid for #{version.to_s}" if version != :SNMPv2c pdu = PDU.decode(GetBulkRequest, pdu_data, mib) when InformRequest_PDU_TAG raise InvalidPduTag, "inform not valid for #{version.to_s}" if version != :SNMPv2c pdu = PDU.decode(InformRequest, pdu_data, mib) when SNMPv2_Trap_PDU_TAG raise InvalidPduTag, "SNMPv2c-trap not valid for #{version.to_s}" if version != :SNMPv2c pdu = PDU.decode(SNMPv2_Trap, pdu_data, mib) else raise UnsupportedPduTag, pdu_tag.to_s end return pdu, remainder end
# File lib/snmp/pdu.rb, line 45 def decode_version(data) version_data, remainder = decode_integer(data) if version_data == SNMP_V1 version = :SNMPv1 elsif version_data == SNMP_V2C version = :SNMPv2c else raise UnsupportedVersion, version_data.to_s end return version, remainder end
# File lib/snmp/pdu.rb, line 107 def encode data = encode_version(@version) data << encode_octet_string(@community) data << @pdu.encode encode_sequence(data) end
Generated with the Darkfish Rdoc Generator 2.