Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions about the design of conn.WriteAny #69

Open
clytzelbj opened this issue Nov 20, 2023 · 0 comments
Open

Questions about the design of conn.WriteAny #69

clytzelbj opened this issue Nov 20, 2023 · 0 comments

Comments

@clytzelbj
Copy link

clytzelbj commented Nov 20, 2023

Hi, I have a question about the design concern about the conn.WriteAny function.

If I use the conn.WriteInt and pass a int parameter to it, it will write a integer response to the client.

// WriteInt64 writes a 64-bit signed integer to the client.
func (w *Writer) WriteInt64(num int64) {
    if w.err != nil {
         return
    }
    w.b = AppendInt(w.b, num)
}

However, if I use the conn.WriteAny and pass the same parameter to it, the function will write a string format of integer response which are quoted with a "" to the client.

func AppendAny(b []byte, v interface{}) []byte {
    switch v := v.(type) {
    case SimpleString:
         b = AppendString(b, string(v))
    case SimpleInt:
         b = AppendInt(b, int64(v))
    case SimpleError:
         b = AppendError(b, v.Error())
    case nil:
         b = AppendNull(b)
    case error:
         b = AppendError(b, prefixERRIfNeeded(v.Error()))
    case string:
         b = AppendBulkString(b, v)
    case []byte:
         b = AppendBulk(b, v)
    case bool:
         if v {
	    b = AppendBulkString(b, "1")
         } else {
	    b = AppendBulkString(b, "0")
         }
    case int:
         b = AppendBulkInt(b, int64(v))
    case int8:
         b = AppendBulkInt(b, int64(v))
    case int16:
         b = AppendBulkInt(b, int64(v))
    case int32:
         b = AppendBulkInt(b, int64(v))
    case int64:
         b = AppendBulkInt(b, int64(v))
    ......
    }
}

Can you give me any ideas about the design principles here?

@clytzelbj clytzelbj changed the title Questions about the design of writeAny Questions about the design of conn.WriteAny Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant