@lichtblick/cdr
Version:
Common Data Representation serialization and deserialization library
78 lines • 3.99 kB
TypeScript
import { EncapsulationKind } from "./EncapsulationKind";
export type CdrWriterOpts = {
buffer?: ArrayBuffer;
size?: number;
kind?: EncapsulationKind;
};
export declare class CdrWriter {
#private;
static DEFAULT_CAPACITY: number;
static BUFFER_COPY_THRESHOLD: number;
get data(): Uint8Array;
get size(): number;
get kind(): EncapsulationKind;
constructor(options?: CdrWriterOpts);
int8(value: number): this;
uint8(value: number): this;
int16(value: number): this;
uint16(value: number): this;
int32(value: number): this;
uint32(value: number): this;
int64(value: bigint): this;
uint64(value: bigint): this;
uint16BE(value: number): this;
uint32BE(value: number): this;
uint64BE(value: bigint): this;
float32(value: number): this;
float64(value: number): this;
string(value: string, writeLength?: boolean): this;
/** Writes the delimiter header using object size
* NOTE: changing endian-ness with a single CDR message is not supported
*/
dHeader(objectSize: number): this;
/**
* Writes the member header (EMHEADER)
* Accomodates for PL_CDR and PL_CDR2 based on the CdrWriter constructor options
*
* @param mustUnderstand - Whether the member is required to be understood by the receiver
* @param id - The member ID
* @param objectSize - The size of the member in bytes
* @param lengthCode - Optional length code for CDR2 emHeaders.
* lengthCode values [5-7] allow the emHeader object size to take the place of the normally encoded member length.
*
* NOTE: Dynamically determines default value if not provided that does not affect serialization ie will use lengthCode values [0-4].
*
* From Extensible and Dynamic Topic Types in DDS-XTypes v1.3 @ `7.4.3.4.2`:
* "EMHEADER1 with LC values 5 to 7 also affect the serialization/deserialization virtual machine in that they cause NEXTINT to be
* reused also as part of the serialized member. This is useful because the serialization of certain members also starts with an
* integer length, which would take exactly the same value as NEXTINT. Therefore the use of length codes 5 to 7 saves 4 bytes in
* the serialization."
* @returns - CdrWriter instance
*/
emHeader(mustUnderstand: boolean, id: number, objectSize: number, lengthCode?: number): this;
/** Writes the PID_SENTINEL value if encapsulation supports it*/
sentinelHeader(): this;
sequenceLength(value: number): this;
int8Array(value: Int8Array | number[], writeLength?: boolean): this;
uint8Array(value: Uint8Array | number[], writeLength?: boolean): this;
int16Array(value: Int16Array | number[], writeLength?: boolean): this;
uint16Array(value: Uint16Array | number[], writeLength?: boolean): this;
int32Array(value: Int32Array | number[], writeLength?: boolean): this;
uint32Array(value: Uint32Array | number[], writeLength?: boolean): this;
int64Array(value: BigInt64Array | bigint[] | number[], writeLength?: boolean): this;
uint64Array(value: BigUint64Array | bigint[] | number[], writeLength?: boolean): this;
float32Array(value: Float32Array | number[], writeLength?: boolean): this;
float64Array(value: Float64Array | number[], writeLength?: boolean): this;
/**
* Calculate the capacity needed to hold the given number of aligned bytes,
* resize if needed, and write padding bytes for alignment
* @param size Byte width to align to. If the current #offset is 1 and `size`
* is 4, 3 bytes of padding will be written
* @param bytesToWrite Optional, total amount of bytes that are intended to be
* written directly following the alignment. This can be used to avoid
* additional #buffer resizes in the case of writing large blocks of aligned
* data such as arrays
*/
align(size: number, bytesToWrite?: number): void;
}
//# sourceMappingURL=CdrWriter.d.ts.map