diff --git a/command_complete.go b/command_complete.go index 4a74734..94cfc42 100644 --- a/command_complete.go +++ b/command_complete.go @@ -8,7 +8,7 @@ import ( ) type CommandComplete struct { - CommandTag []byte `json:"-" yaml:"-"` + CommandTag []byte `json:"command_tag" yaml:"command_tag,omitempty,flow"` CommandTagType string `json:"command_tag_type" yaml:"command_tag_type"` } @@ -26,7 +26,8 @@ func (dst *CommandComplete) Decode(src []byte) error { dst.CommandTag = src[:idx] dst.CommandTagType = string(dst.CommandTag) - + // empty the buffer + dst.CommandTag = []byte{} return nil } @@ -36,7 +37,10 @@ func (src *CommandComplete) Encode(dst []byte) []byte { dst = append(dst, 'C') sp := len(dst) dst = pgio.AppendInt32(dst, -1) - src.CommandTag = []byte(src.CommandTagType) + + if len(src.CommandTag) == 0 { + src.CommandTag = []byte(src.CommandTagType) + } dst = append(dst, src.CommandTag...) dst = append(dst, 0) diff --git a/row_description.go b/row_description.go index d68bfbc..046d3ff 100644 --- a/row_description.go +++ b/row_description.go @@ -14,8 +14,8 @@ const ( ) type FieldDescription struct { - Name []byte `json:"-" yaml:"-"` - FieldName string `json:"name" yaml:"name"` + Name []byte `json:"name" yaml:"name,omitempty"` + FieldName string `json:"field_name" yaml:"field_name"` TableOID uint32 `json:"table_oid" yaml:"table_oid"` TableAttributeNumber uint16 `json:"table_attribute_number" yaml:"table_attribute_number"` DataTypeOID uint32 `json:"data_type_oid" yaml:"data_type_oid"` @@ -73,6 +73,8 @@ func (dst *RowDescription) Decode(src []byte) error { } fd.Name = src[rp : rp+idx] fd.FieldName = string(fd.Name) + // now empty the buffer + fd.Name = []byte{} rp += idx + 1 // Since buf.Next() doesn't return an error if we hit the end of the buffer @@ -109,8 +111,10 @@ func (src *RowDescription) Encode(dst []byte) []byte { dst = pgio.AppendUint16(dst, uint16(len(src.Fields))) for _, fd := range src.Fields { + if len(fd.Name) == 0 { + fd.Name = []byte(fd.FieldName) + } - fd.Name = []byte(fd.FieldName) dst = append(dst, fd.Name...) dst = append(dst, 0)