package pgproto3
import (
)
type ErrorResponse struct {
Severity string
SeverityUnlocalized string
Code string
Message string
Detail string
Hint string
Position int32
InternalPosition int32
InternalQuery string
Where string
SchemaName string
TableName string
ColumnName string
DataTypeName string
ConstraintName string
File string
Line int32
Routine string
UnknownFields map[byte]string
}
func (*ErrorResponse) () {}
func ( *ErrorResponse) ( []byte) error {
* = ErrorResponse{}
:= bytes.NewBuffer()
for {
, := .ReadByte()
if != nil {
return
}
if == 0 {
break
}
, := .ReadBytes(0)
if != nil {
return
}
:= string([:len()-1])
switch {
case 'S':
.Severity =
case 'V':
.SeverityUnlocalized =
case 'C':
.Code =
case 'M':
.Message =
case 'D':
.Detail =
case 'H':
.Hint =
case 'P':
:=
, := strconv.ParseInt(, 10, 32)
.Position = int32()
case 'p':
:=
, := strconv.ParseInt(, 10, 32)
.InternalPosition = int32()
case 'q':
.InternalQuery =
case 'W':
.Where =
case 's':
.SchemaName =
case 't':
.TableName =
case 'c':
.ColumnName =
case 'd':
.DataTypeName =
case 'n':
.ConstraintName =
case 'F':
.File =
case 'L':
:=
, := strconv.ParseInt(, 10, 32)
.Line = int32()
case 'R':
.Routine =
default:
if .UnknownFields == nil {
.UnknownFields = make(map[byte]string)
}
.UnknownFields[] =
}
}
return nil
}
func ( *ErrorResponse) ( []byte) ([]byte, error) {
, := beginMessage(, 'E')
= .appendFields()
return finishMessage(, )
}
func ( *ErrorResponse) ( []byte) []byte {
if .Severity != "" {
= append(, 'S')
= append(, .Severity...)
= append(, 0)
}
if .SeverityUnlocalized != "" {
= append(, 'V')
= append(, .SeverityUnlocalized...)
= append(, 0)
}
if .Code != "" {
= append(, 'C')
= append(, .Code...)
= append(, 0)
}
if .Message != "" {
= append(, 'M')
= append(, .Message...)
= append(, 0)
}
if .Detail != "" {
= append(, 'D')
= append(, .Detail...)
= append(, 0)
}
if .Hint != "" {
= append(, 'H')
= append(, .Hint...)
= append(, 0)
}
if .Position != 0 {
= append(, 'P')
= append(, strconv.Itoa(int(.Position))...)
= append(, 0)
}
if .InternalPosition != 0 {
= append(, 'p')
= append(, strconv.Itoa(int(.InternalPosition))...)
= append(, 0)
}
if .InternalQuery != "" {
= append(, 'q')
= append(, .InternalQuery...)
= append(, 0)
}
if .Where != "" {
= append(, 'W')
= append(, .Where...)
= append(, 0)
}
if .SchemaName != "" {
= append(, 's')
= append(, .SchemaName...)
= append(, 0)
}
if .TableName != "" {
= append(, 't')
= append(, .TableName...)
= append(, 0)
}
if .ColumnName != "" {
= append(, 'c')
= append(, .ColumnName...)
= append(, 0)
}
if .DataTypeName != "" {
= append(, 'd')
= append(, .DataTypeName...)
= append(, 0)
}
if .ConstraintName != "" {
= append(, 'n')
= append(, .ConstraintName...)
= append(, 0)
}
if .File != "" {
= append(, 'F')
= append(, .File...)
= append(, 0)
}
if .Line != 0 {
= append(, 'L')
= append(, strconv.Itoa(int(.Line))...)
= append(, 0)
}
if .Routine != "" {
= append(, 'R')
= append(, .Routine...)
= append(, 0)
}
for , := range .UnknownFields {
= append(, )
= append(, ...)
= append(, 0)
}
= append(, 0)
return
}
func ( ErrorResponse) () ([]byte, error) {
return json.Marshal(struct {
string
string
string
string
string
string
string
int32
int32
string
string
string
string
string
string
string
string
int32
string
map[byte]string
}{
: "ErrorResponse",
: .Severity,
: .SeverityUnlocalized,
: .Code,
: .Message,
: .Detail,
: .Hint,
: .Position,
: .InternalPosition,
: .InternalQuery,
: .Where,
: .SchemaName,
: .TableName,
: .ColumnName,
: .DataTypeName,
: .ConstraintName,
: .File,
: .Line,
: .Routine,
: .UnknownFields,
})
}
func ( *ErrorResponse) ( []byte) error {
if string() == "null" {
return nil
}
var struct {
string
string
string
string
string
string
string
int32
int32
string
string
string
string
string
string
string
string
int32
string
map[byte]string
}
if := json.Unmarshal(, &); != nil {
return
}
.Severity = .
.SeverityUnlocalized = .
.Code = .
.Message = .
.Detail = .
.Hint = .
.Position = .
.InternalPosition = .
.InternalQuery = .
.Where = .
.SchemaName = .
.TableName = .
.ColumnName = .
.DataTypeName = .
.ConstraintName = .
.File = .
.Line = .
.Routine = .
.UnknownFields = .
return nil
}