Skip to content

Commit

Permalink
Add back accidentally deleted deserializeOptionStr and mark deprecated (
Browse files Browse the repository at this point in the history
#597)

* Add back function that was supposed to be deprecated

* update deprecated comment

* update changelog
  • Loading branch information
heliuchuan authored and kaw2k committed Dec 19, 2024
1 parent 35bd157 commit 401ee0e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to the Aptos TypeScript SDK will be captured in this file. T
- Add `gasProfile` function to `Move` class to allow for gas profiling of Aptos Move functions
- `PrivateKey.formatPrivateKey` now supports formatting AIP-80 strings
- Removed strictness warnings for bytes AIP-80 private key parsing formatting.
- Add accidentally deleted `deserializeOptionStr` and mark deprecated to unbreak Wallet Adapter

# 1.33.0 (2024-11-13)

Expand Down
18 changes: 17 additions & 1 deletion src/bcs/deserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export class Deserializer {
}

/**
* @deprecated use `deserializeOption` instead.
* Deserializes a UTF-8 encoded string from a byte array. It first reads the length of the string in bytes,
* followed by the actual byte content, and decodes it into a string.
*
Expand All @@ -101,6 +100,23 @@ export class Deserializer {
return textDecoder.decode(value);
}

/**
* @deprecated use `deserializeOption("string")` instead.
*
* The BCS layout for Optional<String> is 0 if none, else 1 followed by the string length and string content.
* @returns The deserialized string if it exists, otherwise undefined.
* @example
* ```typescript
* const deserializer = new Deserializer(new Uint8Array([0x00]));
* assert(deserializer.deserializeOptionStr() === undefined);
* const deserializer = new Deserializer(new Uint8Array([1, 8, 49, 50, 51, 52, 97, 98, 99, 100]));
* assert(deserializer.deserializeOptionStr() === "1234abcd");
* ```
*/
deserializeOptionStr(): string | undefined {
return this.deserializeOption("string");
}

/**
* Deserializes an optional value from the buffer.
*
Expand Down

0 comments on commit 401ee0e

Please sign in to comment.