hibiken / asynq

Simple, reliable, and efficient distributed task queue in Go
MIT License
10.04k stars 716 forks source link

[FEATURE REQUEST] customize serializer #873

Open cold-bin opened 6 months ago

cold-bin commented 6 months ago

Is your feature request related to a problem? Please describe. I want to customize serializer, need a defined interface in order to better readability or better performance

// EncodeSchedulerEnqueueEvent marshals the given event
// and returns an encoded bytes.
func EncodeSchedulerEnqueueEvent(event *SchedulerEnqueueEvent) ([]byte, error) {
    if event == nil {
        return nil, fmt.Errorf("cannot encode nil enqueue event")
    }
    enqueuedAt, err := ptypes.TimestampProto(event.EnqueuedAt)
    if err != nil {
        return nil, err
    }
    return proto.Marshal(&pb.SchedulerEnqueueEvent{
        TaskId:      event.TaskID,
        EnqueueTime: enqueuedAt,
    })
}

Describe the solution you'd like

type Serializer interface{
  func Marshal(v any) ([]byte, error)
  func Unmarshal(data []byte, v any) error
}

so that, I can write my serializer.