Buffer.hx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package eval.luv;
  2. import haxe.io.Bytes;
  3. /**
  4. Data buffers.
  5. @see https://aantron.github.io/luv/luv/Luv/Buffer
  6. **/
  7. @:coreType abstract Buffer {
  8. /**
  9. Allocates a fresh buffer of the given size.
  10. **/
  11. static public function create(size:Int):Buffer;
  12. /**
  13. Creates a buffer from a string.
  14. **/
  15. @:from static public function fromNativeString(s:NativeString):Buffer;
  16. /**
  17. Creates a buffer from a string.
  18. **/
  19. @:from static public function fromString(s:String):Buffer;
  20. /**
  21. Creates a buffer from bytes.
  22. **/
  23. @:from static public function fromBytes(b:Bytes):Buffer;
  24. /**
  25. Evaluates to the sum of the sizes of the buffers in the array.
  26. **/
  27. static public function totalSize(buffers:Array<Buffer>):Int;
  28. /**
  29. `Buffer.drop(buffers, count)` drops the first `count` bytes from `buffers`.
  30. For example, if `buffers` contains two buffers of size 16, `Buffer.drop(buffers, 18)`
  31. will evaluate to an array that has lost the reference to the first buffer,
  32. and contains only a view into the second buffer of size 14.
  33. **/
  34. static public function drop(buffers:Array<Buffer>, count:Int):Array<Buffer>;
  35. /**
  36. Evaluates to the size of the buffer.
  37. **/
  38. public function size():Int;
  39. /**
  40. Retrieve a byte at the given index.
  41. **/
  42. @:arrayAccess public function get(index:Int):Int;
  43. /**
  44. Retrieve a byte at the given index without a bounds check.
  45. **/
  46. public function unsafeGet(index:Int):Int;
  47. /**
  48. Set byte value at the given index.
  49. **/
  50. @:arrayAccess public function set(index:Int, byte:Int):Int;
  51. /**
  52. Set byte value at the given index without a bounds check.
  53. **/
  54. public function unsafeSet(index:Int, byte:Int):Int;
  55. /**
  56. Creates a view into buffer that starts at the given `offset` and has the given `length`.
  57. No data is copied.
  58. **/
  59. public function sub(offset:Int, length:Int):Buffer;
  60. /**
  61. Copies data from this buffer to destination.
  62. The amount of data copied is the minimum of the two buffers' size.
  63. **/
  64. public function blit(destination:Buffer):Void;
  65. /**
  66. Fills the given buffer with the given byte.
  67. **/
  68. public function fill(byte:Int):Void;
  69. /**
  70. Creates a string with the same contents as the buffer.
  71. **/
  72. public function toString():String;
  73. /**
  74. Creates a native string with the same contents as the buffer.
  75. **/
  76. public function toNativeString():NativeString;
  77. /**
  78. Creates a `haxe.io.Bytes` instance with the same contents as this buffer.
  79. **/
  80. public function toBytes():Bytes;
  81. /**
  82. Copies data from a buffer to bytes buffer.
  83. **/
  84. public function blitToBytes(destination:Bytes, destinationOffset:Int):Void;
  85. /**
  86. Copies data from bytes to a buffer.
  87. **/
  88. public function blitFromBytes(source:Bytes, sourceOffset:Int):Void;
  89. /**
  90. Copies data from bytes to a buffer.
  91. Note: `sourceOffset` is not a character offset but a byte offset.
  92. **/
  93. public function blitFromString(source:NativeString, sourceOffset:Int):Void;
  94. }