what is the equivalent of ByteBuffer.wrap in dart?

735 Views Asked by At

I have the following snippet of code to be converted to dart.

JAVA CODE

static final byte[] MESSAGE_M1_REQUEST = new byte[]{(int) 1, (int) 2, (int) 3, (int) 4};
ByteBuffer bf =   ByteBuffer.wrap(MESSAGE_M1_REQUEST);
int certLength = ByteBuffer.wrap(macIdBytes).getInt();

Dart

Using Uint8List in Dart instead of byte[] and how to do ByteBuffer.wrap & use .getInt() on Uint8List ?

final Uint8List MESSAGE_M1_REQUEST = Uint8List.fromList([1, 2, 3, 4]);
1

There are 1 best solutions below

1
On

As per the Documentation : https://api.dart.dev/stable/1.24.3/dart-typed_data/ByteData-class.html

Tried something like this and getting the same output in Java & Dart.

MESSAGE_M1_REQUEST.buffer.asByteData().getInt32(0)