2023-11-27 18:48:37 +03:00
|
|
|
// Automatically generated by the FlatBuffers compiler (flatc version 1.12.0),
|
2023-10-07 23:57:47 +03:00
|
|
|
// and modified by inlining the `flatbuffers` dependency and switching from manual decoding
|
|
|
|
// to a `DataView`.
|
|
|
|
// Helper classes copied from https://github.com/google/flatbuffers,
|
|
|
|
// which is licensed under the Apache License, Version 2.0:
|
|
|
|
/*
|
|
|
|
|
|
|
|
Apache License
|
|
|
|
Version 2.0, January 2004
|
|
|
|
http://www.apache.org/licenses/
|
|
|
|
|
|
|
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
|
|
|
|
|
|
1. Definitions.
|
|
|
|
|
|
|
|
"License" shall mean the terms and conditions for use, reproduction,
|
|
|
|
and distribution as defined by Sections 1 through 9 of this document.
|
|
|
|
|
|
|
|
"Licensor" shall mean the copyright owner or entity authorized by
|
|
|
|
the copyright owner that is granting the License.
|
|
|
|
|
|
|
|
"Legal Entity" shall mean the union of the acting entity and all
|
|
|
|
other entities that control, are controlled by, or are under common
|
|
|
|
control with that entity. For the purposes of this definition,
|
|
|
|
"control" means (i) the power, direct or indirect, to cause the
|
|
|
|
direction or management of such entity, whether by contract or
|
|
|
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
|
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
|
|
|
|
|
|
"You" (or "Your") shall mean an individual or Legal Entity
|
|
|
|
exercising permissions granted by this License.
|
|
|
|
|
|
|
|
"Source" form shall mean the preferred form for making modifications,
|
|
|
|
including but not limited to software source code, documentation
|
|
|
|
source, and configuration files.
|
|
|
|
|
|
|
|
"Object" form shall mean any form resulting from mechanical
|
|
|
|
transformation or translation of a Source form, including but
|
|
|
|
not limited to compiled object code, generated documentation,
|
|
|
|
and conversions to other media types.
|
|
|
|
|
|
|
|
"Work" shall mean the work of authorship, whether in Source or
|
|
|
|
Object form, made available under the License, as indicated by a
|
|
|
|
copyright notice that is included in or attached to the work
|
|
|
|
(an example is provided in the Appendix below).
|
|
|
|
|
|
|
|
"Derivative Works" shall mean any work, whether in Source or Object
|
|
|
|
form, that is based on (or derived from) the Work and for which the
|
|
|
|
editorial revisions, annotations, elaborations, or other modifications
|
|
|
|
represent, as a whole, an original work of authorship. For the purposes
|
|
|
|
of this License, Derivative Works shall not include works that remain
|
|
|
|
separable from, or merely link (or bind by name) to the interfaces of,
|
|
|
|
the Work and Derivative Works thereof.
|
|
|
|
|
|
|
|
"Contribution" shall mean any work of authorship, including
|
|
|
|
the original version of the Work and any modifications or additions
|
|
|
|
to that Work or Derivative Works thereof, that is intentionally
|
|
|
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
|
|
or by an individual or Legal Entity authorized to submit on behalf of
|
|
|
|
the copyright owner. For the purposes of this definition, "submitted"
|
|
|
|
means any form of electronic, verbal, or written communication sent
|
|
|
|
to the Licensor or its representatives, including but not limited to
|
|
|
|
communication on electronic mailing lists, source code control systems,
|
|
|
|
and issue tracking systems that are managed by, or on behalf of, the
|
|
|
|
Licensor for the purpose of discussing and improving the Work, but
|
|
|
|
excluding communication that is conspicuously marked or otherwise
|
|
|
|
designated in writing by the copyright owner as "Not a Contribution."
|
|
|
|
|
|
|
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
|
|
on behalf of whom a Contribution has been received by Licensor and
|
|
|
|
subsequently incorporated within the Work.
|
|
|
|
|
|
|
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
|
|
this License, each Contributor hereby grants to You a perpetual,
|
|
|
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
|
|
copyright license to reproduce, prepare Derivative Works of,
|
|
|
|
publicly display, publicly perform, sublicense, and distribute the
|
|
|
|
Work and such Derivative Works in Source or Object form.
|
|
|
|
|
|
|
|
3. Grant of Patent License. Subject to the terms and conditions of
|
|
|
|
this License, each Contributor hereby grants to You a perpetual,
|
|
|
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
|
|
(except as stated in this section) patent license to make, have made,
|
|
|
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
|
|
where such license applies only to those patent claims licensable
|
|
|
|
by such Contributor that are necessarily infringed by their
|
|
|
|
Contribution(s) alone or by combination of their Contribution(s)
|
|
|
|
with the Work to which such Contribution(s) was submitted. If You
|
|
|
|
institute patent litigation against any entity (including a
|
|
|
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
|
|
or a Contribution incorporated within the Work constitutes direct
|
|
|
|
or contributory patent infringement, then any patent licenses
|
|
|
|
granted to You under this License for that Work shall terminate
|
|
|
|
as of the date such litigation is filed.
|
|
|
|
|
|
|
|
4. Redistribution. You may reproduce and distribute copies of the
|
|
|
|
Work or Derivative Works thereof in any medium, with or without
|
|
|
|
modifications, and in Source or Object form, provided that You
|
|
|
|
meet the following conditions:
|
|
|
|
|
|
|
|
(a) You must give any other recipients of the Work or
|
|
|
|
Derivative Works a copy of this License; and
|
|
|
|
|
|
|
|
(b) You must cause any modified files to carry prominent notices
|
|
|
|
stating that You changed the files; and
|
|
|
|
|
|
|
|
(c) You must retain, in the Source form of any Derivative Works
|
|
|
|
that You distribute, all copyright, patent, trademark, and
|
|
|
|
attribution notices from the Source form of the Work,
|
|
|
|
excluding those notices that do not pertain to any part of
|
|
|
|
the Derivative Works; and
|
|
|
|
|
|
|
|
(d) If the Work includes a "NOTICE" text file as part of its
|
|
|
|
distribution, then any Derivative Works that You distribute must
|
|
|
|
include a readable copy of the attribution notices contained
|
|
|
|
within such NOTICE file, excluding those notices that do not
|
|
|
|
pertain to any part of the Derivative Works, in at least one
|
|
|
|
of the following places: within a NOTICE text file distributed
|
|
|
|
as part of the Derivative Works; within the Source form or
|
|
|
|
documentation, if provided along with the Derivative Works; or,
|
|
|
|
within a display generated by the Derivative Works, if and
|
|
|
|
wherever such third-party notices normally appear. The contents
|
|
|
|
of the NOTICE file are for informational purposes only and
|
|
|
|
do not modify the License. You may add Your own attribution
|
|
|
|
notices within Derivative Works that You distribute, alongside
|
|
|
|
or as an addendum to the NOTICE text from the Work, provided
|
|
|
|
that such additional attribution notices cannot be construed
|
|
|
|
as modifying the License.
|
|
|
|
|
|
|
|
You may add Your own copyright statement to Your modifications and
|
|
|
|
may provide additional or different license terms and conditions
|
|
|
|
for use, reproduction, or distribution of Your modifications, or
|
|
|
|
for any such Derivative Works as a whole, provided Your use,
|
|
|
|
reproduction, and distribution of the Work otherwise complies with
|
|
|
|
the conditions stated in this License.
|
|
|
|
|
|
|
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
|
|
any Contribution intentionally submitted for inclusion in the Work
|
|
|
|
by You to the Licensor shall be under the terms and conditions of
|
|
|
|
this License, without any additional terms or conditions.
|
|
|
|
Notwithstanding the above, nothing herein shall supersede or modify
|
|
|
|
the terms of any separate license agreement you may have executed
|
|
|
|
with Licensor regarding such Contributions.
|
|
|
|
|
|
|
|
6. Trademarks. This License does not grant permission to use the trade
|
|
|
|
names, trademarks, service marks, or product names of the Licensor,
|
|
|
|
except as required for reasonable and customary use in describing the
|
|
|
|
origin of the Work and reproducing the content of the NOTICE file.
|
|
|
|
|
|
|
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
|
|
agreed to in writing, Licensor provides the Work (and each
|
|
|
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
|
|
implied, including, without limitation, any warranties or conditions
|
|
|
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
|
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
|
|
appropriateness of using or redistributing the Work and assume any
|
|
|
|
risks associated with Your exercise of permissions under this License.
|
|
|
|
|
|
|
|
8. Limitation of Liability. In no event and under no legal theory,
|
|
|
|
whether in tort (including negligence), contract, or otherwise,
|
|
|
|
unless required by applicable law (such as deliberate and grossly
|
|
|
|
negligent acts) or agreed to in writing, shall any Contributor be
|
|
|
|
liable to You for damages, including any direct, indirect, special,
|
|
|
|
incidental, or consequential damages of any character arising as a
|
|
|
|
result of this License or out of the use or inability to use the
|
|
|
|
Work (including but not limited to damages for loss of goodwill,
|
|
|
|
work stoppage, computer failure or malfunction, or any and all
|
|
|
|
other commercial damages or losses), even if such Contributor
|
|
|
|
has been advised of the possibility of such damages.
|
|
|
|
|
|
|
|
9. Accepting Warranty or Additional Liability. While redistributing
|
|
|
|
the Work or Derivative Works thereof, You may choose to offer,
|
|
|
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
|
|
or other liability obligations and/or rights consistent with this
|
|
|
|
License. However, in accepting such obligations, You may act only
|
|
|
|
on Your own behalf and on Your sole responsibility, not on behalf
|
|
|
|
of any other Contributor, and only if You agree to indemnify,
|
|
|
|
defend, and hold each Contributor harmless for any liability
|
|
|
|
incurred by, or claims asserted against, such Contributor by reason
|
|
|
|
of your accepting any such warranty or additional liability.
|
|
|
|
|
|
|
|
END OF TERMS AND CONDITIONS
|
|
|
|
|
|
|
|
APPENDIX: How to apply the Apache License to your work.
|
|
|
|
|
|
|
|
To apply the Apache License to your work, attach the following
|
|
|
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
|
|
replaced with your own identifying information. (Don't include
|
|
|
|
the brackets!) The text should be enclosed in the appropriate
|
|
|
|
comment syntax for the file format. We also recommend that a
|
|
|
|
file or class name and description of purpose be included on the
|
|
|
|
same "printed page" as the copyright notice for easier
|
|
|
|
identification within third-party archives.
|
|
|
|
|
|
|
|
Copyright 2014 Google Inc.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const SIZEOF_SHORT = 2
|
|
|
|
const SIZEOF_INT = 4
|
|
|
|
const FILE_IDENTIFIER_LENGTH = 4
|
|
|
|
const SIZE_PREFIX_LENGTH = 4
|
|
|
|
const TEXT_ENCODER = new TextEncoder()
|
|
|
|
const TEXT_DECODER = new TextDecoder()
|
2023-11-27 18:48:37 +03:00
|
|
|
export const Null = 0 as Offset<never>
|
2023-10-07 23:57:47 +03:00
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
declare const offsetType: unique symbol
|
|
|
|
type OffsetConstraint = Table | number | string | Uint8Array | ArrayBuffer | OffsetConstraint[]
|
|
|
|
export type Offset<T extends OffsetConstraint> = number & {
|
|
|
|
[offsetType]: T
|
|
|
|
}
|
|
|
|
type AnyOffset = Offset<OffsetConstraint>
|
|
|
|
export type CreateOffset<T extends OffsetConstraint> =
|
|
|
|
| ((builder: Builder) => Offset<T>)
|
|
|
|
| null
|
|
|
|
| undefined
|
|
|
|
|
|
|
|
interface IGeneratedObject<T extends OffsetConstraint> {
|
|
|
|
pack(builder: Builder): Offset<T>
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export type Table = {
|
|
|
|
bb: ByteBuffer
|
|
|
|
bbPos: number
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Builder {
|
|
|
|
private bb: ByteBuffer
|
|
|
|
private space: number
|
|
|
|
private minAlignment = 1
|
|
|
|
private vtable: number[] | null = null
|
|
|
|
private vtableInUse = 0
|
|
|
|
private isNested = false
|
|
|
|
private objectStart = 0
|
|
|
|
private vtables: number[] = []
|
|
|
|
private vectorNumElems = 0
|
|
|
|
private _forceDefaults = false
|
2023-11-27 18:48:37 +03:00
|
|
|
private stringMaps: Map<string | Uint8Array, AnyOffset> | null = null
|
2023-10-07 23:57:47 +03:00
|
|
|
|
|
|
|
constructor(initialSize?: number) {
|
|
|
|
initialSize ??= 1024
|
|
|
|
this.bb = new ByteBuffer(new ArrayBuffer(initialSize))
|
|
|
|
this.space = initialSize
|
|
|
|
}
|
|
|
|
|
|
|
|
clear(): void {
|
|
|
|
this.bb.position = 0
|
|
|
|
this.space = this.bb.view.byteLength
|
|
|
|
this.minAlignment = 1
|
2023-11-27 18:48:37 +03:00
|
|
|
this.vtable = []
|
2023-10-07 23:57:47 +03:00
|
|
|
this.vtableInUse = 0
|
|
|
|
this.isNested = false
|
|
|
|
this.objectStart = 0
|
|
|
|
this.vtables = []
|
|
|
|
this.vectorNumElems = 0
|
|
|
|
this._forceDefaults = false
|
|
|
|
this.stringMaps = null
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In order to save space, fields that are set to their default value
|
|
|
|
* don't get serialized into the buffer. Forcing defaults provides a
|
|
|
|
* way to manually disable this optimization.
|
|
|
|
*
|
|
|
|
* @param forceDefaults true always serializes default values
|
|
|
|
*/
|
|
|
|
forceDefaults(forceDefaults: boolean): void {
|
|
|
|
this._forceDefaults = forceDefaults
|
|
|
|
}
|
|
|
|
|
|
|
|
toArrayBuffer(): ArrayBuffer {
|
|
|
|
return this.bb.view.buffer.slice(this.bb.position, this.bb.position + this.offset())
|
|
|
|
}
|
|
|
|
|
|
|
|
prep(size: number, additionalBytes: number): void {
|
|
|
|
if (size > this.minAlignment) {
|
|
|
|
this.minAlignment = size
|
|
|
|
}
|
|
|
|
|
|
|
|
const alignSize = (~(this.bb.view.byteLength - this.space + additionalBytes) + 1) & (size - 1)
|
|
|
|
|
|
|
|
while (this.space < alignSize + size + additionalBytes) {
|
|
|
|
const oldBufSize = this.bb.view.byteLength
|
|
|
|
Builder.growByteBuffer(this.bb)
|
|
|
|
this.space += this.bb.view.byteLength - oldBufSize
|
|
|
|
}
|
|
|
|
|
|
|
|
this.pad(alignSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
pad(byteSize: number): void {
|
|
|
|
for (let i = 0; i < byteSize; i++) {
|
|
|
|
this.bb.view.setInt8(--this.space, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
writeInt8(value: number): void {
|
|
|
|
this.bb.view.setInt8((this.space -= 1), value)
|
|
|
|
}
|
|
|
|
|
|
|
|
writeInt16(value: number): void {
|
|
|
|
this.bb.view.setInt16((this.space -= 2), value, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
writeInt32(value: number): void {
|
|
|
|
this.bb.view.setInt32((this.space -= 4), value, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
writeInt64(value: bigint): void {
|
|
|
|
this.bb.view.setBigInt64((this.space -= 8), value, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
writeFloat32(value: number): void {
|
|
|
|
this.bb.view.setFloat32((this.space -= 4), value, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
writeFloat64(value: number): void {
|
|
|
|
this.bb.view.setFloat64((this.space -= 8), value, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
addInt8(value: number): void {
|
|
|
|
this.prep(1, 0)
|
|
|
|
this.writeInt8(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
addInt16(value: number): void {
|
|
|
|
this.prep(2, 0)
|
|
|
|
this.writeInt16(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
addInt32(value: number): void {
|
|
|
|
this.prep(4, 0)
|
|
|
|
this.writeInt32(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
addInt64(value: bigint): void {
|
|
|
|
this.prep(8, 0)
|
|
|
|
this.writeInt64(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
addFloat32(value: number): void {
|
|
|
|
this.prep(4, 0)
|
|
|
|
this.writeFloat32(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
addFloat64(value: number): void {
|
|
|
|
this.prep(8, 0)
|
|
|
|
this.writeFloat64(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
addFieldInt8(voffset: number, value: number, defaultValue: number | null): void {
|
|
|
|
if (this._forceDefaults || value != defaultValue) {
|
|
|
|
this.addInt8(value)
|
|
|
|
this.slot(voffset)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addFieldInt16(voffset: number, value: number, defaultValue: number | null): void {
|
|
|
|
if (this._forceDefaults || value != defaultValue) {
|
|
|
|
this.addInt16(value)
|
|
|
|
this.slot(voffset)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addFieldInt32(voffset: number, value: number, defaultValue: number | null): void {
|
|
|
|
if (this._forceDefaults || value != defaultValue) {
|
|
|
|
this.addInt32(value)
|
|
|
|
this.slot(voffset)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addFieldInt64(voffset: number, value: bigint, defaultValue: bigint | null): void {
|
|
|
|
if (this._forceDefaults || value !== defaultValue) {
|
|
|
|
this.addInt64(value)
|
|
|
|
this.slot(voffset)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addFieldFloat32(voffset: number, value: number, defaultValue: number | null): void {
|
|
|
|
if (this._forceDefaults || value != defaultValue) {
|
|
|
|
this.addFloat32(value)
|
|
|
|
this.slot(voffset)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addFieldFloat64(voffset: number, value: number, defaultValue: number | null): void {
|
|
|
|
if (this._forceDefaults || value != defaultValue) {
|
|
|
|
this.addFloat64(value)
|
|
|
|
this.slot(voffset)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
addFieldOffset<T extends OffsetConstraint>(
|
|
|
|
voffset: number,
|
|
|
|
value: Offset<T>,
|
|
|
|
defaultValue: Offset<T>,
|
|
|
|
): void {
|
2023-10-07 23:57:47 +03:00
|
|
|
if (this._forceDefaults || value != defaultValue) {
|
|
|
|
this.addOffset(value)
|
|
|
|
this.slot(voffset)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
addFieldStruct<T extends OffsetConstraint>(
|
|
|
|
voffset: number,
|
|
|
|
value: Offset<T>,
|
|
|
|
defaultValue: Offset<T>,
|
|
|
|
): void {
|
2023-10-07 23:57:47 +03:00
|
|
|
if (value != defaultValue) {
|
|
|
|
this.nested(value)
|
|
|
|
this.slot(voffset)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
nested(obj: AnyOffset): void {
|
2023-10-07 23:57:47 +03:00
|
|
|
if (obj != this.offset()) {
|
|
|
|
throw new TypeError('FlatBuffers: struct must be serialized inline.')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
notNested(): void {
|
|
|
|
if (this.isNested) {
|
|
|
|
throw new TypeError('FlatBuffers: object serialization must not be nested.')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
slot(voffset: number): void {
|
|
|
|
if (this.vtable !== null) this.vtable[voffset] = this.offset()
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
offset<T extends OffsetConstraint>(): Offset<T> {
|
|
|
|
return (this.bb.view.byteLength - this.space) as Offset<T>
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static growByteBuffer(bb: ByteBuffer): void {
|
|
|
|
const oldBufSize = bb.view.byteLength
|
|
|
|
// Ensure we don't grow beyond what fits in an int.
|
|
|
|
if (oldBufSize & 0xc0000000) {
|
|
|
|
throw new globalThis.Error('FlatBuffers: cannot grow buffer beyond 2 gigabytes.')
|
|
|
|
}
|
|
|
|
const newBufSize = oldBufSize << 1
|
|
|
|
const newBuffer = new ArrayBuffer(newBufSize)
|
|
|
|
bb.position = newBufSize - oldBufSize
|
|
|
|
new Uint8Array(newBuffer).set(new Uint8Array(bb.view.buffer), bb.position)
|
|
|
|
bb.view = new DataView(newBuffer)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
addOffset(offset: AnyOffset): void {
|
2023-10-07 23:57:47 +03:00
|
|
|
this.prep(SIZEOF_INT, 0) // Ensure alignment is already done.
|
|
|
|
this.writeInt32(this.offset() - offset + SIZEOF_INT)
|
|
|
|
}
|
|
|
|
|
|
|
|
startObject(numfields: number): void {
|
|
|
|
this.notNested()
|
|
|
|
if (this.vtable == null) {
|
|
|
|
this.vtable = []
|
|
|
|
}
|
|
|
|
this.vtableInUse = numfields
|
|
|
|
for (let i = 0; i < numfields; i++) {
|
|
|
|
this.vtable[i] = 0 // This will push additional elements as needed
|
|
|
|
}
|
|
|
|
this.isNested = true
|
|
|
|
this.objectStart = this.offset()
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
endObject<T extends OffsetConstraint>(): Offset<T> {
|
2023-10-07 23:57:47 +03:00
|
|
|
if (this.vtable == null || !this.isNested) {
|
|
|
|
throw new globalThis.Error('FlatBuffers: endObject called without startObject')
|
|
|
|
}
|
|
|
|
|
|
|
|
this.addInt32(0)
|
|
|
|
const vtableloc = this.offset()
|
|
|
|
|
|
|
|
// Trim trailing zeroes.
|
|
|
|
let i = this.vtableInUse - 1
|
|
|
|
// eslint-disable-next-line no-empty
|
2023-11-03 23:09:45 +03:00
|
|
|
for (; i >= 0 && this.vtable[i] === 0; i -= 1) {}
|
2023-10-07 23:57:47 +03:00
|
|
|
const trimmedSize = i + 1
|
|
|
|
|
|
|
|
// Write out the current vtable.
|
2023-11-03 23:09:45 +03:00
|
|
|
for (; i >= 0; i -= 1) {
|
2023-10-07 23:57:47 +03:00
|
|
|
// Offset relative to the start of the table.
|
2023-11-03 23:09:45 +03:00
|
|
|
this.addInt16(this.vtable[i] !== 0 ? vtableloc - this.vtable[i]! : 0)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const standardFields = 2 // The fields below:
|
|
|
|
this.addInt16(vtableloc - this.objectStart)
|
|
|
|
const len = (trimmedSize + standardFields) * SIZEOF_SHORT
|
|
|
|
this.addInt16(len)
|
|
|
|
|
|
|
|
// Search for an existing vtable that matches the current one.
|
|
|
|
let existingVtable = 0
|
|
|
|
const vt1 = this.space
|
|
|
|
outerLoop: for (i = 0; i < this.vtables.length; i++) {
|
|
|
|
const vt2 = this.bb.view.byteLength - this.vtables[i]!
|
|
|
|
if (len == this.bb.view.getInt16(vt2, true)) {
|
|
|
|
for (let j = SIZEOF_SHORT; j < len; j += SIZEOF_SHORT) {
|
|
|
|
if (this.bb.view.getInt16(vt1 + j, true) != this.bb.view.getInt16(vt2 + j, true)) {
|
|
|
|
continue outerLoop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
existingVtable = this.vtables[i]!
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (existingVtable) {
|
|
|
|
// Found a match:
|
|
|
|
// Remove the current vtable.
|
|
|
|
this.space = this.bb.view.byteLength - vtableloc
|
|
|
|
|
|
|
|
// Point table to existing vtable.
|
|
|
|
this.bb.view.setInt32(this.space, existingVtable - vtableloc, true)
|
|
|
|
} else {
|
|
|
|
// No match:
|
|
|
|
// Add the location of the current vtable to the list of vtables.
|
|
|
|
this.vtables.push(this.offset())
|
|
|
|
|
|
|
|
// Point table to current vtable.
|
|
|
|
this.bb.view.setInt32(this.bb.view.byteLength - vtableloc, this.offset() - vtableloc, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isNested = false
|
2023-11-27 18:48:37 +03:00
|
|
|
return vtableloc as Offset<T>
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
finish(
|
|
|
|
rootTable: AnyOffset,
|
|
|
|
fileIdentifier?: string,
|
|
|
|
shouldIncludeSizePrefix?: boolean,
|
|
|
|
): Builder {
|
2023-10-07 23:57:47 +03:00
|
|
|
const sizePrefix = shouldIncludeSizePrefix ? SIZE_PREFIX_LENGTH : 0
|
|
|
|
if (fileIdentifier) {
|
|
|
|
this.prep(this.minAlignment, SIZEOF_INT + FILE_IDENTIFIER_LENGTH + sizePrefix)
|
|
|
|
if (fileIdentifier.length != FILE_IDENTIFIER_LENGTH) {
|
|
|
|
throw new TypeError('FlatBuffers: file identifier must be length ' + FILE_IDENTIFIER_LENGTH)
|
|
|
|
}
|
2023-11-03 23:09:45 +03:00
|
|
|
for (let i = FILE_IDENTIFIER_LENGTH - 1; i >= 0; i -= 1) {
|
2023-10-07 23:57:47 +03:00
|
|
|
this.writeInt8(fileIdentifier.charCodeAt(i))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.prep(this.minAlignment, SIZEOF_INT + sizePrefix)
|
|
|
|
this.addOffset(rootTable)
|
|
|
|
if (sizePrefix) {
|
|
|
|
this.addInt32(this.bb.view.byteLength - this.space)
|
|
|
|
}
|
|
|
|
this.bb.position = this.space
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
finishSizePrefixed(rootTable: AnyOffset, fileIdentifier?: string): Builder {
|
2023-10-07 23:57:47 +03:00
|
|
|
this.finish(rootTable, fileIdentifier, true)
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
requiredField(table: AnyOffset, field: number): void {
|
2023-10-07 23:57:47 +03:00
|
|
|
const tableStart = this.bb.view.byteLength - table
|
|
|
|
const vtableStart = tableStart - this.bb.view.getInt32(tableStart, true)
|
|
|
|
const ok =
|
|
|
|
field < this.bb.view.getInt16(vtableStart, true) &&
|
|
|
|
this.bb.view.getInt16(vtableStart + field, true) != 0
|
|
|
|
// If this fails, the caller will show what field needs to be set.
|
|
|
|
if (!ok) {
|
|
|
|
throw new TypeError('FlatBuffers: field ' + field + ' must be set')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
startVector(elemSize: number, numElems: number, alignment: number): void {
|
|
|
|
this.notNested()
|
|
|
|
this.vectorNumElems = numElems
|
|
|
|
this.prep(SIZEOF_INT, elemSize * numElems)
|
|
|
|
this.prep(alignment, elemSize * numElems) // Just in case alignment > int.
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
endVector<T extends OffsetConstraint>(): Offset<T> {
|
2023-10-07 23:57:47 +03:00
|
|
|
this.writeInt32(this.vectorNumElems)
|
|
|
|
return this.offset()
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
createSharedString<T extends string | Uint8Array>(s: T): Offset<T> {
|
2023-10-07 23:57:47 +03:00
|
|
|
if (!s) {
|
2023-11-27 18:48:37 +03:00
|
|
|
return 0 as Offset<T>
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
if (!this.stringMaps) {
|
|
|
|
this.stringMaps = new Map()
|
|
|
|
}
|
|
|
|
const value = this.stringMaps.get(s)
|
|
|
|
if (value != null) {
|
2023-11-27 18:48:37 +03:00
|
|
|
return value as Offset<T>
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
const offset = this.createString(s)
|
|
|
|
this.stringMaps.set(s, offset)
|
2023-11-27 18:48:37 +03:00
|
|
|
return offset as Offset<T>
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
createString(s: string | Uint8Array | ArrayBuffer | null | undefined): Offset<Uint8Array> {
|
|
|
|
if (s === null || s === undefined) return Null
|
2023-10-07 23:57:47 +03:00
|
|
|
let utf8: string | Uint8Array | number[]
|
|
|
|
if (s instanceof Uint8Array) {
|
|
|
|
utf8 = s
|
|
|
|
} else if (s instanceof ArrayBuffer) {
|
|
|
|
utf8 = new Uint8Array(s)
|
|
|
|
} else {
|
|
|
|
utf8 = TEXT_ENCODER.encode(s)
|
|
|
|
}
|
|
|
|
this.addInt8(0)
|
|
|
|
this.startVector(1, utf8.length, 1)
|
|
|
|
this.bb.position = this.space -= utf8.length
|
|
|
|
for (let i = 0, offset = this.space, bytes = this.bb.view; i < utf8.length; i++) {
|
|
|
|
bytes.setUint8(offset++, utf8[i]!)
|
|
|
|
}
|
|
|
|
return this.endVector()
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
createObjectOffset<T extends OffsetConstraint>(
|
|
|
|
obj: T extends string | null ? T : IGeneratedObject<T>,
|
|
|
|
): Offset<T> {
|
|
|
|
if (obj === null) return Null
|
|
|
|
else if (typeof obj === 'string') return this.createString(obj) as Offset<T>
|
|
|
|
else return obj.pack(this) as Offset<T>
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
createObjectOffsetList<T extends OffsetConstraint>(
|
|
|
|
list: (T extends string ? string : IGeneratedObject<T>)[],
|
|
|
|
): Offset<T>[] {
|
2023-10-07 23:57:47 +03:00
|
|
|
const ret: number[] = []
|
|
|
|
for (let i = 0; i < list.length; ++i) {
|
|
|
|
const val = list[i]
|
|
|
|
if (val != null) {
|
2023-11-27 18:48:37 +03:00
|
|
|
ret.push(this.createObjectOffset(val as any))
|
2023-10-07 23:57:47 +03:00
|
|
|
} else {
|
|
|
|
throw new TypeError('FlatBuffers: Argument for createObjectOffsetList cannot contain null.')
|
|
|
|
}
|
|
|
|
}
|
2023-11-27 18:48:37 +03:00
|
|
|
return ret as Offset<T>[]
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
createStructOffsetList<T extends OffsetConstraint>(
|
|
|
|
list: (T extends string ? string : IGeneratedObject<T>)[],
|
2023-10-07 23:57:47 +03:00
|
|
|
startFunc: (builder: Builder, length: number) => void,
|
2023-11-27 18:48:37 +03:00
|
|
|
): Offset<T> {
|
2023-10-07 23:57:47 +03:00
|
|
|
startFunc(this, list.length)
|
|
|
|
this.createObjectOffsetList(list.slice().reverse())
|
|
|
|
return this.endVector()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ByteBuffer {
|
|
|
|
position = 0
|
|
|
|
view: DataView
|
|
|
|
|
|
|
|
constructor(buffer: ArrayBufferLike) {
|
|
|
|
this.view = new DataView(buffer)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
offset<T extends OffsetConstraint>(bbPos: number, vtableOffset: number): Offset<T> {
|
2023-10-07 23:57:47 +03:00
|
|
|
const vtable = bbPos - this.view.getInt32(bbPos, true)
|
2023-11-27 18:48:37 +03:00
|
|
|
return (
|
|
|
|
vtableOffset < this.view.getInt16(vtable, true)
|
|
|
|
? this.view.getInt16(vtable + vtableOffset, true)
|
|
|
|
: 0
|
|
|
|
) as Offset<T>
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
union(t: Table, offset: number): Table {
|
|
|
|
t.bbPos = offset + this.view.getInt32(offset, true)
|
|
|
|
t.bb = this
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
rawMessage(offset: number): ArrayBuffer {
|
|
|
|
offset += this.view.getInt32(offset, true)
|
|
|
|
const length = this.view.getInt32(offset, true)
|
|
|
|
offset += SIZEOF_INT
|
|
|
|
return this.view.buffer.slice(offset, offset + length)
|
|
|
|
}
|
|
|
|
|
|
|
|
message(offset: number): string {
|
|
|
|
return TEXT_DECODER.decode(this.rawMessage(offset))
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
indirect<T extends OffsetConstraint>(offset: number | Offset<T>): Offset<T> {
|
|
|
|
return (offset + this.view.getInt32(offset, true)) as Offset<T>
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
vector<T extends OffsetConstraint>(offset: number | Offset<T>): Offset<T> {
|
|
|
|
return (offset + this.view.getInt32(offset, true) + SIZEOF_INT) as Offset<T> // data starts after the length
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
vectorLength(offset: number | AnyOffset): Offset<number> {
|
|
|
|
return this.view.getInt32(offset + this.view.getInt32(offset, true), true) as Offset<number>
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum InboundPayload {
|
|
|
|
NONE = 0,
|
|
|
|
INIT_SESSION_CMD = 1,
|
|
|
|
WRITE_FILE_CMD = 2,
|
|
|
|
READ_FILE_CMD = 3,
|
|
|
|
WRITE_BYTES_CMD = 4,
|
|
|
|
READ_BYTES_CMD = 5,
|
|
|
|
CHECKSUM_BYTES_CMD = 6,
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
export type AnyInboundPayload =
|
|
|
|
| None
|
|
|
|
| InitSessionCommand
|
|
|
|
| WriteFileCommand
|
|
|
|
| ReadFileCommand
|
|
|
|
| WriteBytesCommand
|
|
|
|
| ReadBytesCommand
|
|
|
|
| ChecksumBytesCommand
|
|
|
|
|
2023-10-07 23:57:47 +03:00
|
|
|
export enum OutboundPayload {
|
|
|
|
NONE = 0,
|
|
|
|
ERROR = 1,
|
|
|
|
SUCCESS = 2,
|
|
|
|
VISUALIZATION_UPDATE = 3,
|
|
|
|
FILE_CONTENTS_REPLY = 4,
|
|
|
|
WRITE_BYTES_REPLY = 5,
|
|
|
|
READ_BYTES_REPLY = 6,
|
|
|
|
CHECKSUM_BYTES_REPLY = 7,
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
export type AnyOutboundPayload =
|
|
|
|
| None
|
|
|
|
| Error
|
|
|
|
| Success
|
|
|
|
| VisualizationUpdate
|
|
|
|
| FileContentsReply
|
|
|
|
| WriteBytesReply
|
|
|
|
| ReadBytesReply
|
|
|
|
| ChecksumBytesReply
|
|
|
|
|
2023-10-07 23:57:47 +03:00
|
|
|
export enum ErrorPayload {
|
|
|
|
NONE = 0,
|
|
|
|
READ_OOB = 1,
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
export type AnyErrorPayload = None | ReadOutOfBoundsError
|
|
|
|
|
2023-10-07 23:57:47 +03:00
|
|
|
export class InboundMessage implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): InboundMessage {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsInboundMessage(bb: ByteBuffer, obj?: InboundMessage): InboundMessage {
|
|
|
|
return (obj ?? new InboundMessage()).init(bb.view.getInt32(bb.position, true) + bb.position, bb)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsInboundMessage(bb: ByteBuffer, obj?: InboundMessage): InboundMessage {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new InboundMessage()).init(bb.view.getInt32(bb.position, true) + bb.position, bb)
|
|
|
|
}
|
|
|
|
|
|
|
|
messageId(obj?: EnsoUUID): EnsoUUID | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset ? (obj ?? new EnsoUUID()).init(this.bbPos + offset, this.bb!) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
correlationId(obj?: EnsoUUID): EnsoUUID | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset ? (obj ?? new EnsoUUID()).init(this.bbPos + offset, this.bb!) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
payloadType(): InboundPayload {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 8)
|
|
|
|
return offset ? this.bb.view.getUint8(this.bbPos + offset) : InboundPayload.NONE
|
|
|
|
}
|
|
|
|
|
|
|
|
payload<T extends Table>(obj: T): T | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 10)
|
|
|
|
// @ts-expect-error
|
|
|
|
return offset ? this.bb.union(obj, this.bbPos + offset) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startInboundMessage(builder: Builder) {
|
|
|
|
builder.startObject(4)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addMessageId(builder: Builder, messageIdOffset: Offset<EnsoUUID>) {
|
|
|
|
builder.addFieldStruct(0, messageIdOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addCorrelationId(builder: Builder, correlationIdOffset: Offset<EnsoUUID>) {
|
|
|
|
builder.addFieldStruct(1, correlationIdOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static addPayloadType(builder: Builder, payloadType: InboundPayload) {
|
|
|
|
builder.addFieldInt8(2, payloadType, InboundPayload.NONE)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addPayload(builder: Builder, payloadOffset: Offset<AnyInboundPayload>) {
|
|
|
|
builder.addFieldOffset(3, payloadOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endInboundMessage(builder: Builder): Offset<InboundMessage> {
|
|
|
|
const offset = builder.endObject<InboundMessage>()
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.requiredField(offset, 4) // messageId
|
|
|
|
builder.requiredField(offset, 10) // payload
|
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
|
|
|
static createInboundMessage(
|
|
|
|
builder: Builder,
|
2023-11-27 18:48:37 +03:00
|
|
|
createMessageId: CreateOffset<EnsoUUID>,
|
|
|
|
createCorrelationId: CreateOffset<EnsoUUID>,
|
2023-10-07 23:57:47 +03:00
|
|
|
payloadType: InboundPayload,
|
2023-11-27 18:48:37 +03:00
|
|
|
payloadOffset: Offset<AnyInboundPayload>,
|
|
|
|
): Offset<InboundMessage> {
|
2023-10-07 23:57:47 +03:00
|
|
|
InboundMessage.startInboundMessage(builder)
|
2023-11-27 18:48:37 +03:00
|
|
|
InboundMessage.addMessageId(builder, createMessageId?.(builder) ?? Null)
|
|
|
|
InboundMessage.addCorrelationId(builder, createCorrelationId?.(builder) ?? Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
InboundMessage.addPayloadType(builder, payloadType)
|
|
|
|
InboundMessage.addPayload(builder, payloadOffset)
|
|
|
|
return InboundMessage.endInboundMessage(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class OutboundMessage implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): OutboundMessage {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsOutboundMessage(bb: ByteBuffer, obj?: OutboundMessage): OutboundMessage {
|
|
|
|
return (obj ?? new OutboundMessage()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsOutboundMessage(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: OutboundMessage,
|
|
|
|
): OutboundMessage {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new OutboundMessage()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
messageId(obj?: EnsoUUID): EnsoUUID | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset ? (obj ?? new EnsoUUID()).init(this.bbPos + offset, this.bb!) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
correlationId(obj?: EnsoUUID): EnsoUUID | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset ? (obj ?? new EnsoUUID()).init(this.bbPos + offset, this.bb!) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
payloadType(): OutboundPayload {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 8)
|
|
|
|
return offset ? this.bb.view.getUint8(this.bbPos + offset) : OutboundPayload.NONE
|
|
|
|
}
|
|
|
|
|
|
|
|
payload<T extends Table>(obj: T): T | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 10)
|
|
|
|
// @ts-expect-error
|
|
|
|
return offset ? this.bb.union(obj, this.bbPos + offset) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startOutboundMessage(builder: Builder) {
|
|
|
|
builder.startObject(4)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addMessageId(builder: Builder, messageIdOffset: Offset<EnsoUUID>) {
|
|
|
|
builder.addFieldStruct(0, messageIdOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addCorrelationId(builder: Builder, correlationIdOffset: Offset<EnsoUUID>) {
|
|
|
|
builder.addFieldStruct(1, correlationIdOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static addPayloadType(builder: Builder, payloadType: OutboundPayload) {
|
|
|
|
builder.addFieldInt8(2, payloadType, OutboundPayload.NONE)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addPayload(builder: Builder, payloadOffset: Offset<AnyOutboundPayload>) {
|
|
|
|
builder.addFieldOffset(3, payloadOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endOutboundMessage(builder: Builder): Offset<OutboundMessage> {
|
|
|
|
const offset = builder.endObject<OutboundMessage>()
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.requiredField(offset, 4) // messageId
|
|
|
|
builder.requiredField(offset, 10) // payload
|
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
|
|
|
static createOutboundMessage(
|
|
|
|
builder: Builder,
|
2023-11-27 18:48:37 +03:00
|
|
|
createMessageId: CreateOffset<EnsoUUID>,
|
|
|
|
createCorrelationId: CreateOffset<EnsoUUID>,
|
2023-10-07 23:57:47 +03:00
|
|
|
payloadType: OutboundPayload,
|
2023-11-27 18:48:37 +03:00
|
|
|
payloadOffset: Offset<AnyOutboundPayload>,
|
|
|
|
): Offset<OutboundMessage> {
|
2023-10-07 23:57:47 +03:00
|
|
|
OutboundMessage.startOutboundMessage(builder)
|
2023-11-27 18:48:37 +03:00
|
|
|
OutboundMessage.addMessageId(builder, createMessageId?.(builder) ?? Null)
|
|
|
|
OutboundMessage.addCorrelationId(builder, createCorrelationId?.(builder) ?? Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
OutboundMessage.addPayloadType(builder, payloadType)
|
|
|
|
OutboundMessage.addPayload(builder, payloadOffset)
|
|
|
|
return OutboundMessage.endOutboundMessage(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class EnsoUUID implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): EnsoUUID {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
leastSigBits(): bigint {
|
|
|
|
return this.bb.view.getBigUint64(this.bbPos, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
mostSigBits(): bigint {
|
|
|
|
return this.bb.view.getBigUint64(this.bbPos + 8, true)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createEnsoUUID(
|
|
|
|
builder: Builder,
|
|
|
|
leastSigBits: bigint,
|
|
|
|
mostSigBits: bigint,
|
|
|
|
): Offset<EnsoUUID> {
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.prep(8, 16)
|
|
|
|
builder.writeInt64(mostSigBits)
|
|
|
|
builder.writeInt64(leastSigBits)
|
|
|
|
return builder.offset()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Error implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): Error {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsError(bb: ByteBuffer, obj?: Error): Error {
|
|
|
|
return (obj ?? new Error()).init(bb.view.getInt32(bb.position, true) + bb.position, bb)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsError(bb: ByteBuffer, obj?: Error): Error {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new Error()).init(bb.view.getInt32(bb.position, true) + bb.position, bb)
|
|
|
|
}
|
|
|
|
|
|
|
|
code(): number {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset ? this.bb.view.getInt32(this.bbPos + offset, true) : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
rawMessage(): ArrayBuffer | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset ? this.bb.rawMessage(this.bbPos + offset) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
message(): string | null {
|
|
|
|
const rawMessage = this.rawMessage()
|
|
|
|
return rawMessage ? TEXT_DECODER.decode(rawMessage) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
dataType(): ErrorPayload {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 8)
|
|
|
|
return offset ? this.bb.view.getUint8(this.bbPos + offset) : ErrorPayload.NONE
|
|
|
|
}
|
|
|
|
|
|
|
|
data<T extends Table>(obj: T): T | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 10)
|
|
|
|
// @ts-expect-error
|
|
|
|
return offset ? this.bb.union(obj, this.bbPos + offset) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startError(builder: Builder) {
|
|
|
|
builder.startObject(4)
|
|
|
|
}
|
|
|
|
|
|
|
|
static addCode(builder: Builder, code: number) {
|
|
|
|
builder.addFieldInt32(0, code, 0)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addMessage(builder: Builder, messageOffset: Offset<string | ArrayBuffer>) {
|
|
|
|
builder.addFieldOffset(1, messageOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static addDataType(builder: Builder, dataType: ErrorPayload) {
|
|
|
|
builder.addFieldInt8(2, dataType, ErrorPayload.NONE)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addData(builder: Builder, dataOffset: Offset<AnyErrorPayload>) {
|
|
|
|
builder.addFieldOffset(3, dataOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endError(builder: Builder): Offset<Error> {
|
|
|
|
const offset = builder.endObject<Error>()
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.requiredField(offset, 6) // message
|
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
|
|
|
static createError(
|
|
|
|
builder: Builder,
|
|
|
|
code: number,
|
2023-11-27 18:48:37 +03:00
|
|
|
messageOffset: Offset<string | ArrayBuffer>,
|
2023-10-07 23:57:47 +03:00
|
|
|
dataType: ErrorPayload,
|
2023-11-27 18:48:37 +03:00
|
|
|
dataOffset: Offset<AnyErrorPayload>,
|
|
|
|
): Offset<Error> {
|
2023-10-07 23:57:47 +03:00
|
|
|
Error.startError(builder)
|
|
|
|
Error.addCode(builder, code)
|
|
|
|
Error.addMessage(builder, messageOffset)
|
|
|
|
Error.addDataType(builder, dataType)
|
|
|
|
Error.addData(builder, dataOffset)
|
|
|
|
return Error.endError(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ReadOutOfBoundsError implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): ReadOutOfBoundsError {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsReadOutOfBoundsError(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: ReadOutOfBoundsError,
|
|
|
|
): ReadOutOfBoundsError {
|
|
|
|
return (obj ?? new ReadOutOfBoundsError()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsReadOutOfBoundsError(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: ReadOutOfBoundsError,
|
|
|
|
): ReadOutOfBoundsError {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new ReadOutOfBoundsError()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fileLength(): bigint {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset ? this.bb.view.getBigUint64(this.bbPos + offset, true) : 0n
|
|
|
|
}
|
|
|
|
|
|
|
|
static startReadOutOfBoundsError(builder: Builder) {
|
|
|
|
builder.startObject(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
static addFileLength(builder: Builder, fileLength: bigint) {
|
|
|
|
builder.addFieldInt64(0, fileLength, 0n)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endReadOutOfBoundsError(builder: Builder): Offset<ReadOutOfBoundsError> {
|
|
|
|
const offset = builder.endObject<ReadOutOfBoundsError>()
|
2023-10-07 23:57:47 +03:00
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createReadOutOfBoundsError(
|
|
|
|
builder: Builder,
|
|
|
|
fileLength: bigint,
|
|
|
|
): Offset<ReadOutOfBoundsError> {
|
2023-10-07 23:57:47 +03:00
|
|
|
ReadOutOfBoundsError.startReadOutOfBoundsError(builder)
|
|
|
|
ReadOutOfBoundsError.addFileLength(builder, fileLength)
|
|
|
|
return ReadOutOfBoundsError.endReadOutOfBoundsError(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class None implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
2023-11-03 23:09:45 +03:00
|
|
|
init(i: number, bb: ByteBuffer): None {
|
2023-10-07 23:57:47 +03:00
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Success implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): Success {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsSuccess(bb: ByteBuffer, obj?: Success): Success {
|
|
|
|
return (obj ?? new Success()).init(bb.view.getInt32(bb.position, true) + bb.position, bb)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsSuccess(bb: ByteBuffer, obj?: Success): Success {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new Success()).init(bb.view.getInt32(bb.position, true) + bb.position, bb)
|
|
|
|
}
|
|
|
|
|
|
|
|
static startSuccess(builder: Builder) {
|
|
|
|
builder.startObject(0)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endSuccess(builder: Builder): Offset<Success> {
|
|
|
|
const offset = builder.endObject<Success>()
|
2023-10-07 23:57:47 +03:00
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createSuccess(builder: Builder): Offset<Success> {
|
2023-10-07 23:57:47 +03:00
|
|
|
Success.startSuccess(builder)
|
|
|
|
return Success.endSuccess(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class InitSessionCommand implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): InitSessionCommand {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsInitSessionCommand(bb: ByteBuffer, obj?: InitSessionCommand): InitSessionCommand {
|
|
|
|
return (obj ?? new InitSessionCommand()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsInitSessionCommand(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: InitSessionCommand,
|
|
|
|
): InitSessionCommand {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new InitSessionCommand()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
identifier(obj?: EnsoUUID): EnsoUUID | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset ? (obj ?? new EnsoUUID()).init(this.bbPos + offset, this.bb!) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startInitSessionCommand(builder: Builder) {
|
|
|
|
builder.startObject(1)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addIdentifier(builder: Builder, identifierOffset: Offset<EnsoUUID>) {
|
|
|
|
builder.addFieldStruct(0, identifierOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endInitSessionCommand(builder: Builder): Offset<InitSessionCommand> {
|
|
|
|
const offset = builder.endObject<InitSessionCommand>()
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.requiredField(offset, 4) // identifier
|
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createInitSessionCommand(
|
|
|
|
builder: Builder,
|
|
|
|
createIdentifier: CreateOffset<EnsoUUID>,
|
|
|
|
): Offset<InitSessionCommand> {
|
2023-10-07 23:57:47 +03:00
|
|
|
InitSessionCommand.startInitSessionCommand(builder)
|
2023-11-27 18:48:37 +03:00
|
|
|
InitSessionCommand.addIdentifier(builder, createIdentifier?.(builder) ?? Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
return InitSessionCommand.endInitSessionCommand(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class VisualizationContext implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): VisualizationContext {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsVisualizationContext(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: VisualizationContext,
|
|
|
|
): VisualizationContext {
|
|
|
|
return (obj ?? new VisualizationContext()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsVisualizationContext(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: VisualizationContext,
|
|
|
|
): VisualizationContext {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new VisualizationContext()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
visualizationId(obj?: EnsoUUID): EnsoUUID | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset ? (obj ?? new EnsoUUID()).init(this.bbPos + offset, this.bb!) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
contextId(obj?: EnsoUUID): EnsoUUID | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset ? (obj ?? new EnsoUUID()).init(this.bbPos + offset, this.bb!) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
expressionId(obj?: EnsoUUID): EnsoUUID | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 8)
|
|
|
|
return offset ? (obj ?? new EnsoUUID()).init(this.bbPos + offset, this.bb!) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startVisualizationContext(builder: Builder) {
|
|
|
|
builder.startObject(3)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addVisualizationId(builder: Builder, visualizationIdOffset: Offset<EnsoUUID>) {
|
|
|
|
builder.addFieldStruct(0, visualizationIdOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addContextId(builder: Builder, contextIdOffset: Offset<EnsoUUID>) {
|
|
|
|
builder.addFieldStruct(1, contextIdOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addExpressionId(builder: Builder, expressionIdOffset: Offset<EnsoUUID>) {
|
|
|
|
builder.addFieldStruct(2, expressionIdOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endVisualizationContext(builder: Builder): Offset<VisualizationContext> {
|
|
|
|
const offset = builder.endObject<VisualizationContext>()
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.requiredField(offset, 4) // visualizationId
|
|
|
|
builder.requiredField(offset, 6) // contextId
|
|
|
|
builder.requiredField(offset, 8) // expressionId
|
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
|
|
|
static createVisualizationContext(
|
|
|
|
builder: Builder,
|
2023-11-27 18:48:37 +03:00
|
|
|
createVisualizationId: CreateOffset<EnsoUUID>,
|
|
|
|
createContextId: CreateOffset<EnsoUUID>,
|
|
|
|
createExpressionId: CreateOffset<EnsoUUID>,
|
|
|
|
): Offset<VisualizationContext> {
|
2023-10-07 23:57:47 +03:00
|
|
|
VisualizationContext.startVisualizationContext(builder)
|
2023-11-27 18:48:37 +03:00
|
|
|
VisualizationContext.addVisualizationId(builder, createVisualizationId?.(builder) ?? Null)
|
|
|
|
VisualizationContext.addContextId(builder, createContextId?.(builder) ?? Null)
|
|
|
|
VisualizationContext.addExpressionId(builder, createExpressionId?.(builder) ?? Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
return VisualizationContext.endVisualizationContext(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class VisualizationUpdate implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): VisualizationUpdate {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsVisualizationUpdate(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: VisualizationUpdate,
|
|
|
|
): VisualizationUpdate {
|
|
|
|
return (obj ?? new VisualizationUpdate()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsVisualizationUpdate(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: VisualizationUpdate,
|
|
|
|
): VisualizationUpdate {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new VisualizationUpdate()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
visualizationContext(obj?: VisualizationContext): VisualizationContext | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset
|
|
|
|
? (obj ?? new VisualizationContext()).init(this.bb.indirect(this.bbPos + offset), this.bb!)
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
|
|
|
|
data(index: number): number | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset ? this.bb.view.getUint8(this.bb.vector(this.bbPos + offset) + index) : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
dataLength(): number {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset ? this.bb.vectorLength(this.bbPos + offset) : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
dataArray(): Uint8Array | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset
|
|
|
|
? new Uint8Array(
|
|
|
|
this.bb.view.buffer,
|
|
|
|
this.bb.view.byteOffset + this.bb.vector(this.bbPos + offset),
|
|
|
|
this.bb.vectorLength(this.bbPos + offset),
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
|
|
|
|
dataString(): string | null {
|
|
|
|
const buffer = this.dataArray()
|
|
|
|
return buffer != null ? TEXT_DECODER.decode(buffer) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startVisualizationUpdate(builder: Builder) {
|
|
|
|
builder.startObject(2)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addVisualizationContext(
|
|
|
|
builder: Builder,
|
|
|
|
visualizationContextOffset: Offset<VisualizationContext>,
|
|
|
|
) {
|
|
|
|
builder.addFieldOffset(0, visualizationContextOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addData(builder: Builder, dataOffset: Offset<Uint8Array>) {
|
|
|
|
builder.addFieldOffset(1, dataOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createDataVector(builder: Builder, data: number[] | Uint8Array): Offset<Uint8Array> {
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.startVector(1, data.length, 1)
|
|
|
|
// An iterator is more type-safe, but less performant.
|
2023-11-03 23:09:45 +03:00
|
|
|
for (let i = data.length - 1; i >= 0; i -= 1) {
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.addInt8(data[i]!)
|
|
|
|
}
|
|
|
|
return builder.endVector()
|
|
|
|
}
|
|
|
|
|
|
|
|
static startDataVector(builder: Builder, numElems: number) {
|
|
|
|
builder.startVector(1, numElems, 1)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endVisualizationUpdate(builder: Builder): Offset<VisualizationUpdate> {
|
|
|
|
const offset = builder.endObject<VisualizationUpdate>()
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.requiredField(offset, 4) // visualizationContext
|
|
|
|
builder.requiredField(offset, 6) // data
|
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
|
|
|
static createVisualizationUpdate(
|
|
|
|
builder: Builder,
|
2023-11-27 18:48:37 +03:00
|
|
|
visualizationContextOffset: Offset<VisualizationContext>,
|
|
|
|
dataOffset: Offset<Uint8Array>,
|
|
|
|
): Offset<VisualizationUpdate> {
|
2023-10-07 23:57:47 +03:00
|
|
|
VisualizationUpdate.startVisualizationUpdate(builder)
|
|
|
|
VisualizationUpdate.addVisualizationContext(builder, visualizationContextOffset)
|
|
|
|
VisualizationUpdate.addData(builder, dataOffset)
|
|
|
|
return VisualizationUpdate.endVisualizationUpdate(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Path implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): Path {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsPath(bb: ByteBuffer, obj?: Path): Path {
|
|
|
|
return (obj ?? new Path()).init(bb.view.getInt32(bb.position, true) + bb.position, bb)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsPath(bb: ByteBuffer, obj?: Path): Path {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new Path()).init(bb.view.getInt32(bb.position, true) + bb.position, bb)
|
|
|
|
}
|
|
|
|
|
|
|
|
rootId(obj?: EnsoUUID): EnsoUUID | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset ? (obj ?? new EnsoUUID()).init(this.bbPos + offset, this.bb) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
rawSegments(index: number): ArrayBuffer {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
2023-11-03 23:09:45 +03:00
|
|
|
return offset
|
|
|
|
? this.bb.rawMessage(this.bb.vector(this.bbPos + offset) + index * 4)
|
|
|
|
: new Uint8Array()
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
segments(index: number): string {
|
|
|
|
return TEXT_DECODER.decode(this.rawSegments(index))
|
|
|
|
}
|
|
|
|
|
|
|
|
segmentsLength(): number {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset ? this.bb.vectorLength(this.bbPos + offset) : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
static startPath(builder: Builder) {
|
|
|
|
builder.startObject(2)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addRootId(builder: Builder, rootIdOffset: Offset<EnsoUUID>) {
|
|
|
|
builder.addFieldStruct(0, rootIdOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addSegments(builder: Builder, segmentsOffset: Offset<string[] | ArrayBuffer[]>) {
|
|
|
|
builder.addFieldOffset(1, segmentsOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createSegmentsVector(
|
|
|
|
builder: Builder,
|
|
|
|
data: Offset<string>[] | Offset<ArrayBuffer>[],
|
|
|
|
): Offset<string[] | ArrayBuffer[]> {
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.startVector(4, data.length, 4)
|
|
|
|
// An iterator is more type-safe, but less performant.
|
2023-11-03 23:09:45 +03:00
|
|
|
for (let i = data.length - 1; i >= 0; i -= 1) {
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.addOffset(data[i]!)
|
|
|
|
}
|
|
|
|
return builder.endVector()
|
|
|
|
}
|
|
|
|
|
|
|
|
static startSegmentsVector(builder: Builder, numElems: number) {
|
|
|
|
builder.startVector(4, numElems, 4)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endPath(builder: Builder): Offset<Path> {
|
|
|
|
const offset = builder.endObject<Path>()
|
2023-10-07 23:57:47 +03:00
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createPath(
|
|
|
|
builder: Builder,
|
|
|
|
createRootId: CreateOffset<EnsoUUID>,
|
|
|
|
segmentsOffset: Offset<string[] | ArrayBuffer[]>,
|
|
|
|
): Offset<Path> {
|
2023-10-07 23:57:47 +03:00
|
|
|
Path.startPath(builder)
|
2023-11-27 18:48:37 +03:00
|
|
|
Path.addRootId(builder, createRootId?.(builder) ?? Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
Path.addSegments(builder, segmentsOffset)
|
|
|
|
return Path.endPath(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class WriteFileCommand implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): WriteFileCommand {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsWriteFileCommand(bb: ByteBuffer, obj?: WriteFileCommand): WriteFileCommand {
|
|
|
|
return (obj ?? new WriteFileCommand()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsWriteFileCommand(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: WriteFileCommand,
|
|
|
|
): WriteFileCommand {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new WriteFileCommand()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
path(obj?: Path): Path | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset ? (obj ?? new Path()).init(this.bb.indirect(this.bbPos + offset), this.bb!) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
contents(index: number): number | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset ? this.bb.view.getUint8(this.bb.vector(this.bbPos + offset) + index) : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
contentsLength(): number {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset ? this.bb.vectorLength(this.bbPos + offset) : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
contentsArray(): Uint8Array | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset
|
|
|
|
? new Uint8Array(
|
|
|
|
this.bb.view.buffer,
|
|
|
|
this.bb.view.byteOffset + this.bb.vector(this.bbPos + offset),
|
|
|
|
this.bb.vectorLength(this.bbPos + offset),
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startWriteFileCommand(builder: Builder) {
|
|
|
|
builder.startObject(2)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addPath(builder: Builder, pathOffset: Offset<Path>) {
|
|
|
|
builder.addFieldOffset(0, pathOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addContents(builder: Builder, contentsOffset: Offset<Uint8Array>) {
|
|
|
|
builder.addFieldOffset(1, contentsOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createContentsVector(builder: Builder, data: number[] | Uint8Array): Offset<Uint8Array> {
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.startVector(1, data.length, 1)
|
|
|
|
// An iterator is more type-safe, but less performant.
|
2023-11-03 23:09:45 +03:00
|
|
|
for (let i = data.length - 1; i >= 0; i -= 1) {
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.addInt8(data[i]!)
|
|
|
|
}
|
|
|
|
return builder.endVector()
|
|
|
|
}
|
|
|
|
|
|
|
|
static startContentsVector(builder: Builder, numElems: number) {
|
|
|
|
builder.startVector(1, numElems, 1)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endWriteFileCommand(builder: Builder): Offset<WriteFileCommand> {
|
|
|
|
const offset = builder.endObject<WriteFileCommand>()
|
2023-10-07 23:57:47 +03:00
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
|
|
|
static createWriteFileCommand(
|
|
|
|
builder: Builder,
|
2023-11-27 18:48:37 +03:00
|
|
|
pathOffset: Offset<Path>,
|
|
|
|
contentsOffset: Offset<Uint8Array>,
|
|
|
|
): Offset<WriteFileCommand> {
|
2023-10-07 23:57:47 +03:00
|
|
|
WriteFileCommand.startWriteFileCommand(builder)
|
|
|
|
WriteFileCommand.addPath(builder, pathOffset)
|
|
|
|
WriteFileCommand.addContents(builder, contentsOffset)
|
|
|
|
return WriteFileCommand.endWriteFileCommand(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ReadFileCommand implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): ReadFileCommand {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsReadFileCommand(bb: ByteBuffer, obj?: ReadFileCommand): ReadFileCommand {
|
|
|
|
return (obj ?? new ReadFileCommand()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsReadFileCommand(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: ReadFileCommand,
|
|
|
|
): ReadFileCommand {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new ReadFileCommand()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
path(obj?: Path): Path | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset ? (obj ?? new Path()).init(this.bb.indirect(this.bbPos + offset), this.bb!) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startReadFileCommand(builder: Builder) {
|
|
|
|
builder.startObject(1)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addPath(builder: Builder, pathOffset: Offset<Path>) {
|
|
|
|
builder.addFieldOffset(0, pathOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endReadFileCommand(builder: Builder): Offset<ReadFileCommand> {
|
|
|
|
const offset = builder.endObject<ReadFileCommand>()
|
2023-10-07 23:57:47 +03:00
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createReadFileCommand(
|
|
|
|
builder: Builder,
|
|
|
|
pathOffset: Offset<Path>,
|
|
|
|
): Offset<ReadFileCommand> {
|
2023-10-07 23:57:47 +03:00
|
|
|
ReadFileCommand.startReadFileCommand(builder)
|
|
|
|
ReadFileCommand.addPath(builder, pathOffset)
|
|
|
|
return ReadFileCommand.endReadFileCommand(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class FileContentsReply implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): FileContentsReply {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsFileContentsReply(bb: ByteBuffer, obj?: FileContentsReply): FileContentsReply {
|
|
|
|
return (obj ?? new FileContentsReply()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsFileContentsReply(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: FileContentsReply,
|
|
|
|
): FileContentsReply {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new FileContentsReply()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
contents(index: number): number | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset ? this.bb.view.getUint8(this.bb.vector(this.bbPos + offset) + index) : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
contentsLength(): number {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset ? this.bb.vectorLength(this.bbPos + offset) : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
contentsArray(): Uint8Array | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset
|
|
|
|
? new Uint8Array(
|
|
|
|
this.bb.view.buffer,
|
|
|
|
this.bb.view.byteOffset + this.bb.vector(this.bbPos + offset),
|
|
|
|
this.bb.vectorLength(this.bbPos + offset),
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startFileContentsReply(builder: Builder) {
|
|
|
|
builder.startObject(1)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addContents(builder: Builder, contentsOffset: Offset<Uint8Array>) {
|
|
|
|
builder.addFieldOffset(0, contentsOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createContentsVector(builder: Builder, data: number[] | Uint8Array): Offset<Uint8Array> {
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.startVector(1, data.length, 1)
|
|
|
|
// An iterator is more type-safe, but less performant.
|
2023-11-03 23:09:45 +03:00
|
|
|
for (let i = data.length - 1; i >= 0; i -= 1) {
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.addInt8(data[i]!)
|
|
|
|
}
|
|
|
|
return builder.endVector()
|
|
|
|
}
|
|
|
|
|
|
|
|
static startContentsVector(builder: Builder, numElems: number) {
|
|
|
|
builder.startVector(1, numElems, 1)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endFileContentsReply(builder: Builder): Offset<FileContentsReply> {
|
|
|
|
const offset = builder.endObject<FileContentsReply>()
|
2023-10-07 23:57:47 +03:00
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createFileContentsReply(
|
|
|
|
builder: Builder,
|
|
|
|
contentsOffset: Offset<Uint8Array>,
|
|
|
|
): Offset<FileContentsReply> {
|
2023-10-07 23:57:47 +03:00
|
|
|
FileContentsReply.startFileContentsReply(builder)
|
|
|
|
FileContentsReply.addContents(builder, contentsOffset)
|
|
|
|
return FileContentsReply.endFileContentsReply(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class WriteBytesCommand implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): WriteBytesCommand {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsWriteBytesCommand(bb: ByteBuffer, obj?: WriteBytesCommand): WriteBytesCommand {
|
|
|
|
return (obj ?? new WriteBytesCommand()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsWriteBytesCommand(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: WriteBytesCommand,
|
|
|
|
): WriteBytesCommand {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new WriteBytesCommand()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
path(obj?: Path): Path | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset ? (obj ?? new Path()).init(this.bb.indirect(this.bbPos + offset), this.bb!) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
byteOffset(): bigint {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset ? this.bb.view.getBigUint64(this.bbPos + offset, true) : 0n
|
|
|
|
}
|
|
|
|
|
|
|
|
overwriteExisting(): boolean {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 8)
|
|
|
|
return offset ? !!this.bb.view.getInt8(this.bbPos + offset) : false
|
|
|
|
}
|
|
|
|
|
|
|
|
bytes(index: number): number | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 10)
|
|
|
|
return offset ? this.bb.view.getUint8(this.bb.vector(this.bbPos + offset) + index) : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
bytesLength(): number {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 10)
|
|
|
|
return offset ? this.bb.vectorLength(this.bbPos + offset) : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
bytesArray(): Uint8Array | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 10)
|
|
|
|
return offset
|
|
|
|
? new Uint8Array(
|
|
|
|
this.bb.view.buffer,
|
|
|
|
this.bb.view.byteOffset + this.bb.vector(this.bbPos + offset),
|
|
|
|
this.bb.vectorLength(this.bbPos + offset),
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startWriteBytesCommand(builder: Builder) {
|
|
|
|
builder.startObject(4)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addPath(builder: Builder, pathOffset: Offset<Path>) {
|
|
|
|
builder.addFieldOffset(0, pathOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static addByteOffset(builder: Builder, byteOffset: bigint) {
|
|
|
|
builder.addFieldInt64(1, byteOffset, 0n)
|
|
|
|
}
|
|
|
|
|
|
|
|
static addOverwriteExisting(builder: Builder, overwriteExisting: boolean) {
|
|
|
|
builder.addFieldInt8(2, +overwriteExisting, +false)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addBytes(builder: Builder, bytesOffset: Offset<Uint8Array>) {
|
|
|
|
builder.addFieldOffset(3, bytesOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createBytesVector(builder: Builder, data: number[] | Uint8Array): Offset<Uint8Array> {
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.startVector(1, data.length, 1)
|
|
|
|
// An iterator is more type-safe, but less performant.
|
2023-11-03 23:09:45 +03:00
|
|
|
for (let i = data.length - 1; i >= 0; i -= 1) {
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.addInt8(data[i]!)
|
|
|
|
}
|
|
|
|
return builder.endVector()
|
|
|
|
}
|
|
|
|
|
|
|
|
static startBytesVector(builder: Builder, numElems: number) {
|
|
|
|
builder.startVector(1, numElems, 1)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endWriteBytesCommand(builder: Builder): Offset<WriteBytesCommand> {
|
|
|
|
const offset = builder.endObject<WriteBytesCommand>()
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.requiredField(offset, 4) // path
|
|
|
|
builder.requiredField(offset, 10) // bytes
|
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
|
|
|
static createWriteBytesCommand(
|
|
|
|
builder: Builder,
|
2023-11-27 18:48:37 +03:00
|
|
|
pathOffset: Offset<Path>,
|
2023-10-07 23:57:47 +03:00
|
|
|
byteOffset: bigint,
|
|
|
|
overwriteExisting: boolean,
|
2023-11-27 18:48:37 +03:00
|
|
|
bytesOffset: Offset<Uint8Array>,
|
|
|
|
): Offset<WriteBytesCommand> {
|
2023-10-07 23:57:47 +03:00
|
|
|
WriteBytesCommand.startWriteBytesCommand(builder)
|
|
|
|
WriteBytesCommand.addPath(builder, pathOffset)
|
|
|
|
WriteBytesCommand.addByteOffset(builder, byteOffset)
|
|
|
|
WriteBytesCommand.addOverwriteExisting(builder, overwriteExisting)
|
|
|
|
WriteBytesCommand.addBytes(builder, bytesOffset)
|
|
|
|
return WriteBytesCommand.endWriteBytesCommand(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class WriteBytesReply implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): WriteBytesReply {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsWriteBytesReply(bb: ByteBuffer, obj?: WriteBytesReply): WriteBytesReply {
|
|
|
|
return (obj ?? new WriteBytesReply()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsWriteBytesReply(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: WriteBytesReply,
|
|
|
|
): WriteBytesReply {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new WriteBytesReply()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
checksum(obj?: EnsoDigest): EnsoDigest | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset
|
|
|
|
? (obj ?? new EnsoDigest()).init(this.bb.indirect(this.bbPos + offset), this.bb!)
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startWriteBytesReply(builder: Builder) {
|
|
|
|
builder.startObject(1)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addChecksum(builder: Builder, checksumOffset: Offset<EnsoDigest>) {
|
|
|
|
builder.addFieldOffset(0, checksumOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endWriteBytesReply(builder: Builder): Offset<WriteBytesReply> {
|
|
|
|
const offset = builder.endObject<WriteBytesReply>()
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.requiredField(offset, 4) // checksum
|
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createWriteBytesReply(
|
|
|
|
builder: Builder,
|
|
|
|
checksumOffset: Offset<EnsoDigest>,
|
|
|
|
): Offset<WriteBytesReply> {
|
2023-10-07 23:57:47 +03:00
|
|
|
WriteBytesReply.startWriteBytesReply(builder)
|
|
|
|
WriteBytesReply.addChecksum(builder, checksumOffset)
|
|
|
|
return WriteBytesReply.endWriteBytesReply(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ReadBytesCommand implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): ReadBytesCommand {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsReadBytesCommand(bb: ByteBuffer, obj?: ReadBytesCommand): ReadBytesCommand {
|
|
|
|
return (obj ?? new ReadBytesCommand()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsReadBytesCommand(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: ReadBytesCommand,
|
|
|
|
): ReadBytesCommand {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new ReadBytesCommand()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
segment(obj?: FileSegment): FileSegment | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset
|
|
|
|
? (obj ?? new FileSegment()).init(this.bb.indirect(this.bbPos + offset), this.bb!)
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startReadBytesCommand(builder: Builder) {
|
|
|
|
builder.startObject(1)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addSegment(builder: Builder, segmentOffset: Offset<FileSegment>) {
|
|
|
|
builder.addFieldOffset(0, segmentOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endReadBytesCommand(builder: Builder): Offset<ReadBytesCommand> {
|
|
|
|
const offset = builder.endObject<ReadBytesCommand>()
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.requiredField(offset, 4) // segment
|
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createReadBytesCommand(
|
|
|
|
builder: Builder,
|
|
|
|
segmentOffset: Offset<FileSegment>,
|
|
|
|
): Offset<ReadBytesCommand> {
|
2023-10-07 23:57:47 +03:00
|
|
|
ReadBytesCommand.startReadBytesCommand(builder)
|
|
|
|
ReadBytesCommand.addSegment(builder, segmentOffset)
|
|
|
|
return ReadBytesCommand.endReadBytesCommand(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ReadBytesReply implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): ReadBytesReply {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsReadBytesReply(bb: ByteBuffer, obj?: ReadBytesReply): ReadBytesReply {
|
|
|
|
return (obj ?? new ReadBytesReply()).init(bb.view.getInt32(bb.position, true) + bb.position, bb)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsReadBytesReply(bb: ByteBuffer, obj?: ReadBytesReply): ReadBytesReply {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new ReadBytesReply()).init(bb.view.getInt32(bb.position, true) + bb.position, bb)
|
|
|
|
}
|
|
|
|
|
|
|
|
checksum(obj?: EnsoDigest): EnsoDigest | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset
|
|
|
|
? (obj ?? new EnsoDigest()).init(this.bb.indirect(this.bbPos + offset), this.bb!)
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
|
|
|
|
bytes(index: number): number | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset ? this.bb.view.getUint8(this.bb.vector(this.bbPos + offset) + index) : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
bytesLength(): number {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset ? this.bb.vectorLength(this.bbPos + offset) : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
bytesArray(): Uint8Array | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset
|
|
|
|
? new Uint8Array(
|
|
|
|
this.bb.view.buffer,
|
|
|
|
this.bb.view.byteOffset + this.bb.vector(this.bbPos + offset),
|
|
|
|
this.bb.vectorLength(this.bbPos + offset),
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startReadBytesReply(builder: Builder) {
|
|
|
|
builder.startObject(2)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addChecksum(builder: Builder, checksumOffset: Offset<EnsoDigest>) {
|
|
|
|
builder.addFieldOffset(0, checksumOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addBytes(builder: Builder, bytesOffset: Offset<Uint8Array>) {
|
|
|
|
builder.addFieldOffset(1, bytesOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createBytesVector(builder: Builder, data: number[] | Uint8Array): Offset<Uint8Array> {
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.startVector(1, data.length, 1)
|
|
|
|
// An iterator is more type-safe, but less performant.
|
2023-11-03 23:09:45 +03:00
|
|
|
for (let i = data.length - 1; i >= 0; i -= 1) {
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.addInt8(data[i]!)
|
|
|
|
}
|
|
|
|
return builder.endVector()
|
|
|
|
}
|
|
|
|
|
|
|
|
static startBytesVector(builder: Builder, numElems: number) {
|
|
|
|
builder.startVector(1, numElems, 1)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endReadBytesReply(builder: Builder): Offset<ReadBytesReply> {
|
|
|
|
const offset = builder.endObject<ReadBytesReply>()
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.requiredField(offset, 4) // checksum
|
|
|
|
builder.requiredField(offset, 6) // bytes
|
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
|
|
|
static createReadBytesReply(
|
|
|
|
builder: Builder,
|
2023-11-27 18:48:37 +03:00
|
|
|
checksumOffset: Offset<EnsoDigest>,
|
|
|
|
bytesOffset: Offset<Uint8Array>,
|
|
|
|
): Offset<ReadBytesReply> {
|
2023-10-07 23:57:47 +03:00
|
|
|
ReadBytesReply.startReadBytesReply(builder)
|
|
|
|
ReadBytesReply.addChecksum(builder, checksumOffset)
|
|
|
|
ReadBytesReply.addBytes(builder, bytesOffset)
|
|
|
|
return ReadBytesReply.endReadBytesReply(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ChecksumBytesCommand implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): ChecksumBytesCommand {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsChecksumBytesCommand(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: ChecksumBytesCommand,
|
|
|
|
): ChecksumBytesCommand {
|
|
|
|
return (obj ?? new ChecksumBytesCommand()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsChecksumBytesCommand(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: ChecksumBytesCommand,
|
|
|
|
): ChecksumBytesCommand {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new ChecksumBytesCommand()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
segment(obj?: FileSegment): FileSegment | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset
|
|
|
|
? (obj ?? new FileSegment()).init(this.bb.indirect(this.bbPos + offset), this.bb!)
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startChecksumBytesCommand(builder: Builder) {
|
|
|
|
builder.startObject(1)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addSegment(builder: Builder, segmentOffset: Offset<FileSegment>) {
|
|
|
|
builder.addFieldOffset(0, segmentOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endChecksumBytesCommand(builder: Builder): Offset<ChecksumBytesCommand> {
|
|
|
|
const offset = builder.endObject<ChecksumBytesCommand>()
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.requiredField(offset, 4) // segment
|
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createChecksumBytesCommand(
|
|
|
|
builder: Builder,
|
|
|
|
segmentOffset: Offset<FileSegment>,
|
|
|
|
): Offset<ChecksumBytesCommand> {
|
2023-10-07 23:57:47 +03:00
|
|
|
ChecksumBytesCommand.startChecksumBytesCommand(builder)
|
|
|
|
ChecksumBytesCommand.addSegment(builder, segmentOffset)
|
|
|
|
return ChecksumBytesCommand.endChecksumBytesCommand(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ChecksumBytesReply implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): ChecksumBytesReply {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsChecksumBytesReply(bb: ByteBuffer, obj?: ChecksumBytesReply): ChecksumBytesReply {
|
|
|
|
return (obj ?? new ChecksumBytesReply()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsChecksumBytesReply(
|
|
|
|
bb: ByteBuffer,
|
|
|
|
obj?: ChecksumBytesReply,
|
|
|
|
): ChecksumBytesReply {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new ChecksumBytesReply()).init(
|
|
|
|
bb.view.getInt32(bb.position, true) + bb.position,
|
|
|
|
bb,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
checksum(obj?: EnsoDigest): EnsoDigest | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset
|
|
|
|
? (obj ?? new EnsoDigest()).init(this.bb.indirect(this.bbPos + offset), this.bb!)
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startChecksumBytesReply(builder: Builder) {
|
|
|
|
builder.startObject(1)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addChecksum(builder: Builder, checksumOffset: Offset<EnsoDigest>) {
|
|
|
|
builder.addFieldOffset(0, checksumOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endChecksumBytesReply(builder: Builder): Offset<ChecksumBytesReply> {
|
|
|
|
const offset = builder.endObject<ChecksumBytesReply>()
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.requiredField(offset, 4) // checksum
|
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createChecksumBytesReply(
|
|
|
|
builder: Builder,
|
|
|
|
checksumOffset: Offset<EnsoDigest>,
|
|
|
|
): Offset<ChecksumBytesReply> {
|
2023-10-07 23:57:47 +03:00
|
|
|
ChecksumBytesReply.startChecksumBytesReply(builder)
|
|
|
|
ChecksumBytesReply.addChecksum(builder, checksumOffset)
|
|
|
|
return ChecksumBytesReply.endChecksumBytesReply(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class EnsoDigest implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): EnsoDigest {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsEnsoDigest(bb: ByteBuffer, obj?: EnsoDigest): EnsoDigest {
|
|
|
|
return (obj ?? new EnsoDigest()).init(bb.view.getInt32(bb.position, true) + bb.position, bb)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsEnsoDigest(bb: ByteBuffer, obj?: EnsoDigest): EnsoDigest {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new EnsoDigest()).init(bb.view.getInt32(bb.position, true) + bb.position, bb)
|
|
|
|
}
|
|
|
|
|
|
|
|
bytes(index: number): number | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset ? this.bb.view.getUint8(this.bb.vector(this.bbPos + offset) + index) : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
bytesLength(): number {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset ? this.bb.vectorLength(this.bbPos + offset) : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
bytesArray(): Uint8Array | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset
|
|
|
|
? new Uint8Array(
|
|
|
|
this.bb.view.buffer,
|
|
|
|
this.bb.view.byteOffset + this.bb.vector(this.bbPos + offset),
|
|
|
|
this.bb.vectorLength(this.bbPos + offset),
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
|
|
|
|
static startEnsoDigest(builder: Builder) {
|
|
|
|
builder.startObject(1)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addBytes(builder: Builder, bytesOffset: Offset<Uint8Array>) {
|
|
|
|
builder.addFieldOffset(0, bytesOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createBytesVector(builder: Builder, data: number[] | Uint8Array): Offset<Uint8Array> {
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.startVector(1, data.length, 1)
|
|
|
|
// An iterator is more type-safe, but less performant.
|
2023-11-03 23:09:45 +03:00
|
|
|
for (let i = data.length - 1; i >= 0; i -= 1) {
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.addInt8(data[i]!)
|
|
|
|
}
|
|
|
|
return builder.endVector()
|
|
|
|
}
|
|
|
|
|
|
|
|
static startBytesVector(builder: Builder, numElems: number) {
|
|
|
|
builder.startVector(1, numElems, 1)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endEnsoDigest(builder: Builder): Offset<EnsoDigest> {
|
|
|
|
const offset = builder.endObject<EnsoDigest>()
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.requiredField(offset, 4) // bytes
|
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static createEnsoDigest(builder: Builder, bytesOffset: Offset<Uint8Array>): Offset<EnsoDigest> {
|
2023-10-07 23:57:47 +03:00
|
|
|
EnsoDigest.startEnsoDigest(builder)
|
|
|
|
EnsoDigest.addBytes(builder, bytesOffset)
|
|
|
|
return EnsoDigest.endEnsoDigest(builder)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class FileSegment implements Table {
|
|
|
|
bb!: ByteBuffer
|
|
|
|
bbPos: number = 0
|
|
|
|
init(i: number, bb: ByteBuffer): FileSegment {
|
|
|
|
this.bbPos = i
|
|
|
|
this.bb = bb
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
static getRootAsFileSegment(bb: ByteBuffer, obj?: FileSegment): FileSegment {
|
|
|
|
return (obj ?? new FileSegment()).init(bb.view.getInt32(bb.position, true) + bb.position, bb)
|
|
|
|
}
|
|
|
|
|
|
|
|
static getSizePrefixedRootAsFileSegment(bb: ByteBuffer, obj?: FileSegment): FileSegment {
|
|
|
|
bb.position += SIZE_PREFIX_LENGTH
|
|
|
|
return (obj ?? new FileSegment()).init(bb.view.getInt32(bb.position, true) + bb.position, bb)
|
|
|
|
}
|
|
|
|
|
|
|
|
path(obj?: Path): Path | null {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 4)
|
|
|
|
return offset ? (obj ?? new Path()).init(this.bb.indirect(this.bbPos + offset), this.bb!) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
byteOffset(): bigint {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 6)
|
|
|
|
return offset ? this.bb.view.getBigUint64(this.bbPos + offset, true) : 0n
|
|
|
|
}
|
|
|
|
|
|
|
|
length(): bigint {
|
|
|
|
const offset = this.bb.offset(this.bbPos, 8)
|
|
|
|
return offset ? this.bb.view.getBigUint64(this.bbPos + offset, true) : 0n
|
|
|
|
}
|
|
|
|
|
|
|
|
static startFileSegment(builder: Builder) {
|
|
|
|
builder.startObject(3)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static addPath(builder: Builder, pathOffset: Offset<Path>) {
|
|
|
|
builder.addFieldOffset(0, pathOffset, Null)
|
2023-10-07 23:57:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static addByteOffset(builder: Builder, byteOffset: bigint) {
|
|
|
|
builder.addFieldInt64(1, byteOffset, 0n)
|
|
|
|
}
|
|
|
|
|
|
|
|
static addLength(builder: Builder, length: bigint) {
|
|
|
|
builder.addFieldInt64(2, length, 0n)
|
|
|
|
}
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
static endFileSegment(builder: Builder): Offset<FileSegment> {
|
|
|
|
const offset = builder.endObject<FileSegment>()
|
2023-10-07 23:57:47 +03:00
|
|
|
builder.requiredField(offset, 4) // path
|
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
|
|
|
static createFileSegment(
|
|
|
|
builder: Builder,
|
2023-11-27 18:48:37 +03:00
|
|
|
pathOffset: Offset<Path>,
|
2023-10-07 23:57:47 +03:00
|
|
|
byteOffset: bigint,
|
|
|
|
length: bigint,
|
2023-11-27 18:48:37 +03:00
|
|
|
): Offset<FileSegment> {
|
2023-10-07 23:57:47 +03:00
|
|
|
FileSegment.startFileSegment(builder)
|
|
|
|
FileSegment.addPath(builder, pathOffset)
|
|
|
|
FileSegment.addByteOffset(builder, byteOffset)
|
|
|
|
FileSegment.addLength(builder, length)
|
|
|
|
return FileSegment.endFileSegment(builder)
|
|
|
|
}
|
|
|
|
}
|