vid_us_data_writer.dart 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'dart:typed_data';
  4. ///Not used for now.
  5. class VidUsDataWriter {
  6. final BytesBuilder _builder = new BytesBuilder();
  7. Uint8List get data => _builder.toBytes();
  8. void writeString(String value) {
  9. var data = utf8.encode(value);
  10. var length = data.length;
  11. writeInt(length);
  12. _builder.add(data);
  13. }
  14. void writeInt(int value) {
  15. var data = Uint8List(4);
  16. data.buffer.asByteData().setInt32(0, value, Endian.little);
  17. _builder.add(data);
  18. }
  19. void writeInt16(int value) {
  20. var data = Uint8List(2);
  21. data.buffer.asByteData().setInt16(0, value, Endian.little);
  22. _builder.add(data);
  23. }
  24. void writeInt64(int value) {
  25. var data = Uint8List(8);
  26. data.buffer.asByteData().setInt64(0, value, Endian.little);
  27. _builder.add(data);
  28. }
  29. void writeFloat(double value) {
  30. var data = Uint8List(4);
  31. data.buffer.asByteData().setFloat32(0, value, Endian.little);
  32. _builder.add(data);
  33. }
  34. void writeDouble(double value) {
  35. var data = Uint8List(8);
  36. data.buffer.asByteData().setFloat64(0, value, Endian.little);
  37. _builder.add(data);
  38. }
  39. void writeBool(bool value) {
  40. _builder.addByte(value ? 1 : 0);
  41. }
  42. void writeByte(int value) {
  43. _builder.addByte(value);
  44. }
  45. void writeBytes(Uint8List value) {
  46. writeInt(value.length);
  47. _builder.add(value);
  48. }
  49. void writeLongs(Int64List value) {
  50. _builder.add(value.buffer.asUint8List());
  51. }
  52. }