package pgproto3
import (
)
type FunctionCallResponse struct {
Result []byte
}
func (*FunctionCallResponse) () {}
func ( *FunctionCallResponse) ( []byte) error {
if len() < 4 {
return &invalidMessageFormatErr{messageType: "FunctionCallResponse"}
}
:= 0
:= int(int32(binary.BigEndian.Uint32([:])))
+= 4
if == -1 {
.Result = nil
return nil
}
if < 0 || len([:]) != {
return &invalidMessageFormatErr{messageType: "FunctionCallResponse"}
}
.Result = [:]
return nil
}
func ( *FunctionCallResponse) ( []byte) ([]byte, error) {
, := beginMessage(, 'V')
if .Result == nil {
= pgio.AppendInt32(, -1)
} else {
= pgio.AppendInt32(, int32(len(.Result)))
= append(, .Result...)
}
return finishMessage(, )
}
func ( FunctionCallResponse) () ([]byte, error) {
var map[string]string
var bool
for , := range .Result {
if < 32 {
= true
break
}
}
if {
= map[string]string{"binary": hex.EncodeToString(.Result)}
} else {
= map[string]string{"text": string(.Result)}
}
return json.Marshal(struct {
string
map[string]string
}{
: "FunctionCallResponse",
: ,
})
}
func ( *FunctionCallResponse) ( []byte) error {
if string() == "null" {
return nil
}
var struct {
map[string]string
}
:= json.Unmarshal(, &)
if != nil {
return
}
.Result, = getValueFromJSON(.)
return
}