Unpack given Motorola S-Record record into variables.
338999
def unpack_srec(record):
    

    # Minimum STSSCC, where T is type, SS is size and CC is crc.
    if len(record) < 6:
        raise Error("record '{}' too short".format(record))

    if record[0] != 'S':
        raise Error(
            "record '{}' not starting with an 'S'".format(record))

    size = int(record[2:4], 16)
    type_ = record[1:2]

    if type_ in '0159':
        width = 4
    elif type_ in '268':
        width = 6
    elif type_ in '37':
        width = 8
    else:
        raise Error(
            "expected record type 0..3 or 5..9, but got '{}'".format(type_))

    data_offset = (4 + width)
    crc_offset = (4 + 2 * size - 2)

    address = int(record[4:data_offset], 16)
    data = binascii.unhexlify(record[data_offset:crc_offset])
    actual_crc = int(record[crc_offset:], 16)
    expected_crc = crc_srec(record[2:crc_offset])

    if actual_crc != expected_crc:
        raise Error(
            "expected crc '{:02X}' in record {}, but got '{:02X}'".format(
                expected_crc,
                record,
                actual_crc))

    return (type_, address, size - 1 - width // 2, data)
237846
def _fromfile(self, parent):
        """"""
        fd = parent._fd
        byte_order = parent.byte_order

        self._offset = fd.tell()
        self.value_offset = self._offset + parent.offset_size + 4

        fmt, size = {4: ('HHI4s', 12), 8: ('HHQ8s', 20)}[parent.offset_size]
        data = fd.read(size)
        code, dtype = struct.unpack(byte_order + fmt[:2], data[:4])
        count, value = struct.unpack(byte_order + fmt[2:], data[4:])

        if code in TIFF_TAGS:
            name = TIFF_TAGS[code][0]
        elif code in CUSTOM_TAGS:
            name = CUSTOM_TAGS[code][0]
        else:
            name = str(code)

        try:
            dtype = TIFF_DATA_TYPES[dtype]
        except KeyError:
            raise ValueError("unknown TIFF tag data type %i" % dtype)

        fmt = '%s%i%s' % (byte_order, count*int(dtype[0]), dtype[1])
        size = struct.calcsize(fmt)
        if size > parent.offset_size or code in CUSTOM_TAGS:
            pos = fd.tell()
            tof = {4: 'I', 8: 'Q'}[parent.offset_size]
            self.value_offset = struct.unpack(byte_order+tof, value)[0]
            fd.seek(self.value_offset)
            if code in CUSTOM_TAGS:
                readfunc = CUSTOM_TAGS[code][1]
                value = readfunc(fd, byte_order, dtype, count)
                fd.seek(0, 2)  # bug in numpy/Python 3.x ?
                if isinstance(value, dict):  # numpy.core.records.record
                    value = Record(value)
            elif code in TIFF_TAGS or dtype[-1] == 's':
                value = struct.unpack(fmt, fd.read(size))
            else:
                value = read_numpy(fd, byte_order, dtype, count)
                fd.seek(0, 2)  # bug in numpy/Python 3.x ?
            fd.seek(pos)
        else:
            value = struct.unpack(fmt, value[:size])

        if not code in CUSTOM_TAGS:
            if len(value) == 1:
                value = value[0]

        if dtype.endswith('s'):
            value = stripnull(value)

        self.code = code
        self.name = name
        self.dtype = dtype
        self.count = count
        self.value = value
462205
def _unpack_from(buf, format_s, count=None, little_endian=True):
    """"""

    if count is not None:
        assert count > 0
        format_s = '%i%s' % (count, format_s)

    if little_endian is True:
        format_s = '<' + format_s
    else:
        format_s = '>' + format_s

    size = struct.calcsize(format_s)
    res = struct.unpack_from(format_s, buf.read(size))

    if count is not None:
        return res
    else:
        return res[0]
935966
def unpack(cls, msg):
        """"""
        # PYTHON-945: ignore starting_from field.
        flags, cursor_id, _, number_returned = cls.UNPACK_FROM(msg)

        # Convert Python 3 memoryview to bytes. Note we should call
        # memoryview.tobytes() if we start using memoryview in Python 2.7.
        documents = bytes(msg[20:])
        return cls(flags, cursor_id, number_returned, documents)
650948
def wet_records(wet_filepath):
  """"""
  if wet_filepath.endswith('.gz'):
    fopen = gzip.open
  else:
    fopen = tf.gfile.GFile

  with fopen(wet_filepath) as f:
    for record in wet_records_from_file_obj(f):
      yield record
716548
def _record_to_struct(cur_rec, records):
    
    def to_camel_case(x):
        def uppercase_word(w):
            return w[0].upper() + w[1:]
        return "".join(uppercase_word(w) for w in x.split("_"))
    struct_name = to_camel_case(cur_rec["name"].split("/")[-1])
    if struct_name not in records:
        records[struct_name] = collections.OrderedDict()
        for field in cur_rec["fields"]:
            field_type, records = _to_variable_type(field["type"], records)
            records[struct_name][field["name"].split("/")[-1]] = field_type
    return struct_name, records
896505
async function decodeData (record) {
    // convert null values to undefined
    for (const key of Object.keys(record)) {
        if (record[key] === null) {
            record[key] = undefined
        }
    }
    // get data column to decode data
    var dataColumn = this.columnName('data')
    // skip if no data column
    if (!defined(dataColumn) || !defined(record[dataColumn])) {
        return
    }
    // decompress if compresion in use
    if (this.compression) {
        // decompress data
        record[dataColumn] = await snappyUncompress(Buffer.from(record[dataColumn], 'base64'), {asBuffer: false})
    }
    // decode data
    record[dataColumn] = JSON.parse(record[dataColumn])
}
149493
def _convert(cls, record):
        
        if not record:
            return {}

        converted_dict = {}
        for field in cls.conversion:
            key = field[0]
            if len(field) >= 2 and field[1]:
                converted_key = field[1]
            else:
                converted_key = key
            if len(field) >= 3 and field[2]:
                conversion_method = field[2]
            else:
                conversion_method = cls.default_conversion_method
            if len(field) >= 4:
                converter = field[3]
            else:
                converter = None
            try:
                value = conversion_method(record[key])
            except KeyError:
                continue
            if converter:
                value = converter._convert_internal(value)
            if converted_key is APPEND:
                if isinstance(value, list):
                    for v in value:
                        converted_dict.update(v)
                else:
                    converted_dict.update(value)
            else:
                converted_dict[converted_key] = value
        return converted_dict
444362
def _record_from_json(value, field):
    """"""
    if _not_null(value, field):
        record = {}
        record_iter = zip(field.fields, value["f"])
        for subfield, cell in record_iter:
            converter = _CELLDATA_FROM_JSON[subfield.field_type]
            if subfield.mode == "REPEATED":
                value = [converter(item["v"], subfield) for item in cell["v"]]
            else:
                value = converter(cell["v"], subfield)
            record[subfield.name] = value
        return record
1139761
def dictionize(fields: Sequence, records: Sequence) -> Generator:
    """"""

    return (dict(zip(fields, rec)) for rec in records)
1128983
def preprocess_record(self, pid, record, links_factory=None, **kwargs):
        """"""
        links_factory = links_factory or (lambda x, record=None, **k: dict())
        metadata = copy.deepcopy(record.replace_refs()) if self.replace_refs \
            else record.dumps()
        return dict(
            pid=pid,
            metadata=metadata,
            links=links_factory(pid, record=record, **kwargs),
            revision=record.revision_id,
            created=(pytz.utc.localize(record.created).isoformat()
                     if record.created else None),
            updated=(pytz.utc.localize(record.updated).isoformat()
                     if record.updated else None),
        )
861883
def parse(self, rrstr):
        # type: (bytes) -> None
        '''
        
        '''
        if self._initialized:
            raise pycdlibexception.PyCdlibInternalError('ER record already initialized!')

        (su_len, su_entry_version_unused, len_id, len_des, len_src,
         self.ext_ver) = struct.unpack_from('=BBBBBB', rrstr[:8], 2)

        # We assume that the caller has already checked the su_entry_version,
        # so we don't bother.

        # Ensure that the length isn't crazy
        if su_len > len(rrstr):
            raise pycdlibexception.PyCdlibInvalidISO('Length of ER record much too long')

        # Also ensure that the combination of len_id, len_des, and len_src
        # doesn't overrun su_len; because of the check above, this means it
        # can't overrun len(rrstr) either
        total_length = len_id + len_des + len_src
        if total_length > su_len:
            raise pycdlibexception.PyCdlibInvalidISO('Combined length of ER ID, des, and src longer than record')

        fmtstr = '=%ds%ds%ds' % (len_id, len_des, len_src)
        (self.ext_id, self.ext_des, self.ext_src) = struct.unpack_from(fmtstr, rrstr, 8)

        self._initialized = True
429654
def _convert_internal(cls, record):
        
        if isinstance(record, list):
            return [cls._convert(r) for r in record]
        else:
            return cls._convert(record)
941081
def unpack_log_data(self, log_data, timestamp):
        """"""
        ret_data = {}
        data_index = 0
        for var in self.variables:
            size = LogTocElement.get_size_from_id(var.fetch_as)
            name = var.name
            unpackstring = LogTocElement.get_unpack_string_from_id(
                var.fetch_as)
            value = struct.unpack(
                unpackstring, log_data[data_index:data_index + size])[0]
            data_index += size
            ret_data[name] = value
        self.data_received_cb.call(timestamp, ret_data, self)
742317
def Unpack(self, msg):
    """"""
    descriptor = msg.DESCRIPTOR
    if not self.Is(descriptor):
      return False
    msg.ParseFromString(self.value)
    return True
603529
def copyRecord(  rid, numCopies = 1, dbid = @dbid )
      clearFieldValuePairList
      getRecordInfo( dbid, rid ) { |field|
         if field and field.elements[ "value" ] and field.elements[ "value" ].has_text?
            if field.elements[ "fid" ].text.to_i > 5 #skip built-in fields
               addFieldValuePair( field.elements[ "name" ].text, nil, nil, field.elements[ "value" ].text )
            end
         end
      }
      newRecordIDs = []
      if @fvlist and @fvlist.length > 0
         numCopies.times {
           addRecord( dbid, @fvlist )
           newRecordIDs << @rid if @rid and @update_id
         }
      end
      if block_given?
         newRecordIDs.each{ |newRecordID| yield newRecordID }
      else
         newRecordIDs
      end
   end
1159478
def deserialize_records(records):
    
    native_records = []
    for record in records:
        parsed = json.loads(record['body'])

        # Is this a DynamoDB stream event?
        if isinstance(parsed, str):
            native_records.append(json.loads(parsed))

        # Is this a subscription message from SNS? If so, skip it:
        elif parsed.get('Type') == 'SubscriptionConfirmation':
            continue

        # Is this from SNS (cross-region request -- SNS messages wrapped in SQS message) -- or an SNS proxied message?
        elif parsed.get('Message'):
            native_records.append(json.loads(parsed['Message']))

        else:
            native_records.append(parsed)

    return native_records