Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BBO.NestedBufferBackedObject doesn't work at all (or I am not understanding it correctly?) #43

Open
webhype opened this issue Sep 25, 2023 · 0 comments

Comments

@webhype
Copy link

webhype commented Sep 25, 2023

Consider the below sample code to reproduce the problem.

When I populate ONLY "record 1" (as opposed to "record 0") of the arrayView, and then query the uninitialized "virgin" nested object that should belong to record 0, then the expected result would be an empty string or undefined or null or something to that effect.

However, it outputs the nested object from index 1; in the below code it prints "hello, this is record 1". When I "flatten" the hierarchy and avoid NestedBufferBackedObject, then an index of 0 returns only what pertains to record 0 and not record 1 (i.e. expected behavior).

import * as BBO from "buffer-backed-object";

const ARRAY_STRUCT = {
	id: BBO.Uint32({endianness: "big"}),
	nestedObject: BBO.NestedBufferBackedObject({
		nestedStr: BBO.UTF8String(80),
	}),
}

const size = 1000;
const arrayBuf = new SharedArrayBuffer(size * BBO.structSize(ARRAY_STRUCT));
const arrayView = BBO.ArrayOfBufferBackedObjects(arrayBuf, ARRAY_STRUCT);

let bbo1 = arrayView[1];	// <== populating record 1, not 0!
bbo1.id = 123;
bbo1.nestedObject.nestedStr = "hello, this is record 1";

let bbo0 = arrayView[0];	// <== retrieving record 0, not 1!
// Expected result: Empty string
// Actual result: hello, this is record 1
console.log(bbo0.nestedObject.nestedStr);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant