예제 #1
0
 def decode_interest(self, input: bytearray) -> Name:
     """
     Decode an interest packet
     :param input: Interest packet in NDN-TLV wire format
     :return: Name
     """
     decoder = TlvDecoder(input)
     decoder.readNestedTlvsStart(Tlv.Interest)
     return self.decode_name(decoder)
예제 #2
0
 def decode_heartbeat(self, input: bytearray) -> Name:
     """
     Decode a heartbeat packet
     :param input: Heartbeat packet in NDN-TLV wire format
     :return: Name
     """
     decoder = TlvDecoder(input)
     decoder.readNestedTlvsStart(self.heartbeatTV)
     return self.decode_name(decoder)
예제 #3
0
 def decode_meta_info(self, decoder: TlvDecoder) -> None:
     """
     Decode meta info
     :param decoder: Decoder
     :return: Nothing so far
     """
     endOffset = decoder.readNestedTlvsStart(Tlv.MetaInfo)
     # Does not yet parse meta data, but:
     # Lets the decoder jump over meta data.
     decoder.finishNestedTlvs(endOffset)
예제 #4
0
 def decode_name_component(self, decoder: TlvDecoder) -> bytearray:
     """
     Decode a name component
     :param decoder: Decoder
     :return: Value of name component
     """
     savePosition = decoder.getOffset()
     type = decoder.readVarNumber()
     decoder.seek(savePosition)
     return decoder.readBlobTlv(type).tobytes()
예제 #5
0
 def decode_data(self, input: bytearray) -> ([bytearray], bytearray):
     """
     Decodes a data packet
     :param input: Data packet in NDN-TLV wire format
     :return: Name and payload
     """
     decoder = TlvDecoder(input)
     decoder.readNestedTlvsStart(Tlv.Data)
     name = self.decode_name(decoder)
     self.decode_meta_info(decoder)
     payload = decoder.readBlobTlv(Tlv.Content).tobytes()
     return (name, payload)
예제 #6
0
 def decode_nack(self, input: bytearray) -> (Name, NackReason):
     """
     Decode NACK packet
     :param input: Data packet in NDN-TLV wire format
     :return: Name
     """
     # decode name
     name = self.decode_interest(input[13:])
     # decode nack reason
     decoder = TlvDecoder(input)
     decoder.readNestedTlvsStart(Tlv.LpPacket_LpPacket)
     decoder.readNestedTlvsStart(Tlv.LpPacket_Nack)
     try:
         decoder.readNestedTlvsStart(Tlv.LpPacket_NackReason)
         wire_reason = decoder.readVarNumber()
         reason = self.__nack_reason_enum[wire_reason]
     except ValueError:
         # happens when nack reason is not specified
         reason = NackReason.NOT_SET
     return (name, reason)
예제 #7
0
 def decode_name(self, decoder: TlvDecoder) -> Name:
     """
     Decode a name
     :param decoder: Decoder
     :return: Name
     """
     endOffset = decoder.readNestedTlvsStart(Tlv.Name)
     comps = []
     dgest = None
     while decoder.getOffset() < endOffset:
         if decoder.peekType(Tlv.ImplicitSha256DigestComponent, endOffset):
             dgest = decoder.readBlobTlv(Tlv.ImplicitSha256DigestComponent)
             dgest = dgest.tobytes()
         else:
             comps.append(self.decode_name_component(decoder))
     decoder.finishNestedTlvs(endOffset)
     return Name(suite='ndn2013').__add__(comps).set_digest(dgest)