'Encode the value into a Binary BSON object.
The data store only supports the following values:
-Integer
-Unicode
-Bytes (python string)
We preserve integers and unicode objects, but serialize anything else.
Args:
value: The value to be encoded.
Returns:
An encoded value.'

def _Encode(self, value):

    if isinstance(value, (basestring, int, float)):
        return value
    try:
        return value.SerializeToDataStore()
    except AttributeError:
        try:
            return value.SerializeToString()
        except AttributeError:
            return utils.SmartStr(value)
