Bytes.hx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (C)2005-2016 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package hl.types;
  23. @:coreType abstract Bytes {
  24. @:extern public inline function new( v : Int ) {
  25. this = alloc(v);
  26. }
  27. @:hlNative("std","bytes_blit") public function blit( pos : Int, src : Bytes, srcPos : Int, len : Int ) : Void {
  28. }
  29. @:extern @:arrayAccess public inline function getUI8( pos : Int ) : Int {
  30. return untyped $bgetui8(this,pos);
  31. }
  32. @:extern @:arrayAccess public inline function setUI8( pos : Int, value : Int ) : Int {
  33. untyped $bsetui8(this,pos,value);
  34. return value;
  35. }
  36. @:extern public inline function getI32( pos : Int ) : Int {
  37. return untyped $bgeti32(this,pos);
  38. }
  39. public inline function getUI16( pos : Int ) : Int {
  40. return untyped $bgetui16(this, pos);
  41. }
  42. public inline function setUI16( pos : Int, v : Int ) {
  43. untyped $bsetui16(this,pos,v);
  44. }
  45. @:extern public inline function getF32( pos : Int ) : F32 {
  46. return untyped $bgetf32(this,pos);
  47. }
  48. @:extern public inline function getF64( pos : Int ) : Float {
  49. return untyped $bgetf64(this,pos);
  50. }
  51. @:extern public inline function setI32( pos : Int, value : Int ) : Void {
  52. untyped $bseti32(this, pos, value);
  53. }
  54. @:extern public inline function setF32( pos : Int, value : F32 ) : Void {
  55. untyped $bsetf32(this, pos, value);
  56. }
  57. @:extern public inline function setF64( pos : Int, value : Float ) : Void {
  58. untyped $bsetf64(this, pos, value);
  59. }
  60. @:hlNative("std","alloc_bytes")
  61. static function alloc( size : Int ) : Bytes {
  62. return null;
  63. }
  64. @:hlNative("std","parse_int")
  65. public function parseInt( pos : Int, size : Int ) : Null<Int> {
  66. return null;
  67. }
  68. @:hlNative("std","parse_float")
  69. public function parseFloat( pos : Int, size : Int ) : Float {
  70. return 0.;
  71. }
  72. @:hlNative("std","bytes_compare")
  73. public function compare( pos : Int, bytes : Bytes, bytesPos : Int, size : Int ) : Int {
  74. return 0;
  75. }
  76. @:hlNative("std","bytes_find")
  77. public function find( pos : Int, size : Int, bytes : Bytes, bytesPos : Int, bytesSize : Int ) : Int {
  78. return 0;
  79. }
  80. @:hlNative("std","bytes_fill")
  81. public function fill( pos : Int, size : Int, v : Int ) : Void {
  82. }
  83. @:hlNative("std","bsort_i32")
  84. public function sortI32( pos : Int, length : Int, f : Int->Int->Int ) : Void {
  85. }
  86. @:hlNative("std","bsort_f64")
  87. public function sortF64( pos : Int, length : Int, f : Float->Float->Int ) : Void {
  88. }
  89. /**
  90. Please note that you need to retain the original unoffset'ed Bytes so it does not get garbage collected, unless the pointer was not GC allocated.
  91. **/
  92. @:hlNative("std","bytes_offset")
  93. public function offset( pos : Int ) : hl.types.Bytes {
  94. return null;
  95. }
  96. public function sub( pos : Int, size : Int ) {
  97. var b = new Bytes(size);
  98. b.blit(0, this, pos, size);
  99. return b;
  100. }
  101. @:hlNative("std", "ucs2length")
  102. public function ucs2Length( bytePos : Int ) : Int {
  103. return 0;
  104. }
  105. @:hlNative("std","hash")
  106. function hash() : Int {
  107. return 0;
  108. }
  109. @:hlNative("std","utf8_to_utf16")
  110. public function utf8ToUtf16( bytePos : Int, outSize : Ref<Int> ) : Bytes {
  111. return null;
  112. }
  113. @:hlNative("std","utf16_to_utf8")
  114. public function utf16ToUtf8( bytePos : Int, outSize : Ref<Int> ) : Bytes {
  115. return null;
  116. }
  117. @:hlNative("std", "ucs2_upper")
  118. function ucs2Upper( bytePos : Int, size : Int ) : Bytes {
  119. return null;
  120. }
  121. @:hlNative("std", "ucs2_lower")
  122. function ucs2Lower( bytePos : Int, size : Int ) : Bytes {
  123. return null;
  124. }
  125. @:hlNative("std", "url_encode")
  126. function urlEncode( outSize : Ref<Int> ) : Bytes {
  127. return null;
  128. }
  129. @:hlNative("std", "url_decode")
  130. function urlDecode( outSize : Ref<Int> ) : Bytes {
  131. return null;
  132. }
  133. @:hlNative("std","value_to_string")
  134. public static function ofValue( v : Dynamic, length : Ref<Int> ) : Bytes {
  135. return null;
  136. }
  137. }