Implement encode method in Attribute