UNPKG

@secux/app-sol

Version:
138 lines (130 loc) 5.42 kB
/*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh <https://feross.org> * @license MIT */ /*! Copyright 2022 SecuX Technology Inc Copyright Chen Wei-En Copyright Wu Tsung-Yu Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */ /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */ /** * Support for translating between Uint8Array instances and JavaScript * native types. * * {@link module:Layout~Layout|Layout} is the basis of a class * hierarchy that associates property names with sequences of encoded * bytes. * * Layouts are supported for these scalar (numeric) types: * * {@link module:Layout~UInt|Unsigned integers in little-endian * format} with {@link module:Layout.u8|8-bit}, {@link * module:Layout.u16|16-bit}, {@link module:Layout.u24|24-bit}, * {@link module:Layout.u32|32-bit}, {@link * module:Layout.u40|40-bit}, and {@link module:Layout.u48|48-bit} * representation ranges; * * {@link module:Layout~UIntBE|Unsigned integers in big-endian * format} with {@link module:Layout.u16be|16-bit}, {@link * module:Layout.u24be|24-bit}, {@link module:Layout.u32be|32-bit}, * {@link module:Layout.u40be|40-bit}, and {@link * module:Layout.u48be|48-bit} representation ranges; * * {@link module:Layout~Int|Signed integers in little-endian * format} with {@link module:Layout.s8|8-bit}, {@link * module:Layout.s16|16-bit}, {@link module:Layout.s24|24-bit}, * {@link module:Layout.s32|32-bit}, {@link * module:Layout.s40|40-bit}, and {@link module:Layout.s48|48-bit} * representation ranges; * * {@link module:Layout~IntBE|Signed integers in big-endian format} * with {@link module:Layout.s16be|16-bit}, {@link * module:Layout.s24be|24-bit}, {@link module:Layout.s32be|32-bit}, * {@link module:Layout.s40be|40-bit}, and {@link * module:Layout.s48be|48-bit} representation ranges; * * 64-bit integral values that decode to an exact (if magnitude is * less than 2^53) or nearby integral Number in {@link * module:Layout.nu64|unsigned little-endian}, {@link * module:Layout.nu64be|unsigned big-endian}, {@link * module:Layout.ns64|signed little-endian}, and {@link * module:Layout.ns64be|unsigned big-endian} encodings; * * 32-bit floating point values with {@link * module:Layout.f32|little-endian} and {@link * module:Layout.f32be|big-endian} representations; * * 64-bit floating point values with {@link * module:Layout.f64|little-endian} and {@link * module:Layout.f64be|big-endian} representations; * * {@link module:Layout.const|Constants} that take no space in the * encoded expression. * * and for these aggregate types: * * {@link module:Layout.seq|Sequence}s of instances of a {@link * module:Layout~Layout|Layout}, with JavaScript representation as * an Array and constant or data-dependent {@link * module:Layout~Sequence#count|length}; * * {@link module:Layout.struct|Structure}s that aggregate a * heterogeneous sequence of {@link module:Layout~Layout|Layout} * instances, with JavaScript representation as an Object; * * {@link module:Layout.union|Union}s that support multiple {@link * module:Layout~VariantLayout|variant layouts} over a fixed * (padded) or variable (not padded) span of bytes, using an * unsigned integer at the start of the data or a separate {@link * module:Layout.unionLayoutDiscriminator|layout element} to * determine which layout to use when interpreting the buffer * contents; * * {@link module:Layout.bits|BitStructure}s that contain a sequence * of individual {@link * module:Layout~BitStructure#addField|BitField}s packed into an 8, * 16, 24, or 32-bit unsigned integer starting at the least- or * most-significant bit; * * {@link module:Layout.cstr|C strings} of varying length; * * {@link module:Layout.blob|Blobs} of fixed- or variable-{@link * module:Layout~Blob#length|length} raw data. * * All {@link module:Layout~Layout|Layout} instances are immutable * after construction, to prevent internal state from becoming * inconsistent. * * @local Layout * @local ExternalLayout * @local GreedyCount * @local OffsetLayout * @local UInt * @local UIntBE * @local Int * @local IntBE * @local NearUInt64 * @local NearUInt64BE * @local NearInt64 * @local NearInt64BE * @local Float * @local FloatBE * @local Double * @local DoubleBE * @local Sequence * @local Structure * @local UnionDiscriminator * @local UnionLayoutDiscriminator * @local Union * @local VariantLayout * @local BitStructure * @local BitField * @local Boolean * @local Blob * @local CString * @local Constant * @local bindConstructorLayout * @module Layout * @license MIT * @author Peter A. Bigot * @see {@link https://github.com/pabigot/buffer-layout|buffer-layout on GitHub} */