2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-04-22 16:50:18 +08:00

Update base.EncodeMessage to return byte slice

This commit is contained in:
Ken Hibino 2021-03-02 21:57:34 -08:00
parent 4046932fde
commit e408550d76

View File

@ -197,12 +197,11 @@ type TaskMessage struct {
UniqueKey string UniqueKey string
} }
// EncodeMessage marshals the given task message in JSON and returns an encoded string. // EncodeMessage marshals the given task message and returns an encoded bytes.
// TODO: Should return []byte instead of string func EncodeMessage(msg *TaskMessage) ([]byte, error) {
func EncodeMessage(msg *TaskMessage) (string, error) {
payload, err := json.Marshal(msg.Payload) payload, err := json.Marshal(msg.Payload)
if err != nil { if err != nil {
return "", err return nil, err
} }
pbmsg := pb.TaskMessage{ pbmsg := pb.TaskMessage{
Type: msg.Type, Type: msg.Type,
@ -216,11 +215,7 @@ func EncodeMessage(msg *TaskMessage) (string, error) {
Deadline: msg.Deadline, Deadline: msg.Deadline,
UniqueKey: msg.UniqueKey, UniqueKey: msg.UniqueKey,
} }
b, err := proto.Marshal(&pbmsg) return proto.Marshal(&pbmsg)
if err != nil {
return "", err
}
return string(b), nil
} }
// DecodeMessage unmarshals the given encoded string and returns a decoded task message. // DecodeMessage unmarshals the given encoded string and returns a decoded task message.