@carbonenginejs/runtime-resource 0.11.1 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/dist/CjsResMan.js +4 -4
  2. package/dist/CjsResMan.js.map +1 -1
  3. package/dist/_virtual/_rollupPluginBabelHelpers.js +1 -4
  4. package/dist/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  5. package/dist/format/CjsByteReader.js +310 -0
  6. package/dist/format/CjsByteReader.js.map +1 -0
  7. package/dist/format/CjsByteWriter.js +242 -0
  8. package/dist/format/CjsByteWriter.js.map +1 -0
  9. package/dist/format/CjsFormatError.js +41 -0
  10. package/dist/format/CjsFormatError.js.map +1 -0
  11. package/dist/format/CjsStringTable.js +268 -0
  12. package/dist/format/CjsStringTable.js.map +1 -0
  13. package/dist/format/carbonEffect/CjsCarbonEffectReader.js +361 -0
  14. package/dist/format/carbonEffect/CjsCarbonEffectReader.js.map +1 -0
  15. package/dist/format/carbonEffect/CjsCarbonEffectWriter.js +373 -0
  16. package/dist/format/carbonEffect/CjsCarbonEffectWriter.js.map +1 -0
  17. package/dist/format/carbonEffect/carbonDescriptionFromPortable.js +372 -0
  18. package/dist/format/carbonEffect/carbonDescriptionFromPortable.js.map +1 -0
  19. package/dist/format/carbonEffect/carbonEffectBackendBlock.js +427 -0
  20. package/dist/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -0
  21. package/dist/format/carbonEffect/carbonEffectRecords.js +955 -0
  22. package/dist/format/carbonEffect/carbonEffectRecords.js.map +1 -0
  23. package/dist/format/compareUtf8.js +36 -0
  24. package/dist/format/compareUtf8.js.map +1 -0
  25. package/dist/format/index.js +11 -0
  26. package/dist/format/index.js.map +1 -0
  27. package/dist/formats/bnk/CjsBnkFormat.js +18 -2
  28. package/dist/formats/bnk/CjsBnkFormat.js.map +1 -1
  29. package/dist/formats/bnk/core/eventAction.js +305 -0
  30. package/dist/formats/bnk/core/eventAction.js.map +1 -0
  31. package/dist/formats/bnk/core/graph.js +3 -6
  32. package/dist/formats/bnk/core/graph.js.map +1 -1
  33. package/dist/formats/bnk/core/helpers.js +62 -11
  34. package/dist/formats/bnk/core/helpers.js.map +1 -1
  35. package/dist/formats/bnk/core/nodeBase.js +532 -0
  36. package/dist/formats/bnk/core/nodeBase.js.map +1 -0
  37. package/dist/formats/bnk/core/sfxNodes.js +632 -0
  38. package/dist/formats/bnk/core/sfxNodes.js.map +1 -0
  39. package/dist/formats/bnk/core/soundbanksInfo.js +59 -51
  40. package/dist/formats/bnk/core/soundbanksInfo.js.map +1 -1
  41. package/dist/formats/gr2/CjsGr2Format.js +256 -13
  42. package/dist/formats/gr2/CjsGr2Format.js.map +1 -1
  43. package/dist/formats/gr2/core/helpers.js +15 -15
  44. package/dist/formats/gr2/core/helpers.js.map +1 -1
  45. package/dist/formats/gr2/core/json.js +1 -1
  46. package/dist/formats/gr2/core/json.js.map +1 -1
  47. package/dist/formats/gr2/core/targets.js +1 -1
  48. package/dist/formats/gr2/core/targets.js.map +1 -1
  49. package/dist/formats/gr2/index.js +0 -1
  50. package/dist/formats/gr2/index.js.map +1 -1
  51. package/dist/formats/hlsl/core/HlslReader.js +7 -257
  52. package/dist/formats/hlsl/core/HlslReader.js.map +1 -1
  53. package/dist/formats/hlsl/core/analysis.js +1 -1
  54. package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js +781 -0
  55. package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js.map +1 -0
  56. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js +21 -1
  57. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js.map +1 -1
  58. package/dist/formats/hlsl/index.js +1 -0
  59. package/dist/formats/hlsl/index.js.map +1 -1
  60. package/dist/formats/index.js +3 -6
  61. package/dist/formats/index.js.map +1 -1
  62. package/dist/formats/webgl/core/cewg/CewgPackage.js +2 -1
  63. package/dist/formats/webgl/core/cewg/CewgPackage.js.map +1 -1
  64. package/dist/formats/webgl/core/cewg/binary.js +11 -93
  65. package/dist/formats/webgl/core/cewg/binary.js.map +1 -1
  66. package/dist/formats/webgl/core/effectPackage.js +4 -1
  67. package/dist/formats/webgl/core/effectPackage.js.map +1 -1
  68. package/dist/formats/webgl/core/errors.js +3 -3
  69. package/dist/formats/webgl/core/errors.js.map +1 -1
  70. package/dist/formats/webgpu/CjsWebgpuFormat.js +4 -23
  71. package/dist/formats/webgpu/CjsWebgpuFormat.js.map +1 -1
  72. package/dist/formats/webgpu/core/buildCarbonEffectContainer.js +197 -0
  73. package/dist/formats/webgpu/core/buildCarbonEffectContainer.js.map +1 -0
  74. package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js +368 -0
  75. package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js.map +1 -0
  76. package/dist/formats/webgpu/core/cewgpu/containerViews.js +355 -0
  77. package/dist/formats/webgpu/core/cewgpu/containerViews.js.map +1 -0
  78. package/dist/formats/webgpu/core/cewgpu/validateContainer.js +90 -0
  79. package/dist/formats/webgpu/core/cewgpu/validateContainer.js.map +1 -0
  80. package/dist/formats/webgpu/core/effectBackendBodySet.js +21 -20
  81. package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -1
  82. package/dist/formats/webgpu/core/helpers.js +87 -92
  83. package/dist/formats/webgpu/core/helpers.js.map +1 -1
  84. package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js +14 -13
  85. package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js.map +1 -1
  86. package/dist/formats/webgpu/core/ir/inferValueTypes.js +10 -8
  87. package/dist/formats/webgpu/core/ir/inferValueTypes.js.map +1 -1
  88. package/dist/formats/webgpu/core/packageEffect.js +94 -9
  89. package/dist/formats/webgpu/core/packageEffect.js.map +1 -1
  90. package/dist/formats/webgpu/core/packageMetadata.js +10 -1
  91. package/dist/formats/webgpu/core/packageMetadata.js.map +1 -1
  92. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js +17 -15
  93. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js.map +1 -1
  94. package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js +13 -12
  95. package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js.map +1 -1
  96. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js +9 -8
  97. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js.map +1 -1
  98. package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js +23 -22
  99. package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js.map +1 -1
  100. package/dist/formats/webgpu/core/wgsl/selectionPlans.js +46 -44
  101. package/dist/formats/webgpu/core/wgsl/selectionPlans.js.map +1 -1
  102. package/dist/resource/CjsResource.js +700 -684
  103. package/dist/resource/CjsResource.js.map +1 -1
  104. package/dist/resource/Tr2LightProfileRes.js +18 -27
  105. package/dist/resource/Tr2LightProfileRes.js.map +1 -1
  106. package/dist/resource/audio/CjsAudioBufferRes.js +2 -2
  107. package/dist/resource/audio/CjsAudioBufferRes.js.map +1 -1
  108. package/dist/resource/audio/CjsAudioRes.js +2 -2
  109. package/dist/resource/audio/CjsAudioRes.js.map +1 -1
  110. package/dist/resource/geometry/TriGeometryRes.js +605 -586
  111. package/dist/resource/geometry/TriGeometryRes.js.map +1 -1
  112. package/dist/resource/geometry/granny/Tr2GrannyStateRes.js +21 -30
  113. package/dist/resource/geometry/granny/Tr2GrannyStateRes.js.map +1 -1
  114. package/dist/resource/geometry/granny/TriGrannyRes.js +21 -30
  115. package/dist/resource/geometry/granny/TriGrannyRes.js.map +1 -1
  116. package/dist/resource/shader/Tr2EffectRes.js +9 -7
  117. package/dist/resource/shader/Tr2EffectRes.js.map +1 -1
  118. package/dist/resource/shader/Tr2MaterialArea.js +5 -3
  119. package/dist/resource/shader/Tr2MaterialArea.js.map +1 -1
  120. package/dist/resource/shader/Tr2MaterialMesh.js +4 -2
  121. package/dist/resource/shader/Tr2MaterialMesh.js.map +1 -1
  122. package/dist/resource/shader/Tr2MaterialRes.js +5 -3
  123. package/dist/resource/shader/Tr2MaterialRes.js.map +1 -1
  124. package/dist/resource/shader/Tr2Shader.js +26 -21
  125. package/dist/resource/shader/Tr2Shader.js.map +1 -1
  126. package/dist/resource/shader/Tr2ShaderPermutation.js +8 -6
  127. package/dist/resource/shader/Tr2ShaderPermutation.js.map +1 -1
  128. package/dist/resource/shader/reflection/Tr2EffectDefine.js +5 -3
  129. package/dist/resource/shader/reflection/Tr2EffectDefine.js.map +1 -1
  130. package/dist/resource/shader/reflection/Tr2EffectDescription.js +5 -3
  131. package/dist/resource/shader/reflection/Tr2EffectDescription.js.map +1 -1
  132. package/dist/resource/shader/reflection/Tr2EffectLibrary.js +17 -15
  133. package/dist/resource/shader/reflection/Tr2EffectLibrary.js.map +1 -1
  134. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js +11 -9
  135. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js.map +1 -1
  136. package/dist/resource/shader/reflection/Tr2EffectResource.js +8 -6
  137. package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -1
  138. package/dist/resource/shader/reflection/Tr2EffectStageInput.js +15 -13
  139. package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
  140. package/dist/resource/shader/reflection/Tr2EffectTechnique.js +7 -5
  141. package/dist/resource/shader/reflection/Tr2EffectTechnique.js.map +1 -1
  142. package/dist/resource/shader/reflection/Tr2Pass.js +11 -9
  143. package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -1
  144. package/dist/resource/shader/sampler/Tr2SamplerSetup.js +8 -6
  145. package/dist/resource/shader/sampler/Tr2SamplerSetup.js.map +1 -1
  146. package/dist/resource/texture/CjsTextureArrayRes.js +400 -411
  147. package/dist/resource/texture/CjsTextureArrayRes.js.map +1 -1
  148. package/dist/resource/texture/Tr2ImageRes.js +99 -95
  149. package/dist/resource/texture/Tr2ImageRes.js.map +1 -1
  150. package/dist/resource/texture/TriTextureRes.js +312 -273
  151. package/dist/resource/texture/TriTextureRes.js.map +1 -1
  152. package/docs/README.md +13 -1
  153. package/docs/architecture.md +3 -3
  154. package/docs/concepts/resource-lifecycle.md +9 -2
  155. package/docs/concepts/shader-resource-model.md +114 -0
  156. package/docs/concepts/writing-an-engine-adapter.md +115 -0
  157. package/docs/formats/README.md +24 -1
  158. package/docs/formats/carbon-effect-container.md +452 -0
  159. package/docs/formats/dxbc/README.md +68 -0
  160. package/docs/formats/dxbc/architecture.md +80 -0
  161. package/docs/formats/dxbc/reference/api.md +77 -0
  162. package/docs/formats/dxbc/reference/classes/README.md +9 -0
  163. package/docs/formats/dxbc/reference/decoded-output.md +122 -0
  164. package/docs/formats/gr2.md +3 -4
  165. package/docs/formats/hlsl/README.md +54 -0
  166. package/docs/formats/hlsl/architecture.md +67 -0
  167. package/docs/formats/hlsl/guides/hydrating-json-output.md +62 -0
  168. package/docs/formats/hlsl/guides/reading-effects.md +64 -0
  169. package/docs/formats/hlsl/reference/advanced-analysis.md +66 -0
  170. package/docs/formats/hlsl/reference/api.md +98 -0
  171. package/docs/formats/hlsl/reference/classes/README.md +11 -0
  172. package/docs/formats/hlsl/reference/json-graph.md +100 -0
  173. package/docs/formats/hlsl/reference/portable-reflection.md +141 -0
  174. package/docs/formats/provenance.md +32 -17
  175. package/docs/formats/webgl/README.md +57 -0
  176. package/docs/formats/webgl/architecture.md +70 -0
  177. package/docs/formats/webgl/carbon-constant-layouts.md +326 -0
  178. package/docs/formats/webgl/decl-io.md +1234 -0
  179. package/docs/formats/webgl/effect-reflection.md +127 -0
  180. package/docs/formats/webgl/memory-structured.md +871 -0
  181. package/docs/formats/webgl/reference/classes/README.md +9 -0
  182. package/docs/formats/webgl/texture-sample.md +964 -0
  183. package/docs/formats/webgpu/README.md +84 -0
  184. package/docs/formats/webgpu/architecture.md +96 -0
  185. package/docs/formats/webgpu/formats/cewgpu.md +216 -0
  186. package/docs/formats/webgpu/guides/effect-packaging.md +191 -0
  187. package/docs/formats/webgpu/reference/api.md +197 -0
  188. package/docs/formats/webgpu/reference/classes/README.md +9 -0
  189. package/docs/formats/webgpu/reference/wgsl-compatibility.md +1543 -0
  190. package/docs/formats/wwise.md +45 -4
  191. package/docs/reference/classes/core.md +80 -0
  192. package/docs/reference/classes/formats.md +24 -34
  193. package/docs/reference/events.md +25 -0
  194. package/docs/reference/motherlode-cache.md +22 -8
  195. package/docs/reference/workers.md +5 -5
  196. package/docs/roadmap.md +61 -41
  197. package/format-notices/bnk/NOTICE +5 -4
  198. package/format-notices/webgl/NOTICE +1 -1
  199. package/package.json +2 -1
  200. package/dist/formats/gr2/core/CjsFormatGr2.js +0 -273
  201. package/dist/formats/gr2/core/CjsFormatGr2.js.map +0 -1
  202. package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js +0 -415
  203. package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js.map +0 -1
  204. package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js +0 -100
  205. package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js.map +0 -1
  206. package/dist/formats/webgpu/core/cewgpu/binary.js +0 -93
  207. package/dist/formats/webgpu/core/cewgpu/binary.js.map +0 -1
  208. package/dist/formats/webgpu/core/cewgpu/tags.js +0 -17
  209. package/dist/formats/webgpu/core/cewgpu/tags.js.map +0 -1
  210. package/dist/formats/webgpu/core/effectPackageValidation.js +0 -1078
  211. package/dist/formats/webgpu/core/effectPackageValidation.js.map +0 -1
@@ -121,9 +121,6 @@ function _checkInRHS(e) {
121
121
  if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null"));
122
122
  return e;
123
123
  }
124
- function _identity(t) {
125
- return t;
126
- }
127
124
  function _setFunctionName(e, t, n) {
128
125
  "symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : "");
129
126
  try {
@@ -149,5 +146,5 @@ function _toPropertyKey(t) {
149
146
  return "symbol" == typeof i ? i : i + "";
150
147
  }
151
148
 
152
- export { _applyDecs2311 as applyDecs2311, _checkInRHS as checkInRHS, _identity as identity, _setFunctionName as setFunctionName, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey };
149
+ export { _applyDecs2311 as applyDecs2311, _checkInRHS as checkInRHS, _setFunctionName as setFunctionName, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey };
153
150
  //# sourceMappingURL=_rollupPluginBabelHelpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_rollupPluginBabelHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"_rollupPluginBabelHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,310 @@
1
+ import { CjsReader } from './CjsReader.js';
2
+ import { CjsFormatReadError } from './CjsFormatError.js';
3
+ import { asUint8Array } from '@carbonenginejs/runtime-utils/bytes';
4
+
5
+ const textDecoder = new TextDecoder("utf-8", {
6
+ fatal: false
7
+ });
8
+
9
+ /**
10
+ * Little-endian cursor over resource bytes, with optional string-table arena
11
+ * resolution.
12
+ *
13
+ * This is the shared implementation behind `HlslReader`, `WebglReader`, and
14
+ * the Carbon-effect reader. Specialized readers only
15
+ * replace the error class and the end-of-data message:
16
+ *
17
+ * ```js
18
+ * class MyReader extends CjsByteReader
19
+ * {
20
+ * static ReadError = MyReadError;
21
+ * static endOfDataMessage = "Unexpected end of my data";
22
+ * }
23
+ * ```
24
+ *
25
+ * The arena primitives (`readString`, `readStringAt`, `readStringOptional`,
26
+ * `readTableBlob`, `readTableBlobOptional`) model Carbon's string table, where a
27
+ * single `uint32` offset resolves either to a NUL-terminated string or to a
28
+ * sized blob inside the same arena (`trinity/shadercompiler/StringTable.cpp`).
29
+ */
30
+ class CjsByteReader extends CjsReader {
31
+ /** Error class raised for out-of-bounds and arena failures. */
32
+ static ReadError = CjsFormatReadError;
33
+
34
+ /** Message used when a read would run past the configured end. */
35
+ static endOfDataMessage = "Unexpected end of data";
36
+
37
+ /**
38
+ * Creates a reader over a byte payload and optional shared string table.
39
+ *
40
+ * @param {ArrayBuffer|ArrayBufferView|Uint8Array} bytes Source payload.
41
+ * @param {object} [options] Reader bounds and metadata.
42
+ * @param {number} [options.offset] Initial byte offset.
43
+ * @param {number} [options.end] Exclusive end offset.
44
+ * @param {string} [options.source] Source name used in error details.
45
+ * @param {ArrayBuffer|ArrayBufferView|Uint8Array} [options.stringTable] Arena bytes.
46
+ * @param {number} [options.stringTableSize] Valid arena byte count.
47
+ */
48
+ constructor(bytes, options = {}) {
49
+ super(options);
50
+ this.bytes = asUint8Array(bytes);
51
+ this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);
52
+ this.offset = Number(options.offset) || 0;
53
+ this.end = Number.isInteger(options.end) ? options.end : this.bytes.length;
54
+ this.source = options.source || "memory";
55
+ this.stringTable = options.stringTable ? asUint8Array(options.stringTable) : null;
56
+ this.stringTableSize = Number.isInteger(options.stringTableSize) ? options.stringTableSize : this.stringTable ? this.stringTable.length : 0;
57
+ }
58
+
59
+ /**
60
+ * Attaches or replaces the string-table arena used by string and blob reads.
61
+ *
62
+ * @param {ArrayBuffer|ArrayBufferView|Uint8Array} bytes Arena bytes.
63
+ * @param {number|null} [size] Valid arena byte count.
64
+ */
65
+ setStringTable(bytes, size = null) {
66
+ this.stringTable = asUint8Array(bytes);
67
+ this.stringTableSize = Number.isInteger(size) ? size : this.stringTable.length;
68
+ }
69
+
70
+ /**
71
+ * Returns the unread byte count inside the configured reader bounds.
72
+ *
73
+ * @returns {number} Remaining bytes.
74
+ */
75
+ get remaining() {
76
+ return this.end - this.offset;
77
+ }
78
+
79
+ /**
80
+ * Advances the reader by a fixed number of bytes.
81
+ *
82
+ * @param {number} size Byte count to skip.
83
+ */
84
+ skip(size) {
85
+ this._require(size);
86
+ this.offset += size;
87
+ }
88
+
89
+ /**
90
+ * Reads a byte range from the main payload.
91
+ *
92
+ * @param {number} size Byte count to read.
93
+ * @returns {Uint8Array} View over the read bytes.
94
+ */
95
+ readRaw(size) {
96
+ this._require(size);
97
+ const start = this.offset;
98
+ this.offset += size;
99
+ return this.bytes.subarray(start, start + size);
100
+ }
101
+
102
+ /**
103
+ * Reads an unsigned 8-bit integer.
104
+ *
105
+ * @returns {number} Integer value.
106
+ */
107
+ readUint8() {
108
+ this._require(1);
109
+ const value = this.view.getUint8(this.offset);
110
+ this.offset += 1;
111
+ return value;
112
+ }
113
+
114
+ /**
115
+ * Reads a little-endian unsigned 16-bit integer.
116
+ *
117
+ * @returns {number} Integer value.
118
+ */
119
+ readUint16() {
120
+ this._require(2);
121
+ const value = this.view.getUint16(this.offset, true);
122
+ this.offset += 2;
123
+ return value;
124
+ }
125
+
126
+ /**
127
+ * Reads a little-endian unsigned 32-bit integer.
128
+ *
129
+ * @returns {number} Integer value.
130
+ */
131
+ readUint32() {
132
+ this._require(4);
133
+ const value = this.view.getUint32(this.offset, true);
134
+ this.offset += 4;
135
+ return value;
136
+ }
137
+
138
+ /**
139
+ * Reads a little-endian signed 32-bit integer.
140
+ *
141
+ * @returns {number} Integer value.
142
+ */
143
+ readInt32() {
144
+ this._require(4);
145
+ const value = this.view.getInt32(this.offset, true);
146
+ this.offset += 4;
147
+ return value;
148
+ }
149
+
150
+ /**
151
+ * Reads a little-endian 32-bit float.
152
+ *
153
+ * @returns {number} Float value.
154
+ */
155
+ readFloat32() {
156
+ this._require(4);
157
+ const value = this.view.getFloat32(this.offset, true);
158
+ this.offset += 4;
159
+ return value;
160
+ }
161
+
162
+ /**
163
+ * Reads Carbon's byte-sized boolean encoding.
164
+ *
165
+ * @returns {boolean} Boolean value.
166
+ */
167
+ readBool() {
168
+ return this.readUint8() !== 0;
169
+ }
170
+
171
+ /**
172
+ * Reads a string-table offset and resolves it to a UTF-8 string.
173
+ *
174
+ * @param {number} [sizeHint] Optional maximum byte span for bounds checking.
175
+ * @returns {string} Decoded string.
176
+ */
177
+ readString(sizeHint = 0) {
178
+ const offset = this.readUint32();
179
+ return this.readStringAt(offset, sizeHint);
180
+ }
181
+
182
+ /**
183
+ * Reads an optional string-table offset, returning null for zero-length fields.
184
+ *
185
+ * Carbon consumes the offset word regardless of the length and only
186
+ * dereferences it when the length is non-zero, which is the single site
187
+ * where the `0xffffffff` null reference is legal
188
+ * (`Tr2EffectDescription.cpp:80-91`).
189
+ *
190
+ * @param {number} length Source field length.
191
+ * @returns {string|null} Decoded string or null.
192
+ */
193
+ readStringOptional(length) {
194
+ const offset = this.readUint32();
195
+ if (length === 0) {
196
+ return null;
197
+ }
198
+ return this.readStringAt(offset, length);
199
+ }
200
+
201
+ /**
202
+ * Reads a string-table blob offset and returns the referenced byte range.
203
+ *
204
+ * @param {number} size Blob byte count.
205
+ * @returns {{offset:number,bytes:Uint8Array}} Blob location and bytes.
206
+ */
207
+ readTableBlob(size) {
208
+ const offset = this.readUint32();
209
+ this._requireStringTable(offset, size);
210
+ return {
211
+ offset,
212
+ bytes: this.stringTable.subarray(offset, offset + size)
213
+ };
214
+ }
215
+
216
+ /**
217
+ * Reads a possibly empty string-table blob reference.
218
+ *
219
+ * @param {number} size Blob byte count.
220
+ * @returns {{offset:number,bytes:Uint8Array}} Blob location and bytes.
221
+ */
222
+ readTableBlobOptional(size) {
223
+ const offset = this.readUint32();
224
+ if (size === 0) {
225
+ return {
226
+ offset,
227
+ bytes: new Uint8Array(0)
228
+ };
229
+ }
230
+ this._requireStringTable(offset, size);
231
+ return {
232
+ offset,
233
+ bytes: this.stringTable.subarray(offset, offset + size)
234
+ };
235
+ }
236
+
237
+ /**
238
+ * Resolves a string table offset to a null-terminated UTF-8 string.
239
+ *
240
+ * @param {number} offset String-table byte offset.
241
+ * @param {number} [sizeHint] Optional maximum byte span for bounds checking.
242
+ * @returns {string} Decoded string.
243
+ */
244
+ readStringAt(offset, sizeHint = 0) {
245
+ this._requireStringTable(offset, sizeHint);
246
+ let end = offset;
247
+ while (end < this.stringTableSize && this.stringTable[end] !== 0) {
248
+ end += 1;
249
+ }
250
+ return textDecoder.decode(this.stringTable.subarray(offset, end));
251
+ }
252
+
253
+ /**
254
+ * Creates this reader's error type with shared reader-state details.
255
+ *
256
+ * @param {string} message Human-readable failure reason.
257
+ * @param {object} [details] Extra reader state.
258
+ * @returns {Error} Reader-specific error instance.
259
+ * @protected
260
+ */
261
+ _error(message, details = {}) {
262
+ const ReadError = this.constructor.ReadError ?? CjsFormatReadError;
263
+ return new ReadError(message, {
264
+ source: this.source,
265
+ ...details
266
+ });
267
+ }
268
+
269
+ /**
270
+ * Ensures the requested read fits inside the configured payload bounds.
271
+ *
272
+ * @param {number} size Requested byte count.
273
+ * @private
274
+ */
275
+ _require(size) {
276
+ if (!Number.isInteger(size) || size < 0 || this.offset + size > this.end) {
277
+ throw this._error(this.constructor.endOfDataMessage, {
278
+ offset: this.offset,
279
+ requested: size,
280
+ end: this.end
281
+ });
282
+ }
283
+ }
284
+
285
+ /**
286
+ * Ensures a string-table offset and optional span are valid.
287
+ *
288
+ * @param {number} offset String-table byte offset.
289
+ * @param {number} [sizeHint] Optional byte span for bounds checking.
290
+ * @private
291
+ */
292
+ _requireStringTable(offset, sizeHint = 0) {
293
+ const size = Number(sizeHint) || 0;
294
+ if (!this.stringTable) {
295
+ throw this._error("Missing effect string table", {
296
+ offset
297
+ });
298
+ }
299
+ if (!Number.isInteger(offset) || offset < 0 || offset >= this.stringTableSize || offset + size > this.stringTableSize) {
300
+ throw this._error("Invalid string-table offset", {
301
+ offset,
302
+ sizeHint: size,
303
+ stringTableSize: this.stringTableSize
304
+ });
305
+ }
306
+ }
307
+ }
308
+
309
+ export { CjsByteReader };
310
+ //# sourceMappingURL=CjsByteReader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CjsByteReader.js","sources":["../../../src/format/CjsByteReader.js"],"sourcesContent":["import { CjsReader } from \"./CjsReader.js\";\nimport { CjsFormatReadError } from \"./CjsFormatError.js\";\nimport { asUint8Array } from \"@carbonenginejs/runtime-utils/bytes\";\n\nconst textDecoder = new TextDecoder(\"utf-8\", { fatal: false });\n\n/**\n * Little-endian cursor over resource bytes, with optional string-table arena\n * resolution.\n *\n * This is the shared implementation behind `HlslReader`, `WebglReader`, and\n * the Carbon-effect reader. Specialized readers only\n * replace the error class and the end-of-data message:\n *\n * ```js\n * class MyReader extends CjsByteReader\n * {\n * static ReadError = MyReadError;\n * static endOfDataMessage = \"Unexpected end of my data\";\n * }\n * ```\n *\n * The arena primitives (`readString`, `readStringAt`, `readStringOptional`,\n * `readTableBlob`, `readTableBlobOptional`) model Carbon's string table, where a\n * single `uint32` offset resolves either to a NUL-terminated string or to a\n * sized blob inside the same arena (`trinity/shadercompiler/StringTable.cpp`).\n */\nexport class CjsByteReader extends CjsReader\n{\n /** Error class raised for out-of-bounds and arena failures. */\n static ReadError = CjsFormatReadError;\n\n /** Message used when a read would run past the configured end. */\n static endOfDataMessage = \"Unexpected end of data\";\n\n /**\n * Creates a reader over a byte payload and optional shared string table.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} bytes Source payload.\n * @param {object} [options] Reader bounds and metadata.\n * @param {number} [options.offset] Initial byte offset.\n * @param {number} [options.end] Exclusive end offset.\n * @param {string} [options.source] Source name used in error details.\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} [options.stringTable] Arena bytes.\n * @param {number} [options.stringTableSize] Valid arena byte count.\n */\n constructor(bytes, options = {})\n {\n super(options);\n this.bytes = asUint8Array(bytes);\n this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);\n this.offset = Number(options.offset) || 0;\n this.end = Number.isInteger(options.end) ? options.end : this.bytes.length;\n this.source = options.source || \"memory\";\n this.stringTable = options.stringTable ? asUint8Array(options.stringTable) : null;\n this.stringTableSize = Number.isInteger(options.stringTableSize)\n ? options.stringTableSize\n : (this.stringTable ? this.stringTable.length : 0);\n }\n\n /**\n * Attaches or replaces the string-table arena used by string and blob reads.\n *\n * @param {ArrayBuffer|ArrayBufferView|Uint8Array} bytes Arena bytes.\n * @param {number|null} [size] Valid arena byte count.\n */\n setStringTable(bytes, size = null)\n {\n this.stringTable = asUint8Array(bytes);\n this.stringTableSize = Number.isInteger(size) ? size : this.stringTable.length;\n }\n\n /**\n * Returns the unread byte count inside the configured reader bounds.\n *\n * @returns {number} Remaining bytes.\n */\n get remaining()\n {\n return this.end - this.offset;\n }\n\n /**\n * Advances the reader by a fixed number of bytes.\n *\n * @param {number} size Byte count to skip.\n */\n skip(size)\n {\n this._require(size);\n this.offset += size;\n }\n\n /**\n * Reads a byte range from the main payload.\n *\n * @param {number} size Byte count to read.\n * @returns {Uint8Array} View over the read bytes.\n */\n readRaw(size)\n {\n this._require(size);\n const start = this.offset;\n this.offset += size;\n return this.bytes.subarray(start, start + size);\n }\n\n /**\n * Reads an unsigned 8-bit integer.\n *\n * @returns {number} Integer value.\n */\n readUint8()\n {\n this._require(1);\n const value = this.view.getUint8(this.offset);\n this.offset += 1;\n return value;\n }\n\n /**\n * Reads a little-endian unsigned 16-bit integer.\n *\n * @returns {number} Integer value.\n */\n readUint16()\n {\n this._require(2);\n const value = this.view.getUint16(this.offset, true);\n this.offset += 2;\n return value;\n }\n\n /**\n * Reads a little-endian unsigned 32-bit integer.\n *\n * @returns {number} Integer value.\n */\n readUint32()\n {\n this._require(4);\n const value = this.view.getUint32(this.offset, true);\n this.offset += 4;\n return value;\n }\n\n /**\n * Reads a little-endian signed 32-bit integer.\n *\n * @returns {number} Integer value.\n */\n readInt32()\n {\n this._require(4);\n const value = this.view.getInt32(this.offset, true);\n this.offset += 4;\n return value;\n }\n\n /**\n * Reads a little-endian 32-bit float.\n *\n * @returns {number} Float value.\n */\n readFloat32()\n {\n this._require(4);\n const value = this.view.getFloat32(this.offset, true);\n this.offset += 4;\n return value;\n }\n\n /**\n * Reads Carbon's byte-sized boolean encoding.\n *\n * @returns {boolean} Boolean value.\n */\n readBool()\n {\n return this.readUint8() !== 0;\n }\n\n /**\n * Reads a string-table offset and resolves it to a UTF-8 string.\n *\n * @param {number} [sizeHint] Optional maximum byte span for bounds checking.\n * @returns {string} Decoded string.\n */\n readString(sizeHint = 0)\n {\n const offset = this.readUint32();\n return this.readStringAt(offset, sizeHint);\n }\n\n /**\n * Reads an optional string-table offset, returning null for zero-length fields.\n *\n * Carbon consumes the offset word regardless of the length and only\n * dereferences it when the length is non-zero, which is the single site\n * where the `0xffffffff` null reference is legal\n * (`Tr2EffectDescription.cpp:80-91`).\n *\n * @param {number} length Source field length.\n * @returns {string|null} Decoded string or null.\n */\n readStringOptional(length)\n {\n const offset = this.readUint32();\n if (length === 0)\n {\n return null;\n }\n return this.readStringAt(offset, length);\n }\n\n /**\n * Reads a string-table blob offset and returns the referenced byte range.\n *\n * @param {number} size Blob byte count.\n * @returns {{offset:number,bytes:Uint8Array}} Blob location and bytes.\n */\n readTableBlob(size)\n {\n const offset = this.readUint32();\n this._requireStringTable(offset, size);\n return {\n offset,\n bytes: this.stringTable.subarray(offset, offset + size)\n };\n }\n\n /**\n * Reads a possibly empty string-table blob reference.\n *\n * @param {number} size Blob byte count.\n * @returns {{offset:number,bytes:Uint8Array}} Blob location and bytes.\n */\n readTableBlobOptional(size)\n {\n const offset = this.readUint32();\n if (size === 0)\n {\n return {\n offset,\n bytes: new Uint8Array(0)\n };\n }\n this._requireStringTable(offset, size);\n return {\n offset,\n bytes: this.stringTable.subarray(offset, offset + size)\n };\n }\n\n /**\n * Resolves a string table offset to a null-terminated UTF-8 string.\n *\n * @param {number} offset String-table byte offset.\n * @param {number} [sizeHint] Optional maximum byte span for bounds checking.\n * @returns {string} Decoded string.\n */\n readStringAt(offset, sizeHint = 0)\n {\n this._requireStringTable(offset, sizeHint);\n let end = offset;\n while (end < this.stringTableSize && this.stringTable[end] !== 0)\n {\n end += 1;\n }\n return textDecoder.decode(this.stringTable.subarray(offset, end));\n }\n\n /**\n * Creates this reader's error type with shared reader-state details.\n *\n * @param {string} message Human-readable failure reason.\n * @param {object} [details] Extra reader state.\n * @returns {Error} Reader-specific error instance.\n * @protected\n */\n _error(message, details = {})\n {\n const ReadError = this.constructor.ReadError ?? CjsFormatReadError;\n return new ReadError(message, { source: this.source, ...details });\n }\n\n /**\n * Ensures the requested read fits inside the configured payload bounds.\n *\n * @param {number} size Requested byte count.\n * @private\n */\n _require(size)\n {\n if (!Number.isInteger(size) || size < 0 || this.offset + size > this.end)\n {\n throw this._error(this.constructor.endOfDataMessage, {\n offset: this.offset,\n requested: size,\n end: this.end\n });\n }\n }\n\n /**\n * Ensures a string-table offset and optional span are valid.\n *\n * @param {number} offset String-table byte offset.\n * @param {number} [sizeHint] Optional byte span for bounds checking.\n * @private\n */\n _requireStringTable(offset, sizeHint = 0)\n {\n const size = Number(sizeHint) || 0;\n if (!this.stringTable)\n {\n throw this._error(\"Missing effect string table\", { offset });\n }\n if (!Number.isInteger(offset) || offset < 0 || offset >= this.stringTableSize || offset + size > this.stringTableSize)\n {\n throw this._error(\"Invalid string-table offset\", {\n offset,\n sizeHint: size,\n stringTableSize: this.stringTableSize\n });\n }\n }\n}\n\nexport default CjsByteReader;\n"],"names":["textDecoder","TextDecoder","fatal","CjsByteReader","CjsReader","ReadError","CjsFormatReadError","endOfDataMessage","constructor","bytes","options","asUint8Array","view","DataView","buffer","byteOffset","byteLength","offset","Number","end","isInteger","length","source","stringTable","stringTableSize","setStringTable","size","remaining","skip","_require","readRaw","start","subarray","readUint8","value","getUint8","readUint16","getUint16","readUint32","getUint32","readInt32","getInt32","readFloat32","getFloat32","readBool","readString","sizeHint","readStringAt","readStringOptional","readTableBlob","_requireStringTable","readTableBlobOptional","Uint8Array","decode","_error","message","details","requested"],"mappings":";;;;AAIA,MAAMA,WAAW,GAAG,IAAIC,WAAW,CAAC,OAAO,EAAE;AAAEC,EAAAA,KAAK,EAAE;AAAM,CAAC,CAAC;;AAE9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,aAAa,SAASC,SAAS,CAC5C;AACI;EACA,OAAOC,SAAS,GAAGC,kBAAkB;;AAErC;EACA,OAAOC,gBAAgB,GAAG,wBAAwB;;AAElD;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACIC,EAAAA,WAAWA,CAACC,KAAK,EAAEC,OAAO,GAAG,EAAE,EAC/B;IACI,KAAK,CAACA,OAAO,CAAC;AACd,IAAA,IAAI,CAACD,KAAK,GAAGE,YAAY,CAACF,KAAK,CAAC;IAChC,IAAI,CAACG,IAAI,GAAG,IAAIC,QAAQ,CAAC,IAAI,CAACJ,KAAK,CAACK,MAAM,EAAE,IAAI,CAACL,KAAK,CAACM,UAAU,EAAE,IAAI,CAACN,KAAK,CAACO,UAAU,CAAC;IACzF,IAAI,CAACC,MAAM,GAAGC,MAAM,CAACR,OAAO,CAACO,MAAM,CAAC,IAAI,CAAC;IACzC,IAAI,CAACE,GAAG,GAAGD,MAAM,CAACE,SAAS,CAACV,OAAO,CAACS,GAAG,CAAC,GAAGT,OAAO,CAACS,GAAG,GAAG,IAAI,CAACV,KAAK,CAACY,MAAM;AAC1E,IAAA,IAAI,CAACC,MAAM,GAAGZ,OAAO,CAACY,MAAM,IAAI,QAAQ;AACxC,IAAA,IAAI,CAACC,WAAW,GAAGb,OAAO,CAACa,WAAW,GAAGZ,YAAY,CAACD,OAAO,CAACa,WAAW,CAAC,GAAG,IAAI;IACjF,IAAI,CAACC,eAAe,GAAGN,MAAM,CAACE,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MAAM,EAAE,IAAI,CAACA,MAAM;AACnBwC,QAAAA,SAAS,EAAE/B,IAAI;QACfP,GAAG,EAAE,IAAI,CAACA;AACd,OAAC,CAAC;AACN,IAAA;AACJ,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;AACA;AACI+B,EAAAA,mBAAmBA,CAACjC,MAAM,EAAE6B,QAAQ,GAAG,CAAC,EACxC;AACI,IAAA,MAAMpB,IAAI,GAAGR,MAAM,CAAC4B,QAAQ,CAAC,IAAI,CAAC;AAClC,IAAA,IAAI,CAAC,IAAI,CAACvB,WAAW,EACrB;AACI,MAAA,MAAM,IAAI,CAAC+B,MAAM,CAAC,6BAA6B,EAAE;AAAErC,QAAAA;AAAO,OAAC,CAAC;AAChE,IAAA;IACA,IAAI,CAACC,MAAM,CAACE,SAAS,CAACH,MAAM,CAAC,IAAIA,MAAM,GAAG,CAAC,IAAIA,MAAM,IAAI,IAAI,CAACO,eAAe,IAAIP,MAAM,GAAGS,IAAI,GAAG,IAAI,CAACF,eAAe,EACrH;AACI,MAAA,MAAM,IAAI,CAAC8B,MAAM,CAAC,6BAA6B,EAAE;QAC7CrC,MAAM;AACN6B,QAAAA,QAAQ,EAAEpB,IAAI;QACdF,eAAe,EAAE,IAAI,CAACA;AAC1B,OAAC,CAAC;AACN,IAAA;AACJ,EAAA;AACJ;;;;"}
@@ -0,0 +1,242 @@
1
+ import { CjsFormatWriteError } from './CjsFormatError.js';
2
+
3
+ const textEncoder = new TextEncoder();
4
+
5
+ /**
6
+ * Growable little-endian append cursor with reserve-and-patch support.
7
+ *
8
+ * `formats/cmf/core/writer.js` already has a growable buffer, but it is
9
+ * patch-style throughout: every write takes an explicit offset produced by a
10
+ * prior `reserve`. Container assembly wants the opposite default — append in
11
+ * field order — with patching kept for the one case that needs it, an offset
12
+ * table whose values are only known after the payload it points at has been
13
+ * measured.
14
+ *
15
+ * Every append returns the offset it wrote at, so the reserve-and-patch case is
16
+ * just "keep the offset an append returned".
17
+ */
18
+ class CjsByteWriter {
19
+ #bytes;
20
+ #view;
21
+ #length = 0;
22
+
23
+ /**
24
+ * Creates an empty writer with an initial capacity.
25
+ *
26
+ * @param {number} [initialCapacity] Starting buffer size in bytes.
27
+ */
28
+ constructor(initialCapacity = 1024) {
29
+ const capacity = Number.isInteger(initialCapacity) && initialCapacity > 0 ? initialCapacity : 1024;
30
+ this.#bytes = new Uint8Array(capacity);
31
+ this.#view = new DataView(this.#bytes.buffer);
32
+ }
33
+
34
+ /**
35
+ * Returns the number of bytes written so far.
36
+ *
37
+ * @returns {number} Written byte count.
38
+ */
39
+ get length() {
40
+ return this.#length;
41
+ }
42
+
43
+ /**
44
+ * Appends an unsigned 8-bit integer.
45
+ *
46
+ * @param {number} value Integer value.
47
+ * @returns {number} Offset the value was written at.
48
+ */
49
+ u8(value) {
50
+ const offset = this.#advance(1);
51
+ this.#view.setUint8(offset, value & 0xff);
52
+ return offset;
53
+ }
54
+
55
+ /**
56
+ * Appends a little-endian unsigned 16-bit integer.
57
+ *
58
+ * @param {number} value Integer value.
59
+ * @returns {number} Offset the value was written at.
60
+ */
61
+ u16(value) {
62
+ const offset = this.#advance(2);
63
+ this.#view.setUint16(offset, value & 0xffff, true);
64
+ return offset;
65
+ }
66
+
67
+ /**
68
+ * Appends a little-endian unsigned 32-bit integer.
69
+ *
70
+ * @param {number} value Integer value.
71
+ * @returns {number} Offset the value was written at.
72
+ */
73
+ u32(value) {
74
+ const offset = this.#advance(4);
75
+ this.#view.setUint32(offset, value >>> 0, true);
76
+ return offset;
77
+ }
78
+
79
+ /**
80
+ * Appends a little-endian signed 32-bit integer.
81
+ *
82
+ * @param {number} value Integer value.
83
+ * @returns {number} Offset the value was written at.
84
+ */
85
+ i32(value) {
86
+ const offset = this.#advance(4);
87
+ this.#view.setInt32(offset, value | 0, true);
88
+ return offset;
89
+ }
90
+
91
+ /**
92
+ * Appends a little-endian 32-bit float.
93
+ *
94
+ * @param {number} value Float value.
95
+ * @returns {number} Offset the value was written at.
96
+ */
97
+ f32(value) {
98
+ const offset = this.#advance(4);
99
+ this.#view.setFloat32(offset, Number(value) || 0, true);
100
+ return offset;
101
+ }
102
+
103
+ /**
104
+ * Appends Carbon's byte-sized boolean encoding.
105
+ *
106
+ * @param {boolean} value Boolean value.
107
+ * @returns {number} Offset the value was written at.
108
+ */
109
+ bool(value) {
110
+ return this.u8(value ? 1 : 0);
111
+ }
112
+
113
+ /**
114
+ * Appends raw bytes.
115
+ *
116
+ * @param {ArrayBufferView|Uint8Array} value Bytes to append.
117
+ * @returns {number} Offset the bytes were written at.
118
+ */
119
+ bytes(value) {
120
+ const source = value instanceof Uint8Array ? value : new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
121
+ const offset = this.#advance(source.byteLength);
122
+ this.#bytes.set(source, offset);
123
+ return offset;
124
+ }
125
+
126
+ /**
127
+ * Appends UTF-8 text without a terminator.
128
+ *
129
+ * @param {string} value Text to append.
130
+ * @returns {number} Offset the text was written at.
131
+ */
132
+ utf8(value) {
133
+ return this.bytes(textEncoder.encode(String(value)));
134
+ }
135
+
136
+ /**
137
+ * Appends a run of zero bytes and returns its offset, for later patching.
138
+ *
139
+ * @param {number} count Byte count to reserve.
140
+ * @returns {number} Offset of the reserved run.
141
+ */
142
+ reserve(count) {
143
+ if (!Number.isInteger(count) || count < 0) {
144
+ throw new CjsFormatWriteError("Reserve count must be a non-negative integer", {
145
+ count
146
+ });
147
+ }
148
+ const offset = this.#advance(count);
149
+ this.#bytes.fill(0, offset, offset + count);
150
+ return offset;
151
+ }
152
+
153
+ /**
154
+ * Overwrites a previously written unsigned 8-bit integer.
155
+ *
156
+ * @param {number} offset Target offset.
157
+ * @param {number} value Integer value.
158
+ */
159
+ patchU8(offset, value) {
160
+ this.#requireWritten(offset, 1);
161
+ this.#view.setUint8(offset, value & 0xff);
162
+ }
163
+
164
+ /**
165
+ * Overwrites a previously written little-endian unsigned 32-bit integer.
166
+ *
167
+ * @param {number} offset Target offset.
168
+ * @param {number} value Integer value.
169
+ */
170
+ patchU32(offset, value) {
171
+ this.#requireWritten(offset, 4);
172
+ this.#view.setUint32(offset, value >>> 0, true);
173
+ }
174
+
175
+ /**
176
+ * Overwrites a previously written byte range.
177
+ *
178
+ * @param {number} offset Target offset.
179
+ * @param {ArrayBufferView|Uint8Array} value Replacement bytes.
180
+ */
181
+ patchBytes(offset, value) {
182
+ const source = value instanceof Uint8Array ? value : new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
183
+ this.#requireWritten(offset, source.byteLength);
184
+ this.#bytes.set(source, offset);
185
+ }
186
+
187
+ /**
188
+ * Returns an owned copy of the written bytes.
189
+ *
190
+ * @returns {Uint8Array} Written payload.
191
+ */
192
+ toBytes() {
193
+ return this.#bytes.slice(0, this.#length);
194
+ }
195
+
196
+ /**
197
+ * Grows the buffer when a write would exceed capacity.
198
+ *
199
+ * @param {number} capacity Required total capacity.
200
+ */
201
+ #ensure(capacity) {
202
+ if (capacity <= this.#bytes.length) return;
203
+ let next = this.#bytes.length * 2;
204
+ while (next < capacity) next *= 2;
205
+ const grown = new Uint8Array(next);
206
+ grown.set(this.#bytes.subarray(0, this.#length));
207
+ this.#bytes = grown;
208
+ this.#view = new DataView(grown.buffer);
209
+ }
210
+
211
+ /**
212
+ * Reserves space for one append and returns the offset it starts at.
213
+ *
214
+ * @param {number} size Byte count for this append.
215
+ * @returns {number} Offset of the appended run.
216
+ */
217
+ #advance(size) {
218
+ const offset = this.#length;
219
+ this.#ensure(offset + size);
220
+ this.#length = offset + size;
221
+ return offset;
222
+ }
223
+
224
+ /**
225
+ * Rejects a patch that falls outside the bytes already written.
226
+ *
227
+ * @param {number} offset Target offset.
228
+ * @param {number} size Patch byte count.
229
+ */
230
+ #requireWritten(offset, size) {
231
+ if (!Number.isInteger(offset) || offset < 0 || offset + size > this.#length) {
232
+ throw new CjsFormatWriteError("Patch target is outside the written range", {
233
+ offset,
234
+ size,
235
+ length: this.#length
236
+ });
237
+ }
238
+ }
239
+ }
240
+
241
+ export { CjsByteWriter };
242
+ //# sourceMappingURL=CjsByteWriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CjsByteWriter.js","sources":["../../../src/format/CjsByteWriter.js"],"sourcesContent":["import { CjsFormatWriteError } from \"./CjsFormatError.js\";\n\nconst textEncoder = new TextEncoder();\n\n/**\n * Growable little-endian append cursor with reserve-and-patch support.\n *\n * `formats/cmf/core/writer.js` already has a growable buffer, but it is\n * patch-style throughout: every write takes an explicit offset produced by a\n * prior `reserve`. Container assembly wants the opposite default — append in\n * field order — with patching kept for the one case that needs it, an offset\n * table whose values are only known after the payload it points at has been\n * measured.\n *\n * Every append returns the offset it wrote at, so the reserve-and-patch case is\n * just \"keep the offset an append returned\".\n */\nexport class CjsByteWriter\n{\n #bytes;\n #view;\n #length = 0;\n\n /**\n * Creates an empty writer with an initial capacity.\n *\n * @param {number} [initialCapacity] Starting buffer size in bytes.\n */\n constructor(initialCapacity = 1024)\n {\n const capacity = Number.isInteger(initialCapacity) && initialCapacity > 0 ? initialCapacity : 1024;\n this.#bytes = new Uint8Array(capacity);\n this.#view = new DataView(this.#bytes.buffer);\n }\n\n /**\n * Returns the number of bytes written so far.\n *\n * @returns {number} Written byte count.\n */\n get length()\n {\n return this.#length;\n }\n\n /**\n * Appends an unsigned 8-bit integer.\n *\n * @param {number} value Integer value.\n * @returns {number} Offset the value was written at.\n */\n u8(value)\n {\n const offset = this.#advance(1);\n this.#view.setUint8(offset, value & 0xff);\n return offset;\n }\n\n /**\n * Appends a little-endian unsigned 16-bit integer.\n *\n * @param {number} value Integer value.\n * @returns {number} Offset the value was written at.\n */\n u16(value)\n {\n const offset = this.#advance(2);\n this.#view.setUint16(offset, value & 0xffff, true);\n return offset;\n }\n\n /**\n * Appends a little-endian unsigned 32-bit integer.\n *\n * @param {number} value Integer value.\n * @returns {number} Offset the value was written at.\n */\n u32(value)\n {\n const offset = this.#advance(4);\n this.#view.setUint32(offset, value >>> 0, true);\n return offset;\n }\n\n /**\n * Appends a little-endian signed 32-bit integer.\n *\n * @param {number} value Integer value.\n * @returns {number} Offset the value was written at.\n */\n i32(value)\n {\n const offset = this.#advance(4);\n this.#view.setInt32(offset, value | 0, true);\n return offset;\n }\n\n /**\n * Appends a little-endian 32-bit float.\n *\n * @param {number} value Float value.\n * @returns {number} Offset the value was written at.\n */\n f32(value)\n {\n const offset = this.#advance(4);\n this.#view.setFloat32(offset, Number(value) || 0, true);\n return offset;\n }\n\n /**\n * Appends Carbon's byte-sized boolean encoding.\n *\n * @param {boolean} value Boolean value.\n * @returns {number} Offset the value was written at.\n */\n bool(value)\n {\n return this.u8(value ? 1 : 0);\n }\n\n /**\n * Appends raw bytes.\n *\n * @param {ArrayBufferView|Uint8Array} value Bytes to append.\n * @returns {number} Offset the bytes were written at.\n */\n bytes(value)\n {\n const source = value instanceof Uint8Array\n ? value\n : new Uint8Array(value.buffer, value.byteOffset, value.byteLength);\n const offset = this.#advance(source.byteLength);\n this.#bytes.set(source, offset);\n return offset;\n }\n\n /**\n * Appends UTF-8 text without a terminator.\n *\n * @param {string} value Text to append.\n * @returns {number} Offset the text was written at.\n */\n utf8(value)\n {\n return this.bytes(textEncoder.encode(String(value)));\n }\n\n /**\n * Appends a run of zero bytes and returns its offset, for later patching.\n *\n * @param {number} count Byte count to reserve.\n * @returns {number} Offset of the reserved run.\n */\n reserve(count)\n {\n if (!Number.isInteger(count) || count < 0)\n {\n throw new CjsFormatWriteError(\"Reserve count must be a non-negative integer\", { count });\n }\n const offset = this.#advance(count);\n this.#bytes.fill(0, offset, offset + count);\n return offset;\n }\n\n /**\n * Overwrites a previously written unsigned 8-bit integer.\n *\n * @param {number} offset Target offset.\n * @param {number} value Integer value.\n */\n patchU8(offset, value)\n {\n this.#requireWritten(offset, 1);\n this.#view.setUint8(offset, value & 0xff);\n }\n\n /**\n * Overwrites a previously written little-endian unsigned 32-bit integer.\n *\n * @param {number} offset Target offset.\n * @param {number} value Integer value.\n */\n patchU32(offset, value)\n {\n this.#requireWritten(offset, 4);\n this.#view.setUint32(offset, value >>> 0, true);\n }\n\n /**\n * Overwrites a previously written byte range.\n *\n * @param {number} offset Target offset.\n * @param {ArrayBufferView|Uint8Array} value Replacement bytes.\n */\n patchBytes(offset, value)\n {\n const source = value instanceof Uint8Array\n ? value\n : new Uint8Array(value.buffer, value.byteOffset, value.byteLength);\n this.#requireWritten(offset, source.byteLength);\n this.#bytes.set(source, offset);\n }\n\n /**\n * Returns an owned copy of the written bytes.\n *\n * @returns {Uint8Array} Written payload.\n */\n toBytes()\n {\n return this.#bytes.slice(0, this.#length);\n }\n\n /**\n * Grows the buffer when a write would exceed capacity.\n *\n * @param {number} capacity Required total capacity.\n */\n #ensure(capacity)\n {\n if (capacity <= this.#bytes.length) return;\n let next = this.#bytes.length * 2;\n while (next < capacity) next *= 2;\n const grown = new Uint8Array(next);\n grown.set(this.#bytes.subarray(0, this.#length));\n this.#bytes = grown;\n this.#view = new DataView(grown.buffer);\n }\n\n /**\n * Reserves space for one append and returns the offset it starts at.\n *\n * @param {number} size Byte count for this append.\n * @returns {number} Offset of the appended run.\n */\n #advance(size)\n {\n const offset = this.#length;\n this.#ensure(offset + size);\n this.#length = offset + size;\n return offset;\n }\n\n /**\n * Rejects a patch that falls outside the bytes already written.\n *\n * @param {number} offset Target offset.\n * @param {number} size Patch byte count.\n */\n #requireWritten(offset, size)\n {\n if (!Number.isInteger(offset) || offset < 0 || offset + size > this.#length)\n {\n throw new CjsFormatWriteError(\"Patch target is outside the written range\", {\n offset,\n size,\n length: this.#length\n });\n }\n }\n}\n\nexport default CjsByteWriter;\n"],"names":["textEncoder","TextEncoder","CjsByteWriter","constructor","initialCapacity","capacity","Number","isInteger","Uint8Array","DataView","buffer","length","u8","value","offset","setUint8","u16","setUint16","u32","setUint32","i32","setInt32","f32","setFloat32","bool","bytes","source","byteOffset","byteLength","set","utf8","encode","String","reserve","count","CjsFormatWriteError","fill","patchU8","patchU32","patchBytes","toBytes","slice","#ensure","next","grown","subarray","#advance","size","#requireWritten"],"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AC;AAC3B,IAAA,IAAI,CAAC,OAAO,GAAGjC,MAAM,GAAGiC,IAAI;AAC5B,IAAA,OAAOjC,MAAM;AACjB,EAAA;;AAEA;AACJ;AACA;AACA;AACA;AACA;AACI,EAAA,eAAekC,CAAClC,MAAM,EAAEiC,IAAI,EAC5B;IACI,IAAI,CAACzC,MAAM,CAACC,SAAS,CAACO,MAAM,CAAC,IAAIA,MAAM,GAAG,CAAC,IAAIA,MAAM,GAAGiC,IAAI,GAAG,IAAI,CAAC,OAAO,EAC3E;AACI,MAAA,MAAM,IAAIZ,mBAAmB,CAAC,2CAA2C,EAAE;QACvErB,MAAM;QACNiC,IAAI;QACJpC,MAAM,EAAE,IAAI,CAAC;AACjB,OAAC,CAAC;AACN,IAAA;AACJ,EAAA;AACJ;;;;"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Error raised when shared binary format bytes cannot be decoded safely.
3
+ *
4
+ * Format-specific readers substitute their own error class through the
5
+ * `ReadError` static on `CjsByteReader`, so this type is the fallback for
6
+ * readers that do not need a distinguishable name.
7
+ */
8
+ class CjsFormatReadError extends Error {
9
+ /**
10
+ * Creates a read error with structured reader-state details.
11
+ *
12
+ * @param {string} message Human-readable failure reason.
13
+ * @param {object} [details] Extra reader state such as source, offset, or size.
14
+ */
15
+ constructor(message, details = {}) {
16
+ super(message);
17
+ this.name = "CjsFormatReadError";
18
+ this.details = details;
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Error raised when shared binary format bytes cannot be encoded safely.
24
+ */
25
+ class CjsFormatWriteError extends Error {
26
+ /**
27
+ * Creates a write error with structured writer-state details.
28
+ *
29
+ * @param {string} message Human-readable failure reason.
30
+ * @param {object} [details] Extra writer state such as offset or value.
31
+ */
32
+ constructor(message, details = {}) {
33
+ super(message);
34
+ this.name = "CjsFormatWriteError";
35
+ this.code = "CJS_FORMAT_WRITE_ERROR";
36
+ this.details = details;
37
+ }
38
+ }
39
+
40
+ export { CjsFormatReadError, CjsFormatWriteError };
41
+ //# sourceMappingURL=CjsFormatError.js.map