# Protobuf encoder returns empty buffer payload (2)

**URL:** <https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload-2/60183>\
**Category:** General\
**Created:** [22 March 2022 08:23 UTC](https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload-2/60183 "2022-03-22T08:23:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Highlander](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Highlander](https://discourse.nodered.org/u/Highlander)\
**Post date:** [22 March 2022 08:23 UTC](https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload-2/60183/1 "2022-03-22T08:23:06Z")

</div>

I still fail to get the encoder to work.  
I have read the first post. Still no joy.

> [@Protobuf encoder returns empty buffer payload](https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload/34018):
>
> I am using [node-red-contrib-protobuf](https://flows.nodered.org/node/node-red-contrib-protobuf) I got the decoder to work with my .proto just fine, but when I try to do it the other way around with the encoder it doesn't work and just returns to me a payload with buffer[0]. I expect it to return to me the serialized data (bytes) in a buffer array which is what I decoded successfully. I wonder if I might be missing something about the format of the message that is sent to the encoder node. Don't I just send: msg.payload = {protobuf object as json} retu…

the solution presented is msg.payload={payload:{....}}

I still get payload:buffer[0] in the debug node

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 March 2022 08:38 UTC](https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload-2/60183/2 "2022-03-22T08:38:52Z")

</div>

Welcome to the forum @Highlander

Please add a debug node showing what you are sending to the node, expand the contents in the debug pane and paste it here.

---

<div class="post-metadata">

**Author:** ![Highlander](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Highlander](https://discourse.nodered.org/u/Highlander)\
**Post date:** [22 March 2022 09:52 UTC](https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload-2/60183/3 "2022-03-22T09:52:35Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/b/6bd32247f9a78ebdab24011b009992c400fabb69.png)

---

<div class="post-metadata">

**Author:** ![Highlander](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Highlander](https://discourse.nodered.org/u/Highlander)\
**Post date:** [22 March 2022 09:53 UTC](https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload-2/60183/4 "2022-03-22T09:53:15Z")

</div>

Flow...

```auto
[
    {
        "id": "d834d19711c19ca1",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": ""
    },
    {
        "id": "81b70c550e599623",
        "type": "inject",
        "z": "d834d19711c19ca1",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "protobufType",
                "v": "Request",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"Request\":{\"has_id\":true,\"id\":35123456123456,\"location_count\":2,\"locations\":[{\"time\":0,\"latitude\":0,\"longitude\":0},{\"time\":10,\"latitude\":0.1,\"longitude\":0.1}]}}",
        "payloadType": "json",
        "x": 460,
        "y": 530,
        "wires": [
            [
                "a090e55a694af973",
                "90277ec091af9456"
            ]
        ]
    },
    {
        "id": "c5f63b690b5d79de",
        "type": "debug",
        "z": "d834d19711c19ca1",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 880,
        "y": 530,
        "wires": []
    },
    {
        "id": "a090e55a694af973",
        "type": "debug",
        "z": "d834d19711c19ca1",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 480,
        "wires": []
    },
    {
        "id": "90277ec091af9456",
        "type": "encode",
        "z": "d834d19711c19ca1",
        "name": "Request",
        "protofile": "fe99114ba64e9057",
        "protoType": "Request",
        "x": 690,
        "y": 530,
        "wires": [
            [
                "c5f63b690b5d79de"
            ]
        ]
    },
    {
        "id": "fe99114ba64e9057",
        "type": "protobuf-file",
        "protopath": "c:\\Temp\\proto\\test-proto2.proto",
        "watchFile": true
    }
]

```

---

<div class="post-metadata">

**Author:** ![Highlander](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Highlander](https://discourse.nodered.org/u/Highlander)\
**Post date:** [22 March 2022 09:56 UTC](https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload-2/60183/5 "2022-03-22T09:56:20Z")

</div>

test-proto2.proto

```auto
syntax = "proto2";

message Request {
    // Device's unique id
    optional fixed64 id = 1;

    repeated Location locations = 200;

    message Location {
        required int32 time = 1;
        required float latitude = 2;
        required float longitude = 3;
    }
}

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 March 2022 10:14 UTC](https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload-2/60183/6 "2022-03-22T10:14:00Z")

</div>

You need to exclude the Request part.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/1/f1921533d8e96ad22297a91d08ecbe0b63965e1b.png)

Use a change node to move `msg.payload.Request` to `msg.payload`

---

<div class="post-metadata">

**Author:** ![Highlander](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Highlander](https://discourse.nodered.org/u/Highlander)\
**Post date:** [22 March 2022 10:20 UTC](https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload-2/60183/7 "2022-03-22T10:20:27Z")

</div>

Thanks !

I have changed the msg.payload.Request to msg.payload

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 May 2022 10:21 UTC](https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload-2/60183/8 "2022-05-21T10:21:18Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
