Skip to content

Commit

Permalink
define constants for bytes per js number and bytes per agent data
Browse files Browse the repository at this point in the history
  • Loading branch information
interim17 committed Sep 30, 2024
1 parent 51787ab commit 6d32a9a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AGENT_OBJECT_KEYS,
AgentData,
CameraSpec,
PerspectiveCameraSpec,
Expand Down Expand Up @@ -52,3 +53,6 @@ export const nullAgent = (): AgentData => {

// the size of the header before the agent data in the binary file
export const AGENT_HEADER_SIZE = 3; // frameNumber, time, agentCount

export const BYTE_SIZE_64_BIT_NUM = 8;
export const BYTES_PER_AGENT = BYTE_SIZE_64_BIT_NUM * AGENT_OBJECT_KEYS.length;
6 changes: 3 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ISimulariumFile } from "./simularium/ISimulariumFile";
import JsonFileReader from "./simularium/JsonFileReader";
import BinaryFileReader from "./simularium/BinaryFileReader";
import { AGENT_OBJECT_KEYS, AgentData, CachedFrame } from "./simularium/types";
import { nullAgent } from "./constants";
import { BYTES_PER_AGENT, BYTE_SIZE_64_BIT_NUM, nullAgent } from "./constants";

export const compareTimes = (
time1: number,
Expand Down Expand Up @@ -83,8 +83,8 @@ export function calculateCachedSize(parsedAgentData: AgentData[]): number {
// Calculate the size of parsedAgentDataArray
for (let j = 0; j < parsedAgentData.length; ++j) {
const agent = parsedAgentData[j];
totalSize += 8 * 10; // 10 number properties in AgentData (excluding subpoints)
totalSize += agent.subpoints.length * 8;
totalSize += BYTES_PER_AGENT; // 10 number properties in AgentData (excluding subpoints)
totalSize += agent.subpoints.length * BYTE_SIZE_64_BIT_NUM;
}

return (totalSize += 16); // should always be 16 bytes bceause its just one frame per message with octopus
Expand Down

0 comments on commit 6d32a9a

Please sign in to comment.