flush.go 896 B

12345678910111213141516171819202122232425262728293031323334
  1. package pgproto3
  2. import (
  3. "encoding/json"
  4. )
  5. type Flush struct{}
  6. // Frontend identifies this message as sendable by a PostgreSQL frontend.
  7. func (*Flush) Frontend() {}
  8. // Decode decodes src into dst. src must contain the complete message with the exception of the initial 1 byte message
  9. // type identifier and 4 byte message length.
  10. func (dst *Flush) Decode(src []byte) error {
  11. if len(src) != 0 {
  12. return &invalidMessageLenErr{messageType: "Flush", expectedLen: 0, actualLen: len(src)}
  13. }
  14. return nil
  15. }
  16. // Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
  17. func (src *Flush) Encode(dst []byte) ([]byte, error) {
  18. return append(dst, 'H', 0, 0, 0, 4), nil
  19. }
  20. // MarshalJSON implements encoding/json.Marshaler.
  21. func (src Flush) MarshalJSON() ([]byte, error) {
  22. return json.Marshal(struct {
  23. Type string
  24. }{
  25. Type: "Flush",
  26. })
  27. }