@@ -8,7 +8,12 @@ import (
88 headerVal "github.com/bxcodec/goqueue/headers/value"
99)
1010
11+ // EncoderFn is a function type that encodes a message into a byte slice.
12+ // It takes a context and a message as input and returns the encoded data and an error (if any).
1113type EncoderFn func (ctx context.Context , m Message ) (data []byte , err error )
14+
15+ // DecoderFn is a function type that decodes a byte slice into a Message.
16+ // It takes a context and a byte slice as input and returns a Message and an error.
1217type DecoderFn func (ctx context.Context , data []byte ) (m Message , err error )
1318
1419var (
@@ -28,27 +33,37 @@ var (
2833)
2934
3035var (
31- GoquEncodingMap = sync.Map {}
36+ // goQueueEncodingMap is a concurrent-safe map used for encoding in GoQueue.
37+ goQueueEncodingMap = sync.Map {}
3238)
3339
34- func AddGoquEncoding (contentType headerVal.ContentType , encoding * Encoding ) {
35- GoquEncodingMap .Store (contentType , encoding )
40+ // AddGoQueueEncoding stores the given encoding for the specified content type in the goQueueEncodingMap.
41+ // The goQueueEncodingMap is a concurrent-safe map that maps content types to encodings.
42+ // The content type is specified by the `contentType` parameter, and the encoding is specified by the `encoding` parameter.
43+ // This function is typically used to register custom encodings for specific content types in the GoQueue library.
44+ func AddGoQueueEncoding (contentType headerVal.ContentType , encoding * Encoding ) {
45+ goQueueEncodingMap .Store (contentType , encoding )
3646}
3747
38- func GetGoquEncoding (contentType headerVal.ContentType ) (res * Encoding , ok bool ) {
39- if encoding , ok := GoquEncodingMap .Load (contentType ); ok {
48+ // GetGoQueueEncoding returns the encoding associated with the given content type.
49+ // It looks up the encoding in the goQueueEncodingMap and returns it along with a boolean value indicating if the encoding was found.
50+ // If the encoding is not found, it returns nil and false.
51+ func GetGoQueueEncoding (contentType headerVal.ContentType ) (res * Encoding , ok bool ) {
52+ if encoding , ok := goQueueEncodingMap .Load (contentType ); ok {
4053 return encoding .(* Encoding ), ok
4154 }
4255 return nil , false
4356}
4457
58+ // Encoding represents an encoding configuration for a specific content type.
4559type Encoding struct {
46- ContentType headerVal.ContentType
47- Encode EncoderFn
48- Decode DecoderFn
60+ ContentType headerVal.ContentType // The content type associated with this encoding.
61+ Encode EncoderFn // The encoding function used to encode data.
62+ Decode DecoderFn // The decoding function used to decode data.
4963}
5064
5165var (
66+ // JSONEncoding represents the encoding configuration for JSON.
5267 JSONEncoding = & Encoding {
5368 ContentType : headerVal .ContentTypeJSON ,
5469 Encode : JSONEncoder ,
0 commit comments