Create response pdu.

        :param data: A list with 0's and/or 1's.
        :return: Byte array of at least 3 bytes.
341067
def create_response_pdu(self, data):
        
        log.debug('Create single bit response pdu {0}.'.format(data))
        bytes_ = [data[i:i + 8] for i in range(0, len(data), 8)]

        # Reduce each all bits per byte to a number. Byte
        # [0, 0, 0, 0, 0, 1, 1, 1] is intepreted as binary en is decimal 3.
        for index, byte in enumerate(bytes_):
            bytes_[index] = \
                reduce(lambda a, b: (a << 1) + b, list(reversed(byte)))

        log.debug('Reduced single bit data to {0}.'.format(bytes_))
        # The first 2 B's of the format encode the function code (1 byte) and
        # the length (1 byte) of the following byte series. Followed by # a B
        # for every byte in the series of bytes. 3 lead to the format '>BBB'
        # and 257 lead to the format '>BBBB'.
        fmt = '>BB' + self.format_character * len(bytes_)
        return struct.pack(fmt, self.function_code, len(bytes_), *bytes_)
818701
function encodeData (data) {
    // json encode data
    data = jsonStableStringify(data)
    // compress if compression in use
    if (this.compression) {
        data = snappy.compressSync(data).toString('base64')
    }
    // return encoded data
    return data
}
817155
def request_pdu(self):
        
        if None in [self.address, self.value]:
            # TODO Raise proper exception.
            raise Exception

        return struct.pack('>BHH', self.function_code, self.address,
                           self._value)
1021785
public void fromBytes(byte[] data) {
        if (data == null || data.length != 4) {
            throw new IllegalArgumentException("invalid header data. It can't be null and the length must be 4 byte.");
        }
        this.packetBodyLength = (data[0] & 0xFF) | ((data[1] & 0xFF) << 8) | ((data[2] & 0xFF) << 16);
        this.setPacketSequenceNumber(data[3]);
    }
136377
public static byte[] convert(int data) {
        long len = Integer.toUnsignedLong(data);
        byte[] b = new byte[Datagram.LEN_LIMIT];
        for (int i = 0; i < b.length; i++) {
            b[i] = (byte) (len >> ((b.length - i - 1) * 8));
        }
        return b;
    }
1208967
def loads(self, data):
        
        st = BytesIO(data)
        try:
            return self.load(st)
        finally:
            st.close()
125204
def to_str(data):
    
    if isinstance(data, bytes):
        return codecs.decode(data, TEXT_ENCODING)
    return data
197584
def format_rpc(data):
    

    address, rpc_id, args, resp, _status = data

    name = rpc_name(rpc_id)

    if isinstance(args, (bytes, bytearray)):
        arg_str = hexlify(args)
    else:
        arg_str = repr(args)

    if isinstance(resp, (bytes, bytearray)):
        resp_str = hexlify(resp)
    else:
        resp_str = repr(resp)

    #FIXME: Check and print status as well
    return "%s called on address %d, payload=%s, response=%s" % (name, address, arg_str, resp_str)
602384
def standardize_input_data(data):
    
    if type(data) == bytes:
        data = data.decode('utf-8')
    if type(data) == list:
        data = [
            el.decode('utf-8') if type(data) == bytes else el
            for el in data
        ]
    return data
1231153
def _set_data(self, data):
        """"""
        if type(data) == bytearray:
            self._data = data
        elif type(data) == str:
            if sys.version_info < (3,):
                self._data = bytearray(data)
            else:
                self._data = bytearray(data.encode('ISO-8859-1'))
        elif type(data) == list or type(data) == tuple:
            self._data = bytearray(data)
        elif sys.version_info >= (3,) and type(data) == bytes:
            self._data = bytearray(data)
        else:
            raise Exception('Data must be bytearray, string, list or tuple,'
                            ' not {}'.format(type(data)))
124617
function buildResponse(data) {
    var response = {};
    response.totalItems = data.length;
    response.itemsPerPage = itemsPerPage;
    response.totalPages = itemsPerPage === null ? 1 : Math.ceil(data.length / itemsPerPage);
    response.currentPage = itemsPerPage === null ? 1 : currentPage;
    response.data = itemsPerPage === null ? data : data.slice(itemsPerPage * (currentPage - 1), itemsPerPage);

    return response;
}
190547
def encode_data(data):
    '''
    
    '''
    if isinstance(data, (six.string_types, bytes)):
        return encode_string(data)
    elif isinstance(data, (six.integer_types, bool, float)):
        return data
    elif data is None:
        return data
    elif isinstance(data, list):
        return [encode_data(x) for x in data]
    elif isinstance(data, dict):
        return {k: encode_data(v) for k, v in data.items()}
    else:
        raise ValueError('Cannot encode data of type %s' % type(data))
619468
def __point_data_to_bytes(self, data, mime=None):  # pylint: disable=too-many-branches
        """"""
        if mime is None:
            if self.__auto_encode_decode:
                if isinstance(data, bytes):
                    return None, data
                elif isinstance(data, dict):
                    # check top level dictionary keys
                    if all(isinstance(key, unicode_type) for key in data):
                        return 'idx/1', ubjdumpb(data)  # application/ubjson
                    else:
                        raise ValueError('At least one key in dict not real (unicode) string')
                elif isinstance(data, unicode_type):
                    return 'idx/2', data.encode('utf8')  # text/plain; charset=utf8
                else:
                    raise ValueError('cannot auto-encode data of type %s' % type(data))
            elif isinstance(data, bytes):
                return None, data
            else:
                raise ValueError('No mime type specified and not bytes object (auto-encode disabled)')
        elif valid_mimetype(mime):
            if isinstance(data, bytes):
                return mime, data
            else:
                raise ValueError('mime specified but data not bytes object')
        else:
            raise ValueError('invalid mime type %s' % mime)
321286
def create(self, data):
        
        data = values.of({'Data': serialize.object(data), })

        payload = self._version.create(
            'POST',
            self._uri,
            data=data,
        )

        return StreamMessageInstance(
            self._version,
            payload,
            service_sid=self._solution['service_sid'],
            stream_sid=self._solution['stream_sid'],
        )
368075
def cdata (self, data):
        
        data = data.encode(self.encoding, "ignore")
        self.fd.write("<![CDATA[%s]]>" % data)
503533
def create_response(
        self, data: dict = None, response: requests.Response = None, errors: list = None
    ) -> Response:
        
        status = FAILURE_STATUS if errors else SUCCESS_STATUS
        return Response(
            status=status,
            provider=self.name,
            data=data,
            response=response,
            errors=errors,
        )
430952
public static byte[] SHA256(byte[] data) {
        Digest sha256 = createSHA256();
        sha256.update(data, 0, data.length);
        byte[] res = new byte[32];
        sha256.doFinal(res, 0);
        return res;
    }