package pgtype
import (
)
type QCharCodec struct{}
func (QCharCodec) ( int16) bool {
return == TextFormatCode || == BinaryFormatCode
}
func (QCharCodec) () int16 {
return BinaryFormatCode
}
func (QCharCodec) ( *Map, uint32, int16, any) EncodePlan {
switch {
case TextFormatCode, BinaryFormatCode:
switch .(type) {
case byte:
return encodePlanQcharCodecByte{}
case rune:
return encodePlanQcharCodecRune{}
}
}
return nil
}
type encodePlanQcharCodecByte struct{}
func (encodePlanQcharCodecByte) ( any, []byte) ( []byte, error) {
:= .(byte)
= append(, )
return , nil
}
type encodePlanQcharCodecRune struct{}
func (encodePlanQcharCodecRune) ( any, []byte) ( []byte, error) {
:= .(rune)
if > math.MaxUint8 {
return nil, fmt.Errorf(`%v cannot be encoded to "char"`, )
}
:= byte()
= append(, )
return , nil
}
func (QCharCodec) ( *Map, uint32, int16, any) ScanPlan {
switch {
case TextFormatCode, BinaryFormatCode:
switch .(type) {
case *byte:
return scanPlanQcharCodecByte{}
case *rune:
return scanPlanQcharCodecRune{}
}
}
return nil
}
type scanPlanQcharCodecByte struct{}
func (scanPlanQcharCodecByte) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() > 1 {
return fmt.Errorf(`invalid length for "char": %v`, len())
}
:= .(*byte)
if len() == 0 {
* = 0
} else {
* = [0]
}
return nil
}
type scanPlanQcharCodecRune struct{}
func (scanPlanQcharCodecRune) ( []byte, any) error {
if == nil {
return fmt.Errorf("cannot scan NULL into %T", )
}
if len() > 1 {
return fmt.Errorf(`invalid length for "char": %v`, len())
}
:= .(*rune)
if len() == 0 {
* = 0
} else {
* = rune([0])
}
return nil
}
func ( QCharCodec) ( *Map, uint32, int16, []byte) (driver.Value, error) {
if == nil {
return nil, nil
}
var rune
:= codecScan(, , , , , &)
if != nil {
return nil,
}
return string(), nil
}
func ( QCharCodec) ( *Map, uint32, int16, []byte) (any, error) {
if == nil {
return nil, nil
}
var rune
:= codecScan(, , , , , &)
if != nil {
return nil,
}
return , nil
}