Reduce allocations and copies in pgproto3
Altered chunkreader to never reuse memory. Altered pgproto3 to to copy memory when decoding. Renamed UnmarshalBinary to Decode because of changed semantics.
This commit is contained in:
+6
-53
@@ -2,8 +2,13 @@ package pgproto3
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Message is the interface implemented by an object that can decode and encode
|
||||
// a particular PostgreSQL message.
|
||||
//
|
||||
// Decode is allowed and expected to retain a reference to data after
|
||||
// returning (unlike encoding.BinaryUnmarshaler).
|
||||
type Message interface {
|
||||
UnmarshalBinary(data []byte) error
|
||||
Decode(data []byte) error
|
||||
MarshalBinary() (data []byte, err error)
|
||||
}
|
||||
|
||||
@@ -17,58 +22,6 @@ type BackendMessage interface {
|
||||
Backend() // no-op method to distinguish frontend from backend methods
|
||||
}
|
||||
|
||||
// func ParseBackend(typeByte byte, body []byte) (BackendMessage, error) {
|
||||
// switch typeByte {
|
||||
// case '1':
|
||||
// return ParseParseComplete(body)
|
||||
// case '2':
|
||||
// return ParseBindComplete(body)
|
||||
// case 'C':
|
||||
// return ParseCommandComplete(body)
|
||||
// case 'D':
|
||||
// return ParseDataRow(body)
|
||||
// case 'E':
|
||||
// return ParseErrorResponse(body)
|
||||
// case 'K':
|
||||
// return ParseBackendKeyData(body)
|
||||
// case 'R':
|
||||
// return ParseAuthentication(body)
|
||||
// case 'S':
|
||||
// return ParseParameterStatus(body)
|
||||
// case 'T':
|
||||
// return ParseRowDescription(body)
|
||||
// case 't':
|
||||
// return ParseParameterDescription(body)
|
||||
// case 'Z':
|
||||
// return ParseReadyForQuery(body)
|
||||
// default:
|
||||
// return ParseUnknownMessage(typeByte, body)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func ParseFrontend(typeByte byte, body []byte) (FrontendMessage, error) {
|
||||
// switch typeByte {
|
||||
// case 'B':
|
||||
// return ParseBind(body)
|
||||
// case 'D':
|
||||
// return ParseDescribe(body)
|
||||
// case 'E':
|
||||
// return ParseExecute(body)
|
||||
// case 'P':
|
||||
// return ParseParse(body)
|
||||
// case 'p':
|
||||
// return ParsePasswordMessage(body)
|
||||
// case 'Q':
|
||||
// return ParseQuery(body)
|
||||
// case 'S':
|
||||
// return ParseSync(body)
|
||||
// case 'X':
|
||||
// return ParseTerminate(body)
|
||||
// default:
|
||||
// return ParseUnknownMessage(typeByte, body)
|
||||
// }
|
||||
// }
|
||||
|
||||
type invalidMessageLenErr struct {
|
||||
messageType string
|
||||
expectedLen int
|
||||
|
||||
Reference in New Issue
Block a user