Skip to content

Commit

Permalink
comments for further clarity around encodedData
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Aug 4, 2023
1 parent 86ea487 commit 201c7b2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/core/dwn-constant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export class DwnConstant {
/**
* The maximum size in bytes of raw data that will be returned as `encodedData`.
* this is also the maximum size that we will store within MessageStore.
*/
public static readonly maxDataSizeAllowedToBeEncoded = 50_000;
}
3 changes: 2 additions & 1 deletion src/handlers/messages-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export class MessagesGetHandler implements MethodHandler {
continue;
}

// RecordsWrite specific handling
// RecordsWrite specific handling, if MessageStore has embedded `encodedData` return it with the entry.
// we store `encodedData` along with the message if the data is below a certain threshold.
const recordsWrite = message as RecordsWriteMessageWithOptionalEncodedData;
if (recordsWrite.encodedData !== undefined) {
entry.encodedData = recordsWrite.encodedData;
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/records-write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ export class RecordsWriteHandler implements MethodHandler {
}

try {
// if data is below the threshold, we store it within MessageStore
if (message.descriptor.dataSize <= DwnConstant.maxDataSizeAllowedToBeEncoded) {
// processes and sets `encodedData` with appropriate data to be saved in MessageStore.
// processes and sets `encodedData` with appropriate data.
messageWithOptionalEncodedData = await this.processEncodedData(
message,
dataStream,
Expand Down
1 change: 1 addition & 0 deletions src/store/storage-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ export class StorageController {
}
}

// records with a data size below a threshold are stored within MessageStore with their data embedded
export type RecordsWriteMessageWithOptionalEncodedData = RecordsWriteMessage & { encodedData?: string };

0 comments on commit 201c7b2

Please sign in to comment.