Source File
bytea.go
Belonging Package
github.com/jackc/pgtype
package pgtype
import (
)
type Bytea struct {
Bytes []byte
Status Status
}
func ( *Bytea) ( interface{}) error {
if == nil {
* = Bytea{Status: Null}
return nil
}
if , := .(interface{ () interface{} }); {
:= .()
if != {
return .()
}
}
switch value := .(type) {
case []byte:
if != nil {
* = Bytea{Bytes: , Status: Present}
} else {
* = Bytea{Status: Null}
}
default:
if , := underlyingBytesType(); {
return .()
}
return fmt.Errorf("cannot convert %v to Bytea", )
}
return nil
}
func ( Bytea) () interface{} {
switch .Status {
case Present:
return .Bytes
case Null:
return nil
default:
return .Status
}
}
func ( *Bytea) ( interface{}) error {
switch .Status {
case Present:
switch v := .(type) {
case *[]byte:
:= make([]byte, len(.Bytes))
copy(, .Bytes)
* =
return nil
default:
if , := GetAssignToDstType(); {
return .()
}
return fmt.Errorf("unable to assign to %T", )
}
case Null:
return NullAssignTo()
}
return fmt.Errorf("cannot decode %#v into %T", , )
}
func ( *Bytea) ( *ConnInfo, []byte) error {
if == nil {
* = Bytea{Status: Null}
return nil
}
if len() < 2 || [0] != '\\' || [1] != 'x' {
return fmt.Errorf("invalid hex format")
}
:= make([]byte, (len()-2)/2)
, := hex.Decode(, [2:])
if != nil {
return
}
* = Bytea{Bytes: , Status: Present}
return nil
}
func ( *Bytea) ( *ConnInfo, []byte) error {
if == nil {
* = Bytea{Status: Null}
return nil
}
* = Bytea{Bytes: , Status: Present}
return nil
}
func ( Bytea) ( *ConnInfo, []byte) ([]byte, error) {
switch .Status {
case Null:
return nil, nil
case Undefined:
return nil, errUndefined
}
= append(, `\x`...)
= append(, hex.EncodeToString(.Bytes)...)
return , nil
}
func ( Bytea) ( *ConnInfo, []byte) ([]byte, error) {
switch .Status {
case Null:
return nil, nil
case Undefined:
return nil, errUndefined
}
return append(, .Bytes...), nil
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |