chengxilo commented on code in PR #2737:
URL: https://github.com/apache/iggy/pull/2737#discussion_r2819690017


##########
foreign/go/contracts/consumer_groups.go:
##########
@@ -35,30 +35,103 @@ type ConsumerGroupMember struct {
        Partitions      []uint32
 }
 
-type CreateConsumerGroupRequest struct {
+type CreateConsumerGroup struct {
        StreamId Identifier `json:"streamId"`
        TopicId  Identifier `json:"topicId"`
        Name     string     `json:"name"`
 }
 
-type DeleteConsumerGroupRequest struct {
+func (c *CreateConsumerGroup) Code() CommandCode {
+       return CreateGroupCode
+}
+
+func (c *CreateConsumerGroup) MarshalBinary() ([]byte, error) {
+       streamIdBytes, err := c.StreamId.MarshalBinary()
+       if err != nil {
+               return nil, err
+       }
+       topicIdBytes, err := c.TopicId.MarshalBinary()
+       if err != nil {
+               return nil, err
+       }
+       offset := len(streamIdBytes) + len(topicIdBytes)
+       bytes := make([]byte, offset+1+len(c.Name))
+       copy(bytes[0:len(streamIdBytes)], streamIdBytes)
+       copy(bytes[len(streamIdBytes):offset], topicIdBytes)
+       bytes[offset] = byte(len(c.Name))
+       copy(bytes[offset+1:], c.Name)
+       return bytes, nil
+}
+
+type DeleteConsumerGroup struct {
        StreamId        Identifier `json:"streamId"`
        TopicId         Identifier `json:"topicId"`
        ConsumerGroupId Identifier `json:"consumerGroupId"`
 }
 
-type JoinConsumerGroupRequest struct {
+func (d *DeleteConsumerGroup) Code() CommandCode {
+       return DeleteGroupCode
+}
+
+func (d *DeleteConsumerGroup) MarshalBinary() ([]byte, error) {
+       return marshalIdentifiers(d.StreamId, d.TopicId, d.ConsumerGroupId)
+}
+
+type JoinConsumerGroup struct {
        StreamId        Identifier `json:"streamId"`
        TopicId         Identifier `json:"topicId"`
        ConsumerGroupId Identifier `json:"consumerGroupId"`

Review Comment:
   Regarding the common struct. If I add a common strust like this:
   ```go
   type ConsumerGroupCommandBase struct {
        StreamId Identifier
        TopicId  Identifier
        GroupId  Identifier
   }
   ```
   `GetConsumerGroup` looks like this
   ```go
   type GetConsumerGroup struct {
        ConsumerGroupCommandBase
   }
   ```
   
   And when I use it, it would be like:
   ```go
   buffer, err := c.do(&iggcon.GetConsumerGroup{
                ConsumerGroupCommandBase: iggcon.ConsumerGroupCommandBase{
                        StreamId: streamId,
                        TopicId:  topicId,
                        GroupId:  groupId,
                },
        })
   ```
   
   To be honest, I prefer the approach without common struct personally, when 
use it, it looks more straightforward.
   ```
   buffer, err := c.do(&iggcon.GetConsumerGroup{
                StreamId: streamId,
                TopicId:  topicId,
                GroupId:  groupId,
        })
   ```
   Just personal preference. What do you think?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to