mirror of
https://github.com/jackc/pgx.git
synced 2025-05-25 17:00:21 +00:00
Support writing to postgres 'text' values from both strings as well as
[]byte. If the input is already []byte, this will avoid having the caller convert to string and then back to []byte. Potentially saves some allocs.
This commit is contained in:
parent
3beff78461
commit
161ec8db6d
13
values.go
13
values.go
@ -986,14 +986,17 @@ func decodeText(vr *ValueReader) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func encodeText(w *WriteBuf, value interface{}) error {
|
func encodeText(w *WriteBuf, value interface{}) error {
|
||||||
s, ok := value.(string)
|
switch t := value.(type) {
|
||||||
if !ok {
|
case string:
|
||||||
|
w.WriteInt32(int32(len(t)))
|
||||||
|
w.WriteBytes([]byte(t))
|
||||||
|
case []byte:
|
||||||
|
w.WriteInt32(int32(len(t)))
|
||||||
|
w.WriteBytes(t)
|
||||||
|
default:
|
||||||
return fmt.Errorf("Expected string, received %T", value)
|
return fmt.Errorf("Expected string, received %T", value)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.WriteInt32(int32(len(s)))
|
|
||||||
w.WriteBytes([]byte(s))
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user