package pubsub

import (
	

	pb 
)

// msgIDGenerator handles computing IDs for msgs
// It allows setting custom generators(MsgIdFunction) per topic
type msgIDGenerator struct {
	Default MsgIdFunction

	topicGensLk sync.RWMutex
	topicGens   map[string]MsgIdFunction
}

func newMsgIdGenerator() *msgIDGenerator {
	return &msgIDGenerator{
		Default:   DefaultMsgIdFn,
		topicGens: make(map[string]MsgIdFunction),
	}
}

// Set sets custom id generator(MsgIdFunction) for topic.
func ( *msgIDGenerator) ( string,  MsgIdFunction) {
	.topicGensLk.Lock()
	.topicGens[] = 
	.topicGensLk.Unlock()
}

// ID computes ID for the msg or short-circuits with the cached value.
func ( *msgIDGenerator) ( *Message) string {
	if .ID != "" {
		return .ID
	}

	.ID = .RawID(.Message)
	return .ID
}

// RawID computes ID for the proto 'msg'.
func ( *msgIDGenerator) ( *pb.Message) string {
	.topicGensLk.RLock()
	,  := .topicGens[.GetTopic()]
	.topicGensLk.RUnlock()
	if ! {
		 = .Default
	}

	return ()
}