Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Ensure we can parse Connect and Disconnect
Browse files Browse the repository at this point in the history
Without this, we'll leave many connections trailing during our
benchmarking. That wouldn't be great, so this commit changes it.
  • Loading branch information
lawrencejones committed Mar 5, 2019
1 parent ecb01ad commit e84982f
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions pkg/pgreplay/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ type (
SessionID string
)

const (
ConnectLabel = "Connect"
StatementLabel = "Statement"
BoundExecuteLabel = "BoundExecute"
DisconnectLabel = "Disconnect"
)

func ItemMarshalJSON(item Item) ([]byte, error) {
type envelope struct {
Type string `json:"type"`
Expand All @@ -21,13 +28,13 @@ func ItemMarshalJSON(item Item) ([]byte, error) {

switch item.(type) {
case Connect, *Connect:
return json.Marshal(envelope{Type: "Connect", Item: item})
return json.Marshal(envelope{Type: ConnectLabel, Item: item})
case Statement, *Statement:
return json.Marshal(envelope{Type: "Statement", Item: item})
return json.Marshal(envelope{Type: StatementLabel, Item: item})
case BoundExecute, *BoundExecute:
return json.Marshal(envelope{Type: "BoundExecute", Item: item})
return json.Marshal(envelope{Type: BoundExecuteLabel, Item: item})
case Disconnect, *Disconnect:
return json.Marshal(envelope{Type: "Disconnect", Item: item})
return json.Marshal(envelope{Type: DisconnectLabel, Item: item})
default:
return nil, nil // it's not important for us to serialize this
}
Expand All @@ -46,10 +53,14 @@ func ItemUnmarshalJSON(payload []byte) (Item, error) {
var item Item

switch envelope.Type {
case "Statement":
case ConnectLabel:
item = &Connect{}
case StatementLabel:
item = &Statement{}
case "BoundExecute":
case BoundExecuteLabel:
item = &BoundExecute{}
case DisconnectLabel:
item = &Disconnect{}
default:
return nil, fmt.Errorf("did not recognise type: %s", envelope.Type)
}
Expand Down

0 comments on commit e84982f

Please sign in to comment.