0

I have 5 fields in protobuf ( 3 required fileds and 2 optional fileds ). From producer end i will send 3 required fileds (marshall) and get those (unmarshall) 3 required fileds at consumer end. Now, i want to add those two optional parameters values at consumer end . Is it possible ? if yes, how?

Thanks in Advance

Vani Polnedi
  • 595
  • 2
  • 4
  • 19
  • What exactly do you mean by "add those two optional parameters at consumer end"? You received a message, how can you add the optional fields? – Burak Serdar Nov 15 '19 at 05:59
  • I want to assign value for optinal paramaters at consumer end and send it to another queue . Is it possible? – Vani Polnedi Nov 15 '19 at 06:06
  • 1
    After receiving the msg, you can modify the struct and marshal it again. It is a new message at that point. – Burak Serdar Nov 15 '19 at 06:14

1 Answers1

0

To update a field for a struct that is already in memory declare the variable name with the field like the example below. If someStruct is in memory the value can be overwritten at anytime.

someStruct.SomeField = SomeValue

package main

import (
    "fmt"
)

type Data struct {
    FieldOne   string
    FieldTwo   int
    FieldThree []string
    FieldFour  float64
}

func main() {
    data := createData("A string", 9)
    data = data.rcv()
    fmt.Println(data)
}

func createData(f1 string, f2 int) *Data {
    d := &Data{}
    d.FieldOne = f1
    d.FieldTwo = f2
    return d
}

func (d *Data) rcv() *Data {
    d.FieldThree = []string{"string1", "string2"}
    d.FieldFour = 1.2
    return d
}