bytestring_internal.js 997 B

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * @fileoverview Exposes internal only functions for ByteString. The
  3. * corresponding BUILD rule restricts access to this file to only the binary
  4. * kernel and APIs directly using the binary kernel.
  5. */
  6. goog.module('protobuf.byteStringInternal');
  7. const ByteString = goog.require('protobuf.ByteString');
  8. /**
  9. * Constructs a ByteString from an Uint8Array. DON'T MODIFY the underlying
  10. * ArrayBuffer, since the ByteString directly uses it without making a copy.
  11. * @param {!Uint8Array} bytes
  12. * @return {!ByteString}
  13. */
  14. function byteStringFromUint8ArrayUnsafe(bytes) {
  15. return ByteString.fromUint8ArrayUnsafe(bytes);
  16. }
  17. /**
  18. * Returns this ByteString as an Uint8Array. DON'T MODIFY the returned array,
  19. * since the ByteString holds the reference to the same array.
  20. * @param {!ByteString} bytes
  21. * @return {!Uint8Array}
  22. */
  23. function byteStringToUint8ArrayUnsafe(bytes) {
  24. return bytes.toUint8ArrayUnsafe();
  25. }
  26. exports = {
  27. byteStringFromUint8ArrayUnsafe,
  28. byteStringToUint8ArrayUnsafe,
  29. };