package pgproto3
import (
)
type SASLInitialResponse struct {
AuthMechanism string
Data []byte
}
func (*SASLInitialResponse) () {}
func ( *SASLInitialResponse) ( []byte) error {
* = SASLInitialResponse{}
:= 0
:= bytes.IndexByte(, 0)
if < 0 {
return errors.New("invalid SASLInitialResponse")
}
.AuthMechanism = string([:])
= + 1
if len([:]) < 4 {
return errors.New("invalid SASLInitialResponse")
}
+= 4
.Data = [:]
return nil
}
func ( *SASLInitialResponse) ( []byte) ([]byte, error) {
, := beginMessage(, 'p')
= append(, []byte(.AuthMechanism)...)
= append(, 0)
= pgio.AppendInt32(, int32(len(.Data)))
= append(, .Data...)
return finishMessage(, )
}
func ( SASLInitialResponse) () ([]byte, error) {
return json.Marshal(struct {
string
string
string
}{
: "SASLInitialResponse",
: .AuthMechanism,
: string(.Data),
})
}
func ( *SASLInitialResponse) ( []byte) error {
if string() == "null" {
return nil
}
var struct {
string
string
}
if := json.Unmarshal(, &); != nil {
return
}
.AuthMechanism = .
if . != "" {
, := hex.DecodeString(.)
if != nil {
return
}
.Data =
}
return nil
}