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

Ability to override Uint8Array with a inherited type e.g. Buffer #4

Merged
merged 1 commit into from
Jul 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Read-only token
* See https://github.com/Borewit/strtok3 for more information
*/
export interface IGetToken<T> {
export interface IGetToken<Value, Array extends Uint8Array = Uint8Array> {

/**
* Length of encoded token in bytes
Expand All @@ -15,16 +15,16 @@ export interface IGetToken<T> {
* @param offset - Decode offset
* @return decoded value
*/
get(array: Uint8Array, offset: number): T;
get(array: Array, offset: number): Value;
}

export interface IToken<T> extends IGetToken<T> {
export interface IToken<Value, Array extends Uint8Array = Uint8Array> extends IGetToken<Value, Array> {
/**
* Encode value to buffer
* @param array - Uint8Array to write the encoded value to
* @param offset - Buffer write offset
* @param value - Value to decode of type T
* @return offset plus number of bytes written
*/
put(array: Uint8Array, offset: number, value: T): number
put(array: Array, offset: number, value: Value): number
}