def decode_array(decoder, subtype, shareable_index=None): # Major tag 4 items = [] decoder.set_shareable(shareable_index, items) length = decode_uint(decoder, subtype, allow_infinite=True) if length is None: # Indefinite length while True: value = decoder.decode() if value is break_marker: break else: items.append(value) else: for _ in xrange(length): item = decoder.decode() items.append(item) return items
def decode_array(self, subtype, fp, shareable_index=None): # Major tag 4 items = [] if shareable_index is not None: self.shareables[shareable_index] = items length = self.decode_uint(subtype, fp, allow_infinite=True) if length is None: # Indefinite length while True: value = self.decode(fp) if value is break_marker: break else: items.append(value) else: for _ in xrange(length): item = self.decode(fp) items.append(item) return items
def decode_map(self, subtype, fp, shareable_index=None): # Major tag 5 dictionary = {} if shareable_index is not None: self.shareables[shareable_index] = dictionary length = self.decode_uint(subtype, fp, allow_infinite=True) if length is None: # Indefinite length while True: key = self.decode(fp) if key is break_marker: break else: value = self.decode(fp) dictionary[key] = value else: for _ in xrange(length): key = self.decode(fp) value = self.decode(fp) dictionary[key] = value return dictionary
def decode_map(decoder, subtype, shareable_index=None): # Major tag 5 dictionary = {} decoder.set_shareable(shareable_index, dictionary) length = decode_uint(decoder, subtype, allow_infinite=True) if length is None: # Indefinite length while True: key = decoder.decode() if key is break_marker: break else: value = decoder.decode() dictionary[key] = value else: for _ in xrange(length): key = decoder.decode() value = decoder.decode() dictionary[key] = value if decoder.object_hook: return decoder.object_hook(decoder, dictionary) else: return dictionary