starwing / lua-protobuf

A Lua module to work with Google protobuf
MIT License
1.71k stars 388 forks source link

Decode to a temporary message to extract or change data #260

Open amyrprv opened 5 months ago

amyrprv commented 5 months ago

Hi, I have the below data for example

{
  "transaction_query": {
    "user_query": "",
    "ids": {},
    "account_ids": [
      {
        "localized_description": "",
        "oneof_account_identifier": "account_number",
        "account_number": {
          "latin_description": "",
          "localized_description": "",
          "raw_value": ""
        }
      }
    ],
    "merchant_category_codes": {}
  },
  "context": {
    "locale": { "identifier": "en" },
    "request_id": "666",
    "app": {
      "device_id": "̊192",
      "version": { "major": 1, "minor": 1, "build": 1, "patch": 0 },
      "debugger_attached": false
    }
  }
}

Now, I aim to modify the debugger_attached field within this structure. While I lack the Protobuf definition and message name, I do possess the field number path to access debugger_attached. My plan is 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.

Could you please provide guidance on how to perform this task without experiencing data loss or losing other fields in the process?