S
S
Space Around2021-01-20 01:20:59
JavaScript
Space Around, 2021-01-20 01:20:59

How to create a data package in js?

I am writing an application on react native for android, which should send data to a device with BLE, it is necessary to form a data packet in the following format:

0xA0 0x29 0x84 0x5A 0x10 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xBC 0x20
, I use the react-native-ble-plx library , there is a function writeWithResponse , which accepts data in base64 format as input.
Question:
  1. What are the ways in js in rn to form a data packet? What type of data is this (string, array of hex numbers)?
  2. If I understand correctly, then the data will be sent as a base64 string, how can I convert it to the data format I need?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Israfil22, 2021-01-20
@viksnamax

I hope you are writing on node, but there are browser polyfills accordingly.
There is such a data type (or class) called Buffer.
The string you described is bytes in hexadecimal form.
Translation to and from base 64 is also provided in the buffer functions.

Buffer.from(str, 'base64')
buff.toString('base64')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question