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()
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)
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)