# Protobuf encoder returns empty buffer payload

**URL:** https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload/34018
**Category:** General
**Created:** [9 October 2020 20:24 UTC](https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload/34018 "2020-10-09T20:24:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zaher](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zaher/32/14891_2.png) [@zaher](https://discourse.nodered.org/u/zaher)
#### Post date: [9 October 2020 20:24 UTC](https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload/34018/1 "2020-10-09T20:24:42Z")

</div>

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:

```auto
msg.payload = {protobuf object as json}
return msg;

```

What could I be missing here? I am using the same messageType, if it works with the decoder, what could I be doing wrong with the encoder?

Thanks for your help in advance! And special thanks to the developer(s) of the node, extremely helpful!

Here are my nodes if you like to import and check:

```auto
[{"id":"8391aaeb.5c6448","type":"inject","z":"7a6c6b37.ffb0a4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":610,"wires":[["c09f489e.5c6b28"]],"l":false},{"id":"f5d777ab.8e5228","type":"debug","z":"7a6c6b37.ffb0a4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":360,"y":610,"wires":[],"l":false},{"id":"c09f489e.5c6b28","type":"function","z":"7a6c6b37.ffb0a4","name":"","func":"msg.payload = {\n \"correlationId\": 123,\n \"getRequest\": {\n \"objectId\": 10\n }\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":220,"y":610,"wires":[["e03e784.769e088"]],"l":false},{"id":"e03e784.769e088","type":"encode","z":"7a6c6b37.ffb0a4","name":"","protofile":"44bcb8c1.0c0a58","protoType":"Message","x":290,"y":610,"wires":[["f5d777ab.8e5228"]],"l":false},{"id":"44bcb8c1.0c0a58","type":"protobuf-file","z":"","protopath":"/home/myProto.proto","watchFile":true}]

```

---

<div class="post-metadata">

### Author: ![zaher](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zaher/32/14891_2.png) [@zaher](https://discourse.nodered.org/u/zaher)
#### Post date: [12 October 2020 00:58 UTC](https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload/34018/2 "2020-10-12T00:58:43Z")

</div>

Just following up, hope anyone who has experience with protobuf node can help.

Thanks!

---

<div class="post-metadata">

### Author: ![zaher](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zaher/32/14891_2.png) [@zaher](https://discourse.nodered.org/u/zaher)
#### Post date: [12 October 2020 15:15 UTC](https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload/34018/3 "2020-10-12T15:15:28Z")

</div>

I got it working. The issue was in my proto format, I needed to have the payload nested under another payload. Like in:

```auto
msg.payload = { 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: [26 October 2020 15:15 UTC](https://discourse.nodered.org/t/protobuf-encoder-returns-empty-buffer-payload/34018/4 "2020-10-26T15:15:49Z")

</div>

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