def encode_string_to_length(string, target_length, pad = :null)
      if pad == :spaces
        template = "A#{target_length}"
      elsif pad == :null
        template = "a#{target_length}"
      else
        raise StandardError, "Could not identify padding type #{pad}"
      end
      
      length = string.length
      if length < target_length
        return [string].pack(template)
      elsif length == target_length
        return [string].pack(@str)
      else
        raise "The specified string is longer than the allowed maximum length (String: #{string}, Target length: #{target_length})."
      end
    end
def encode_string_to_length(string, target_length, pad = :null)
      if pad == :spaces
        template = "A#{target_length}"
      elsif pad == :null
        template = "a#{target_length}"
      else
        raise StandardError, "Could not identify padding type #{pad}"
      end
      
      length = string.length
      if length < target_length
        return [string].pack(template)
      elsif length == target_length
        return [string].pack(@str)
      else
        raise "The specified string is longer than the allowed maximum length (String: #{string}, Target length: #{target_length})."
      end
    end
Appends a string with trailling spaces to achieve a target length, and encodes it to a binary string.
 Returns the binary string.  Raises an error if pad option is different than :null or :spaces

 === Parameters

 * <tt>string</tt> -- A string to be processed.
 * <tt>target_length</tt> -- Fixnum. The target length of the string that is created.
 * <tt>pad</tt> -- Type of desired padding, either :null or :spaces