# \[Feature Request\]Add ability to use buffer type in switch node

**URL:** <https://discourse.nodered.org/t/feature-request-add-ability-to-use-buffer-type-in-switch-node/83385>\
**Category:** Feature Requests\
**Created:** [2 December 2023 18:51 UTC](https://discourse.nodered.org/t/feature-request-add-ability-to-use-buffer-type-in-switch-node/83385 "2023-12-02T18:51:42Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [2 December 2023 18:51 UTC](https://discourse.nodered.org/t/feature-request-add-ability-to-use-buffer-type-in-switch-node/83385/1 "2023-12-02T18:51:42Z")

</div>

I'm sending 3 byte RGB buffers down a flow and wanted to detect [0,0,0] and was surprised to find that the switch node doesn't seem to be able to do this

I tried a bit of JSONata but wasn't successful with that

Could the ability be added to node please?

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [2 December 2023 19:01 UTC](https://discourse.nodered.org/t/feature-request-add-ability-to-use-buffer-type-in-switch-node/83385/2 "2023-12-02T19:01:52Z")

</div>

> [@cymplecy](#):
>
> I tried a bit of JSONata but wasn't successful with that

Hi @cymplecy

If your payload for example is `[0,0,0]`

you can use the `$sum` JSONata function

 ![Screenshot 2023-12-02 at 19.01.40](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/ef349e74e86996c9b5a0c0de1a87f3931b0bcb09.png)

 ![Screenshot 2023-12-02 at 19.02.32](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/2/d2fb18ed44f34eb23f970c020c96af7a7b277df3.png)

`$sum` takes an array of values and returns the result after summing them.

PS: Im surprised I was able to test that after a few Ales! 😃

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [2 December 2023 20:15 UTC](https://discourse.nodered.org/t/feature-request-add-ability-to-use-buffer-type-in-switch-node/83385/3 "2023-12-02T20:15:03Z")

</div>

Your test was a little flawed as it would pass [0,0,0,0] and others.  
try  
`$count($$.payload.*[$ = 0]) = 3`

[edit]still not perfect

This would be better  
`$count($$.payload.*) = 3 and $count($$.payload.*[$ = 0]) = 3`  
or  
`$count($$.payload.*) = 3 and $sum($$.payload.*) = 0`  
or  
`$sum($$.payload.*) + $count($$.payload.*)`  
== 3

[edit] you could test for any buffer using an expression like this  
`$not(false in $$.payload.*#$i.([0,0,0][$i] = $))`  
where `0,0,0` could be replaced with any buffer combination for comparison.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [2 December 2023 20:15 UTC](https://discourse.nodered.org/t/feature-request-add-ability-to-use-buffer-type-in-switch-node/83385/4 "2023-12-02T20:15:51Z")

</div>

Dang it! 🤓

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [2 December 2023 21:51 UTC](https://discourse.nodered.org/t/feature-request-add-ability-to-use-buffer-type-in-switch-node/83385/5 "2023-12-02T21:51:00Z")

</div>

I tried the 1st and the last one but neither worked for me.

The incoming msg.payload is a 3 byte buffer

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [2 December 2023 21:54 UTC](https://discourse.nodered.org/t/feature-request-add-ability-to-use-buffer-type-in-switch-node/83385/6 "2023-12-02T21:54:07Z")

</div>

@E1cid

Your up - my JSONata isn’t up to your standards 🤓

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [2 December 2023 21:55 UTC](https://discourse.nodered.org/t/feature-request-add-ability-to-use-buffer-type-in-switch-node/83385/7 "2023-12-02T21:55:56Z")

</div>

Works for me please supply your test flow.

```auto
[{"id":"6f18bc6d7dd7174f","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[0,25,0,0]","payloadType":"bin","x":70,"y":1480,"wires":[["3e2bbff42a84efa4"]]},{"id":"3e2bbff42a84efa4","type":"switch","z":"d1395164b4eec73e","name":"","property":"$count($$.payload.*) = 3 and $count($$.payload.*[$ = 0]) = 3","propertyType":"jsonata","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":270,"y":1440,"wires":[["4dfb5d80e28a7ca8"]]},{"id":"50999b455bd5c850","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[0,0,0]","payloadType":"bin","x":70,"y":1620,"wires":[["3e2bbff42a84efa4"]]},{"id":"a1a205e83f1b444c","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1 ,0,0]","payloadType":"bin","x":70,"y":1520,"wires":[["3e2bbff42a84efa4"]]},{"id":"6ea79d895c640869","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1 ,0,0,0]","payloadType":"bin","x":70,"y":1560,"wires":[["3e2bbff42a84efa4"]]},{"id":"4dfb5d80e28a7ca8","type":"debug","z":"d1395164b4eec73e","name":"debug 2456","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":450,"y":1560,"wires":[]},{"id":"0f23ca3219ee63b6","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$not(false in $$.payload.*#$i.([0,25,0][$i] = $))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":1560,"wires":[["4dfb5d80e28a7ca8"]]}]

```

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [2 December 2023 22:09 UTC](https://discourse.nodered.org/t/feature-request-add-ability-to-use-buffer-type-in-switch-node/83385/8 "2023-12-02T22:09:17Z")

</div>

I wasn't setting the 1st box to JSONata - I'd just left it at ==  
Silly me

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/5/d58bbba0f3d792a55f7cb18196bdb0cc1cec4366.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [2 December 2023 22:13 UTC](https://discourse.nodered.org/t/feature-request-add-ability-to-use-buffer-type-in-switch-node/83385/9 "2023-12-02T22:13:31Z")

</div>

@marcus-j-davies is 3 sheets to the wind, whats your excuse?

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [2 December 2023 22:22 UTC](https://discourse.nodered.org/t/feature-request-add-ability-to-use-buffer-type-in-switch-node/83385/10 "2023-12-02T22:22:30Z")

</div>

I'm from Newcastle

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [2 December 2023 22:30 UTC](https://discourse.nodered.org/t/feature-request-add-ability-to-use-buffer-type-in-switch-node/83385/11 "2023-12-02T22:30:33Z")

</div>

I was betting your were mortal to.

---

<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:** [31 January 2024 22:31 UTC](https://discourse.nodered.org/t/feature-request-add-ability-to-use-buffer-type-in-switch-node/83385/12 "2024-01-31T22:31:11Z")

</div>

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