@foxglove/cdr
Advanced tools
Comparing version 3.2.1 to 3.3.0
@@ -38,2 +38,3 @@ import { EncapsulationKind } from "./EncapsulationKind"; | ||
* See Extensible and Dynamic Topic Types (DDS-XTypes) v1.3 @ `7.4.3.4.2` for more info about CDR2 EMHEADER composition. | ||
* If a sentinelHeader was read (PL_CDR v1), the readSentinelHeader flag is set to true. | ||
*/ | ||
@@ -45,2 +46,3 @@ emHeader(): { | ||
lengthCode?: LengthCode; | ||
readSentinelHeader?: boolean; | ||
}; | ||
@@ -47,0 +49,0 @@ /** XCDR1 PL_CDR encapsulation parameter header*/ |
@@ -133,2 +133,3 @@ "use strict"; | ||
* See Extensible and Dynamic Topic Types (DDS-XTypes) v1.3 @ `7.4.3.4.2` for more info about CDR2 EMHEADER composition. | ||
* If a sentinelHeader was read (PL_CDR v1), the readSentinelHeader flag is set to true. | ||
*/ | ||
@@ -157,3 +158,5 @@ emHeader() { | ||
if (sentinelPIDFlag) { | ||
throw Error("Expected Member Header but got SENTINEL_PID Flag"); | ||
// Return that we have read the sentinel header when we expected to read an emHeader. | ||
// This can happen for absent optional members at the end of a struct. | ||
return { id: reservedPIDs_1.SENTINEL_PID, objectSize: 0, mustUnderstand: false, readSentinelHeader: true }; | ||
} | ||
@@ -160,0 +163,0 @@ // Indicates that the ID should be ignored |
@@ -198,2 +198,9 @@ "use strict"; | ||
}); | ||
it("returns readSentinelHeader==true if the emHeader read a sentinel header", () => { | ||
const writer = new CdrWriter_1.CdrWriter({ kind: _1.EncapsulationKind.PL_CDR_LE }); | ||
writer.sentinelHeader(); | ||
const reader = new CdrReader_1.CdrReader(writer.data); | ||
const emHeader = reader.emHeader(); | ||
expect(emHeader.readSentinelHeader).toEqual(true); | ||
}); | ||
it("errors when expecting to read a sentinel header but receives non-sentinel_PID value", () => { | ||
@@ -200,0 +207,0 @@ const writer = new CdrWriter_1.CdrWriter({ kind: _1.EncapsulationKind.PL_CDR_LE }); |
{ | ||
"name": "@foxglove/cdr", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"description": "Common Data Representation serialization and deserialization library", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -80,2 +80,2 @@ # @foxglove/cdr | ||
Join our [Slack channel](https://foxglove.dev/join-slack) to ask questions, share feedback, and stay up to date on what our team is working on. | ||
Join our [Slack channel](https://foxglove.dev/slack) to ask questions, share feedback, and stay up to date on what our team is working on. |
@@ -252,2 +252,11 @@ import { EncapsulationKind } from "."; | ||
it("returns readSentinelHeader==true if the emHeader read a sentinel header", () => { | ||
const writer = new CdrWriter({ kind: EncapsulationKind.PL_CDR_LE }); | ||
writer.sentinelHeader(); | ||
const reader = new CdrReader(writer.data); | ||
const emHeader = reader.emHeader(); | ||
expect(emHeader.readSentinelHeader).toEqual(true); | ||
}); | ||
it("errors when expecting to read a sentinel header but receives non-sentinel_PID value", () => { | ||
@@ -254,0 +263,0 @@ const writer = new CdrWriter({ kind: EncapsulationKind.PL_CDR_LE }); |
@@ -193,4 +193,11 @@ import { EncapsulationKind } from "./EncapsulationKind"; | ||
* See Extensible and Dynamic Topic Types (DDS-XTypes) v1.3 @ `7.4.3.4.2` for more info about CDR2 EMHEADER composition. | ||
* If a sentinelHeader was read (PL_CDR v1), the readSentinelHeader flag is set to true. | ||
*/ | ||
emHeader(): { mustUnderstand: boolean; id: number; objectSize: number; lengthCode?: LengthCode } { | ||
emHeader(): { | ||
mustUnderstand: boolean; | ||
id: number; | ||
objectSize: number; | ||
lengthCode?: LengthCode; | ||
readSentinelHeader?: boolean; | ||
} { | ||
if (this.isCDR2) { | ||
@@ -208,2 +215,3 @@ return this.memberHeaderV2(); | ||
mustUnderstand: boolean; | ||
readSentinelHeader?: boolean; | ||
} { | ||
@@ -225,3 +233,5 @@ // 4-byte header with two 16-bit fields | ||
if (sentinelPIDFlag) { | ||
throw Error("Expected Member Header but got SENTINEL_PID Flag"); | ||
// Return that we have read the sentinel header when we expected to read an emHeader. | ||
// This can happen for absent optional members at the end of a struct. | ||
return { id: SENTINEL_PID, objectSize: 0, mustUnderstand: false, readSentinelHeader: true }; | ||
} | ||
@@ -228,0 +238,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
217670
3601