# Buffer-Parser fails by using specification

**URL:** <https://discourse.nodered.org/t/buffer-parser-fails-by-using-specification/82432>\
**Category:** General\
**Created:** [28 October 2023 23:25 UTC](https://discourse.nodered.org/t/buffer-parser-fails-by-using-specification/82432 "2023-10-28T23:25:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris123](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@chris123](https://discourse.nodered.org/u/chris123)\
**Post date:** [28 October 2023 23:25 UTC](https://discourse.nodered.org/t/buffer-parser-fails-by-using-specification/82432/1 "2023-10-28T23:25:24Z")

</div>

Hi All,  
I've got no answer for this behavior of the buffer-parser:

I've got some bytes pushing through the buffer-parser. As long as I do all the settings within the buffer-parser node itselve, all is like expected. But as soon as I start using the specification it does not give me the exponent. It gives me zero and not -1 or -2 like expected. I built an example flow for demonstration:

```auto
[{"id":"77035d12c456286b","type":"tab","label":"Flow 7","disabled":false,"info":"","env":[]},{"id":"d04905d94adb39d0","type":"debug","z":"77035d12c456286b","name":"debug 318","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":160,"wires":[]},{"id":"08e9bee652ad3412","type":"inject","z":"77035d12c456286b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[65024,5008,65280,2283]","payloadType":"json","x":230,"y":160,"wires":[["84b9ee52e5cdcf3f","d64e7654502d18a2"]]},{"id":"84b9ee52e5cdcf3f","type":"function","z":"77035d12c456286b","name":"dynamically set spec","func":"msg.spec = {\n \"options\":\n {\n \"byteSwap\":false,\n \"resultType\": \"keyvalue\",\n \"setTopic\": true,\n \"multipleResult\": false\n },\n \"items\":[\n \n {\n \"name\": \"F\",\n \"type\": \"uint32be\",\n \"offset\": 0,\n \"mask\": 0x00FFFFF\n },\n {\n \"name\": \"F2\",\n \"type\": \"int8\",\n \"offset\": 0\n },\n {\n \"name\": \"Ua\",\n \"type\": \"uint32be\",\n \"offset\": 4,\n \"mask\": \"0x00fffff\"\n },\n {\n \"name\": \"Ua_exp\",\n \"type\": \"int8\",\n \"offset\": 4\n }\n]\n}\n\nreturn msg;\n\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":120,"wires":[["01aa41b430f4a104"]]},{"id":"01aa41b430f4a104","type":"buffer-parser","z":"77035d12c456286b","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"msg","items":[{"type":"uint32be","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"0x00fffff"},{"type":"int8","name":"item2","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":710,"y":120,"wires":[["d04905d94adb39d0"]]},{"id":"d64e7654502d18a2","type":"buffer-parser","z":"77035d12c456286b","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint32be","name":"F","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"0x00fffff"},{"type":"int8","name":"F2","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint32be","name":"Ua","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":"0x00fffff"},{"type":"int8","name":"Ua_exp","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":610,"y":180,"wires":[["d04905d94adb39d0"]]}]

```

 ![buffer-parser](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/e/4e341750dc7d3f99d2e71a96dff1d353df0abc3d.jpeg)

Can you see the difference between the settings inside the buffer-parser and the variation with specification?

Thank you very much!

BR  
Chris

---

<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:** [29 October 2023 07:53 UTC](https://discourse.nodered.org/t/buffer-parser-fails-by-using-specification/82432/2 "2023-10-29T07:53:48Z")

</div>

I havent looked closely but there is a handy trick: if you set the debug to output full msg, the buffer parser outputs the `specification` it used internally which you can capture from a working flow and re-use it as a template.

Here, I copied the specification from the statically set buffer-parser and re-used that as a dynamic spec in 3rd working flow.

 ![Screenshot 2023-10-29 08.49.04](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/e/2e353cf54fe8bef9ef8dd557b0d77c1d376736fc.png)

```auto
[{"id":"08e9bee652ad3412","type":"inject","z":"77035d12c456286b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[65024,5008,65280,2283]","payloadType":"json","x":210,"y":120,"wires":[["84b9ee52e5cdcf3f"]]},{"id":"84b9ee52e5cdcf3f","type":"function","z":"77035d12c456286b","name":"dynamically set spec","func":"msg.spec = {\n \"options\":\n {\n \"byteSwap\":false,\n \"resultType\": \"keyvalue\",\n \"setTopic\": true,\n \"multipleResult\": false\n },\n \"items\":[\n {\n \"name\": \"F\",\n \"type\": \"uint32be\",\n \"offset\": 0,\n \"mask\": 0x00FFFFF\n },\n {\n \"name\": \"F2\",\n \"type\": \"int8\",\n \"offset\": 0\n },\n {\n \"name\": \"Ua\",\n \"type\": \"uint32be\",\n \"offset\": 4,\n \"mask\": \"0x00fffff\"\n },\n {\n \"name\": \"Ua_exp\",\n \"type\": \"int8\",\n \"offset\": 4\n }\n]\n}\n\nreturn msg;\n\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":120,"wires":[["01aa41b430f4a104"]]},{"id":"01aa41b430f4a104","type":"buffer-parser","z":"77035d12c456286b","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"msg","items":[{"type":"uint32be","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"0x00fffff"},{"type":"int8","name":"item2","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":710,"y":120,"wires":[["b3ab3f3e3b7fc006"]]},{"id":"d64e7654502d18a2","type":"buffer-parser","z":"77035d12c456286b","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint32be","name":"F","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"0x00fffff"},{"type":"int8","name":"F2","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint32be","name":"Ua","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":"0x00fffff"},{"type":"int8","name":"Ua_exp","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":710,"y":160,"wires":[["2c3ee34c8e1d75f5","cdb202969869478f"]]},{"id":"de7c280899e6d34f","type":"inject","z":"77035d12c456286b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[65024,5008,65280,2283]","payloadType":"json","x":210,"y":160,"wires":[["d64e7654502d18a2"]]},{"id":"b3ab3f3e3b7fc006","type":"debug","z":"77035d12c456286b","name":"incorrect","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":120,"wires":[]},{"id":"2c3ee34c8e1d75f5","type":"debug","z":"77035d12c456286b","name":"reference","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":160,"wires":[]},{"id":"427512e02bfd1a10","type":"buffer-parser","z":"77035d12c456286b","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"msg","items":[{"type":"uint32be","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":"0x00fffff"},{"type":"int8","name":"item2","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":710,"y":242,"wires":[["d207f73ff47c4da9"]]},{"id":"2f2af8b986e0ca79","type":"function","z":"77035d12c456286b","name":"dynamically set spec","func":"msg.spec = {\n \"options\": {\n \"byteSwap\": [],\n \"resultType\": \"keyvalue\",\n \"singleResult\": true,\n \"msgProperty\": \"payload\",\n \"setTopic\": true\n },\n \"items\": [\n {\n \"type\": \"uint32be\",\n \"name\": \"F\",\n \"offset\": 0,\n \"length\": 1,\n \"scale\": \"1\",\n \"mask\": \"0x00fffff\"\n },\n {\n \"type\": \"int8\",\n \"name\": \"F2\",\n \"offset\": 0,\n \"length\": 1,\n \"scale\": \"1\",\n \"mask\": \"\"\n },\n {\n \"type\": \"uint32be\",\n \"name\": \"Ua\",\n \"offset\": 4,\n \"length\": 1,\n \"scale\": \"1\",\n \"mask\": \"0x00fffff\"\n },\n {\n \"type\": \"int8\",\n \"name\": \"Ua_exp\",\n \"offset\": 4,\n \"length\": 1,\n \"scale\": \"1\",\n \"mask\": \"\"\n }\n]\n}\nreturn msg;\n\n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":242,"wires":[["427512e02bfd1a10"]]},{"id":"d207f73ff47c4da9","type":"debug","z":"77035d12c456286b","name":"working","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":242,"wires":[]},{"id":"7040afd1d9a16ada","type":"inject","z":"77035d12c456286b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[65024,5008,65280,2283]","payloadType":"json","x":210,"y":242,"wires":[["2f2af8b986e0ca79"]]},{"id":"cdb202969869478f","type":"debug","z":"77035d12c456286b","name":"specification from static config","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"specification","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":200,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![chris123](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@chris123](https://discourse.nodered.org/u/chris123)\
**Post date:** [29 October 2023 08:30 UTC](https://discourse.nodered.org/t/buffer-parser-fails-by-using-specification/82432/3 "2023-10-29T08:30:34Z")

</div>

Hi Steve-Mcl,  
thank's a lot!!  
That's a great trick. The problem seems, that it want's to have also a mask "" for the items without mask.

You made my day. It took me 3 hours without success but now I can continue 😉

BR  
Chris

---

<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:** [12 November 2023 08:30 UTC](https://discourse.nodered.org/t/buffer-parser-fails-by-using-specification/82432/4 "2023-11-12T08:30:57Z")

</div>

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