lua-protobuf icon indicating copy to clipboard operation
lua-protobuf copied to clipboard

Decode to a temporary message to extract or change data

Open amyrprv opened this issue 1 year ago • 1 comments

Hi, I have the below data for example

{
  "a": {
    "b": "",
    "c": {},
    "d": [
      {
        "e": "",
        "f": "s",
        "g": {
          "h": "",
          "i": "",
          "j": ""
        }
      }
    ],
    "k": {}
  },
  "l": {
    "m": { "t": "u" },
    "n": "v",
    "o": {
      "p": "̊w",
      "q": { "x": 1, "y": 1, "z": 1, "a1": 0 },
      "e": a2
    }
  }
}

Now, I aim to modify the e field within this structure. While I lack the Protobuf definition and message name, I possess the field number path to access e. I plan to generate a temporary message using the provided field numbers, decode the binary, modify the value, and then encode it again.

However, I've encountered an issue: when I decode the modified message alongside the actual message and its definition, I experience data loss and the disappearance of other fields.

Please guide on performing this task without experiencing data loss or losing other fields in the process.

amyrprv avatar Feb 14 '24 12:02 amyrprv

You could use the lower level API to complete thus mission. See the document of 'Slice' (for decoding) and 'Buffer' (for encoding).

starwing avatar Oct 13 '24 14:10 starwing