Skip to content

Converting Uint8Buffer -> Uint8List #571

Open
@jonasfj

Description

@jonasfj

It's not obvious to me how to convert aUint8Buffer to a Uint8List.

I imagine Uint8Buffer is useful when building a binary representation of something where I don't know the size of the output yet..

Uint8List serializeObjectStructure(Object input) {
  final result = Uint8Buffer();
  _writeInputRecursively(result, input);
  return Uint8List.fromList(result); // <-- is this efficient?
}

It would faster to do:

return Uint8List.view(result.buffer, 0, result.length);

Perhaps we should expose as UintBuffer.view() or Uint8Buffer.asUint8List(), with documentation pointing out that changing the length of the Uint8Buffer will cause the Uint8List to be decoupled.

It might also be enough to just do a documentation example. Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions