Skip to content

Commit

Permalink
Use branded types
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Dec 19, 2024
1 parent b039a45 commit 3a4fd9c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/ncm/src/content-meta-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class NcmContentMetaDatabase {
inArr.set(new Uint8Array(key), 0x8);
const out = new ArrayBuffer(0x10);
this.#srv.dispatchInOut(3, inData, out);
return out;
return out as NcmContentId;
}

has(key: NcmContentMetaKey): boolean {
Expand Down
6 changes: 3 additions & 3 deletions packages/ncm/src/content-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class NcmContentStorage {
//}
const uuid = new ArrayBuffer(0x10);
this.#srv.dispatchOut(0, uuid);
return uuid;
return uuid as NcmPlaceHolderId;
}

createPlaceHolder(
Expand Down Expand Up @@ -223,7 +223,7 @@ export class NcmContentStorage {
const outCount = out[0];
const rtn: NcmPlaceHolderId[] = new Array(outCount);
for (let i = 0; i < outCount; i++) {
rtn[i] = outIds.slice(i * 0x10, i * 0x10 + 0x10);
rtn[i] = outIds.slice(i * 0x10, i * 0x10 + 0x10) as NcmPlaceHolderId;
}
return rtn;
}
Expand Down Expand Up @@ -257,7 +257,7 @@ export class NcmContentStorage {
const outCount = out[0];
const rtn: NcmContentId[] = new Array(outCount);
for (let i = 0; i < outCount; i++) {
rtn[i] = outIds.slice(i * 0x10, i * 0x10 + 0x10);
rtn[i] = outIds.slice(i * 0x10, i * 0x10 + 0x10) as NcmContentId;
}
return rtn;
}
Expand Down
10 changes: 8 additions & 2 deletions packages/ncm/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,19 @@ export enum NcmContentMetaPlatform {
//typedef struct {
// u8 c[0x10]; ///< Id
//} NcmContentId;
export type NcmContentId = ArrayBuffer;
declare const contentIdSymbol: unique symbol;
export type NcmContentId = ArrayBuffer & {
[contentIdSymbol]: void;
};

/// PlaceHolderId
//typedef struct {
// Uuid uuid; ///< UUID
//} NcmPlaceHolderId;
export type NcmPlaceHolderId = ArrayBuffer;
declare const placeHolderIdSymbol: unique symbol;
export type NcmPlaceHolderId = ArrayBuffer & {
[placeHolderIdSymbol]: void;
};

/// ContentMetaKey
//typedef struct {
Expand Down

0 comments on commit 3a4fd9c

Please sign in to comment.