

def encode_value(pieces, value):
    'Encode the value passed in and append it to the pieces list returning\n    the the size of the encoded value.\n\n    :param list pieces: Already encoded values\n    :param any value: The value to encode\n    :rtype: int\n\n    '
    if PY2:
        if isinstance(value, basestring):
            if isinstance(value, unicode_type):
                value = value.encode('utf-8')
            pieces.append(struct.pack('>cI', b'S', len(value)))
            pieces.append(value)
            return (5 + len(value))
    elif isinstance(value, str):
        value = value.encode('utf-8')
        pieces.append(struct.pack('>cI', b'S', len(value)))
        pieces.append(value)
        return (5 + len(value))
    if isinstance(value, bool):
        pieces.append(struct.pack('>cB', b't', int(value)))
        return 2
    if isinstance(value, long):
        pieces.append(struct.pack('>cq', b'l', value))
        return 9
    elif isinstance(value, int):
        pieces.append(struct.pack('>ci', b'I', value))
        return 5
    elif isinstance(value, decimal.Decimal):
        value = value.normalize()
        if (value.as_tuple().exponent < 0):
            decimals = (- value.as_tuple().exponent)
            raw = int((value * (decimal.Decimal(10) ** decimals)))
            pieces.append(struct.pack('>cBi', b'D', decimals, raw))
        else:
            pieces.append(struct.pack('>cBi', b'D', 0, int(value)))
        return 6
    elif isinstance(value, datetime):
        pieces.append(struct.pack('>cQ', b'T', calendar.timegm(value.utctimetuple())))
        return 9
    elif isinstance(value, dict):
        pieces.append(struct.pack('>c', b'F'))
        return (1 + encode_table(pieces, value))
    elif isinstance(value, list):
        p = []
        for v in value:
            encode_value(p, v)
        piece = b''.join(p)
        pieces.append(struct.pack('>cI', b'A', len(piece)))
        pieces.append(piece)
        return (5 + len(piece))
    elif (value is None):
        pieces.append(struct.pack('>c', b'V'))
        return 1
    else:
        raise exceptions.UnsupportedAMQPFieldException(pieces, value)

dataset/ETHPy150Open pika/pika/pika/data.py encode_value/original