Static method for encoding values