jackc / jackc/pgx

Clone a backend message

Open
#1,828 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

**Is your feature request related to a problem? Please describe.**
I used the pgconn to handle low level libpq protocol in my projects which are stream replication proxy. I found that the lifespan of messages which were returned from Receive method is very short. I have to clone the backend messages and keep messages in memory to send in proper time. Now, for clone, I need type assert, encode, define a variable and decode.

**Describe the solution you'd like**
```go
type BackendMessage interface {
Message()
Clone() BackendMessage()
Backend()
}
```
or
```go
type Message interface {
Encode([]byte) []byte
Decode([]byte) error
Clone() Message
}
```

The Message interface are also be contained in FrontedMessage, but the source of FrontedMessage is determined by users, so I think the first method is more reasonable. The simeplest way of Clone:

```go
func (src *CopyData) Clone() BackendMessage {
var ret CopyData
_ = ret.Decode(src.Encode(nil)[5:])
return &ret
}
```

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the pgconn BackendMessage interface and the Receive method, then inspect the CopyData Encode and Decode methods mentioned in the issue. Done means agreeing on and implementing a supported cloning API for backend messages, with behavior that preserves messages after Receive returns.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
backend-api-design, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.