Bytes.hx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 $bgeti8(this,pos);
  31. }
  32. @:extern @:arrayAccess public inline function setUI8( pos : Int, value : Int ) : Int {
  33. untyped $bseti8(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 getUI8(pos) | (getUI8(pos+1) << 8);
  41. }
  42. public inline function setUI16( pos : Int, v : Int ) {
  43. setUI8(pos, v);
  44. setUI8(pos + 1, v>>8);
  45. }
  46. @:extern public inline function getF32( pos : Int ) : F32 {
  47. return untyped $bgetf32(this,pos);
  48. }
  49. @:extern public inline function getF64( pos : Int ) : Float {
  50. return untyped $bgetf64(this,pos);
  51. }
  52. @:extern public inline function setI32( pos : Int, value : Int ) : Void {
  53. untyped $bseti32(this, pos, value);
  54. }
  55. @:extern public inline function setF32( pos : Int, value : F32 ) : Void {
  56. untyped $bsetf32(this, pos, value);
  57. }
  58. @:extern public inline function setF64( pos : Int, value : Float ) : Void {
  59. untyped $bsetf64(this, pos, value);
  60. }
  61. @:hlNative("std","alloc_bytes")
  62. static function alloc( size : Int ) : Bytes {
  63. return null;
  64. }
  65. @:hlNative("std","parse_int")
  66. public function parseInt( pos : Int, size : Int ) : Null<Int> {
  67. return null;
  68. }
  69. @:hlNative("std","parse_float")
  70. public function parseFloat( pos : Int, size : Int ) : Float {
  71. return 0.;
  72. }
  73. @:hlNative("std","bytes_compare")
  74. public function compare( pos : Int, bytes : Bytes, bytesPos : Int, size : Int ) : Int {
  75. return 0;
  76. }
  77. @:hlNative("std","bytes_find")
  78. public function find( pos : Int, size : Int, bytes : Bytes, bytesPos : Int, bytesSize : Int ) : Int {
  79. return 0;
  80. }
  81. @:hlNative("std","bytes_fill")
  82. public function fill( pos : Int, size : Int, v : Int ) : Void {
  83. }
  84. @:hlNative("std","bsort_i32")
  85. public function sortI32( pos : Int, length : Int, f : Int->Int->Int ) : Void {
  86. }
  87. @:hlNative("std","bsort_f64")
  88. public function sortF64( pos : Int, length : Int, f : Float->Float->Int ) : Void {
  89. }
  90. public function sub( pos : Int, size : Int ) {
  91. var b = new Bytes(size);
  92. b.blit(0, this, pos, size);
  93. return b;
  94. }
  95. @:hlNative("std", "ucs2length")
  96. public function ucs2Length( bytePos : Int ) : Int {
  97. return 0;
  98. }
  99. @:hlNative("std","hash")
  100. function hash() : Int {
  101. return 0;
  102. }
  103. @:hlNative("std","utf8_to_utf16")
  104. public function utf8ToUtf16( bytePos : Int, outSize : Ref<Int> ) : Bytes {
  105. return null;
  106. }
  107. @:hlNative("std","utf16_to_utf8")
  108. public function utf16ToUtf8( bytePos : Int, outSize : Ref<Int> ) : Bytes {
  109. return null;
  110. }
  111. @:hlNative("std", "ucs2_upper")
  112. function ucs2Upper( bytePos : Int, size : Int ) : Bytes {
  113. return null;
  114. }
  115. @:hlNative("std", "ucs2_lower")
  116. function ucs2Lower( bytePos : Int, size : Int ) : Bytes {
  117. return null;
  118. }
  119. @:hlNative("std", "url_encode")
  120. function urlEncode( outSize : Ref<Int> ) : Bytes {
  121. return null;
  122. }
  123. @:hlNative("std", "url_decode")
  124. function urlDecode( outSize : Ref<Int> ) : Bytes {
  125. return null;
  126. }
  127. @:hlNative("std","value_to_string")
  128. public static function ofValue( v : Dynamic, length : Ref<Int> ) : Bytes {
  129. return null;
  130. }
  131. }