'Encode the value for the attribute.'

def Encode(self, attribute, value):

    required_type = self._attribute_types.get(attribute, 'bytes')
    if (required_type in ('integer', 'unsigned_integer')):
        return structs.VarintEncode(int(value))
    elif hasattr(value, 'SerializeToString'):
        return value.SerializeToString()
    else:
        return utils.SmartStr(value)
