errors now []byte

master
Jordan Orelli 11 years ago
parent e4314bce1b
commit 1841de74e7

@ -110,7 +110,7 @@ func main() {
response := <-responses response := <-responses
if response.ok() { if response.ok() {
switch r := response.val().(type) { switch r := response.val().(type) {
case Error: case ErrorVal:
if options.verbose { if options.verbose {
fmt.Fprintf(os.Stderr, "%q -> %q\n", request, response.val()) fmt.Fprintf(os.Stderr, "%q -> %q\n", request, response.val())
} else { } else {

@ -106,8 +106,7 @@ func readValue(r io.Reader) (value, error) {
case start_string: case start_string:
return StringVal(line), nil return StringVal(line), nil
case start_error: case start_error:
line = line[:len(line)-2] return ErrorVal(line), nil
return Error(line[1:]), nil
case start_integer: case start_integer:
line = line[:len(line)-2] line = line[:len(line)-2]
return Integer(line[1:]), nil return Integer(line[1:]), nil
@ -141,13 +140,23 @@ func String(s string) value {
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
type Error string type ErrorVal []byte
func (e Error) Write(w io.Writer) (int, error) { func (e ErrorVal) Write(w io.Writer) (int, error) {
w.Write([]byte{'-'}) // w.Write([]byte{'-'})
w.Write([]byte(e)) // w.Write([]byte(e))
w.Write([]byte{'\r', '\n'}) // w.Write([]byte{'\r', '\n'})
return 0, nil // return 0, nil
return w.Write(e)
}
func Error(s string) value {
b := make(ErrorVal, len(s)+3)
b[0] = '-'
copy(b[1:], []byte(s))
b[len(b)-2] = '\r'
b[len(b)-1] = '\n'
return b
} }
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------

Loading…
Cancel
Save