Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 9 additions & 25 deletions data_row.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func (*DataRow) Backend() {}
// Decode decodes src into dst. src must contain the complete message with the exception of the initial 1 byte message
// type identifier and 4 byte message length.
func (dst *DataRow) Decode(src []byte) error {
//println("DataRow.Decode")
if len(src) < 2 {
return &invalidMessageFormatErr{messageType: "DataRow"}
}
Expand Down Expand Up @@ -83,46 +82,31 @@ func (dst *DataRow) Decode(src []byte) error {

// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
func (src *DataRow) Encode(dst []byte) []byte {
//println("DataRow.Encode")

dst = append(dst, 'D')
sp := len(dst)
dst = pgio.AppendInt32(dst, -1)
// src.Values = stringsToBytesArray(src.RowValues)

// epoch := time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)

// // Given date
// givenDate := time.Date(2021, 7, 14, 0, 0, 0, 0, time.UTC)

// Calculate the difference in days
// difference := givenDate.Sub(epoch).Hours() / 24

// Prepare a byte slice to hold the binary representation
// buf := make([]byte, 4)
// binary.BigEndian.PutUint32(buf, uint32(difference))

// // Output the difference in days and the binary representation
// fmt.Printf("Days difference: %d\n", int(difference))
// fmt.Printf("Binary representation: %v\n", buf)
if src.RowValues != nil && len(src.RowValues) > 0 {
src.Values = stringsToBytesArray(src.RowValues)
}
// fmt.Println("SRC VALUES", src.Values)

dst = pgio.AppendUint16(dst, uint16(len(src.Values)))

for _, v := range src.Values {
if v == nil || len(v) == 0 {
// NULL only if v == nil
if v == nil {
dst = pgio.AppendInt32(dst, -1)
continue
}

// Empty string is length 0 (not NULL)
dst = pgio.AppendInt32(dst, int32(len(v)))
dst = append(dst, v...)
if len(v) > 0 {
dst = append(dst, v...)
}
Comment on lines +104 to +106
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The length check len(v) > 0 is redundant since appending an empty slice is a no-op. This check can be removed to simplify the code without changing behavior.

Suggested change
if len(v) > 0 {
dst = append(dst, v...)
}
dst = append(dst, v...)

Copilot uses AI. Check for mistakes.
}

pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))

// src.RowValues = []string{}
// src.Values = [][]byte{}
return dst
}

Expand Down