the Chromium logo

The Chromium Projects

Deserialize objects in golang using protobuf


I want to deserialize an object in golang using protobuf. For example, we want to deserialize the feedback report object in golang using protobuf to check the feedbackUserCtlConsent value in it.


Key steps:

  1. Add go package for the proto. For example, the feedback report proto has proto files under


    We add the following go package to all of the files in this directory.

    option go_package = "chromiumos/tast/local/bundles/cros/feedback/proto";

    The go package directory is the place to generate the pb.go files.

  2. Go to correct directory to run command line and generate the pb.go files. For example, I want to put the pb.go files in


    I should go to the directory where the proto files located


    and run this command line.

    protoc -I . --go_out=../../../../../platform/tast-tests/src ./*.proto
  3. Import


    and go package directory to the test file. For example, I add



    fpb "chromiumos/tast/local/bundles/cros/feedback/proto"

    to the VerifyFeedbackUserCtlConsentValue test.

  4. Use Unmarshal to deserialize the object.

    report := &fpb.ExtensionSubmit{}
    if err = proto.Unmarshal(content, report); err != nil {
      s.Fatal("Failed to parse report: ", err)
  5. Call the getter function in pb.go files to get the value in the object.

    // Loop through the report array to get the feedbackUserCtlConsent value.
    feedbackUserCtlConsentValue := ""
    reportArray := report.GetWebData().GetProductSpecificData()
    for _, element := range reportArray {
      if element.GetKey() == "feedbackUserCtlConsent" {
        feedbackUserCtlConsentValue = element.GetValue()

Example CL