package pgtype
import (
)
type XMLCodec struct {
Marshal func(v any) ([]byte, error)
Unmarshal func(data []byte, v any) error
}
func (*XMLCodec) ( int16) bool {
return == TextFormatCode || == BinaryFormatCode
}
func (*XMLCodec) () int16 {
return TextFormatCode
}
func ( *XMLCodec) ( *Map, uint32, int16, any) EncodePlan {
switch .(type) {
case string:
return encodePlanXMLCodecEitherFormatString{}
case []byte:
return encodePlanXMLCodecEitherFormatByteSlice{}
case driver.Valuer:
return &encodePlanDriverValuer{m: , oid: , formatCode: }
case xml.Marshaler:
return &encodePlanXMLCodecEitherFormatMarshal{
marshal: .Marshal,
}
}
for , := range []TryWrapEncodePlanFunc{
TryWrapDerefPointerEncodePlan,
TryWrapFindUnderlyingTypeEncodePlan,
} {
if , , := (); {
if := .(, , , ); != nil {
.SetNext()
return
}
}
}
return &encodePlanXMLCodecEitherFormatMarshal{
marshal: .Marshal,
}
}
type encodePlanXMLCodecEitherFormatString struct{}
func (encodePlanXMLCodecEitherFormatString) ( any, []byte) ( []byte, error) {
:= .(string)
= append(, ...)
return , nil
}
type encodePlanXMLCodecEitherFormatByteSlice struct{}
func (encodePlanXMLCodecEitherFormatByteSlice) ( any, []byte) ( []byte, error) {
:= .([]byte)
if == nil {
return nil, nil
}
= append(, ...)
return , nil
}
type encodePlanXMLCodecEitherFormatMarshal struct {
marshal func(v any) ([]byte, error)
}
func ( *encodePlanXMLCodecEitherFormatMarshal) ( any, []byte) ( []byte, error) {
, := .marshal()
if != nil {
return nil,
}
= append(, ...)
return , nil
}
func ( *XMLCodec) ( *Map, uint32, int16, any) ScanPlan {
switch .(type) {
case *string:
return scanPlanAnyToString{}
case **string:
if , , := TryPointerPointerScanPlan(); {
if := .planScan(, , , 0); != nil {
if , := .(*scanPlanFail); ! {
.SetNext()
return
}
}
}
case *[]byte:
return scanPlanXMLToByteSlice{}
case BytesScanner:
return scanPlanBinaryBytesToBytesScanner{}
case sql.Scanner:
return &scanPlanSQLScanner{formatCode: }
}
return &scanPlanXMLToXMLUnmarshal{
unmarshal: .Unmarshal,
}
}
type scanPlanXMLToByteSlice struct{}
func (scanPlanXMLToByteSlice) ( []byte, any) error {
:= .(*[]byte)
if == nil {
* = nil
return nil
}
* = make([]byte, len())
copy(*, )
return nil
}
type scanPlanXMLToXMLUnmarshal struct {
unmarshal func(data []byte, v any) error
}
func ( *scanPlanXMLToXMLUnmarshal) ( []byte, any) error {
if == nil {
:= reflect.ValueOf()
if .Kind() == reflect.Ptr {
:= .Elem()
switch .Kind() {
case reflect.Ptr, reflect.Slice, reflect.Map, reflect.Interface, reflect.Struct:
.Set(reflect.Zero(.Type()))
return nil
}
}
return fmt.Errorf("cannot scan NULL into %T", )
}
:= reflect.ValueOf().Elem()
.Set(reflect.Zero(.Type()))
return .unmarshal(, )
}
func ( *XMLCodec) ( *Map, uint32, int16, []byte) (driver.Value, error) {
if == nil {
return nil, nil
}
:= make([]byte, len())
copy(, )
return , nil
}
func ( *XMLCodec) ( *Map, uint32, int16, []byte) (any, error) {
if == nil {
return nil, nil
}
var any
:= .Unmarshal(, &)
return ,
}