json: Implement json.Unmarshaler for messages.
This will allow using pgmockproxy output as ingestion data for pgmock.
This commit is contained in:
committed by
Jack Christensen
parent
1213b69774
commit
ba924e5715
+16
-1
@@ -1,6 +1,10 @@
|
||||
package pgproto3
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Message is the interface implemented by an object that can decode and encode
|
||||
// a particular PostgreSQL message.
|
||||
@@ -40,3 +44,14 @@ type invalidMessageFormatErr struct {
|
||||
func (e *invalidMessageFormatErr) Error() string {
|
||||
return fmt.Sprintf("%s body is invalid", e.messageType)
|
||||
}
|
||||
|
||||
// getValueFromJSON gets the value from a protocol message representation in JSON.
|
||||
func getValueFromJSON(v map[string]string) ([]byte, error) {
|
||||
if text, ok := v["text"]; ok {
|
||||
return []byte(text), nil
|
||||
}
|
||||
if binary, ok := v["binary"]; ok {
|
||||
return hex.DecodeString(binary)
|
||||
}
|
||||
return nil, errors.New("unknown protocol representation")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user