copy_done.go 1022 B

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