'Encode the value for the attribute.'

def _Encode(self, value):

    try:
        return buffer(value.SerializeToString())
    except AttributeError:
        if isinstance(value, (int, long)):
            return value
        else:
            return buffer(utils.SmartStr(value))
