Skip to content

Commit

Permalink
Run style:fix
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher committed Jan 17, 2025
1 parent f1620af commit 63832f3
Show file tree
Hide file tree
Showing 23 changed files with 221 additions and 221 deletions.
8 changes: 4 additions & 4 deletions examples/react-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ This is an example of how to use `@solana/web3.js` and `@solana/react` to build

## Features

- Connects to browser wallets that support the Wallet Standard; one or more at a time
- Fetches and subscribes to the balance of the selected wallet
- Allows you to sign an arbitrary message using a wallet account
- Allows you to make a transfer from the selected wallet to any other connected wallet
- Connects to browser wallets that support the Wallet Standard; one or more at a time
- Fetches and subscribes to the balance of the selected wallet
- Allows you to sign an arbitrary message using a wallet account
- Allows you to make a transfer from the selected wallet to any other connected wallet

## Developing

Expand Down
38 changes: 19 additions & 19 deletions packages/codecs-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const person = personCodec.decode(bytes);

There is a significant library of composable codecs at your disposal, enabling you to compose complex types. You may be interested in the documentation of these other packages to learn more about them:

- [`@solana/codecs-numbers`](https://github.com/anza-xyz/solana-web3.js/tree/main/packages/codecs-numbers) for number codecs.
- [`@solana/codecs-strings`](https://github.com/anza-xyz/solana-web3.js/tree/main/packages/codecs-strings) for string codecs.
- [`@solana/codecs-data-structures`](https://github.com/anza-xyz/solana-web3.js/tree/main/packages/codecs-data-structures) for many data structure codecs such as objects, arrays, tuples, sets, maps, enums, discriminated unions, booleans, etc.
- [`@solana/options`](https://github.com/anza-xyz/solana-web3.js/tree/main/packages/options) for a Rust-like `Option` type and associated codec.
- [`@solana/codecs-numbers`](https://github.com/anza-xyz/solana-web3.js/tree/main/packages/codecs-numbers) for number codecs.
- [`@solana/codecs-strings`](https://github.com/anza-xyz/solana-web3.js/tree/main/packages/codecs-strings) for string codecs.
- [`@solana/codecs-data-structures`](https://github.com/anza-xyz/solana-web3.js/tree/main/packages/codecs-data-structures) for many data structure codecs such as objects, arrays, tuples, sets, maps, enums, discriminated unions, booleans, etc.
- [`@solana/options`](https://github.com/anza-xyz/solana-web3.js/tree/main/packages/options) for a Rust-like `Option` type and associated codec.

You may also be interested in some of the helpers of this `@solana/codecs-core` library such as `transformCodec`, `fixCodecSize` or `reverseCodec` that create new codecs from existing ones.

Expand Down Expand Up @@ -159,19 +159,19 @@ The following type guards are available to identify and/or assert the size of co

Finally, note that the same is true for `Encoders` and `Decoders`.

- A `FixedSizeEncoder` has a `fixedSize` number attribute.
- A `VariableSizeEncoder` has a `getSizeFromValue` function and an optional `maxSize` number attribute.
- A `FixedSizeDecoder` has a `fixedSize` number attribute.
- A `VariableSizeDecoder` has an optional `maxSize` number attribute.
- A `FixedSizeEncoder` has a `fixedSize` number attribute.
- A `VariableSizeEncoder` has a `getSizeFromValue` function and an optional `maxSize` number attribute.
- A `FixedSizeDecoder` has a `fixedSize` number attribute.
- A `VariableSizeDecoder` has an optional `maxSize` number attribute.

## Creating custom codecs

If composing codecs isn’t enough for you, you may implement your own codec logic by using the `createCodec` function. This function requires an object with a `read` and a `write` function telling us how to read from and write to an existing byte array.

The `read` function accepts the `bytes` to decode from and the `offset` at each we should start reading. It returns an array with two items:

- The first item should be the decoded value.
- The second item should be the next offset to read from.
- The first item should be the decoded value.
- The second item should be the next offset to read from.

```ts
createCodec({
Expand Down Expand Up @@ -533,14 +533,14 @@ u32InTheMiddleCodec.encode(0xffffffff);

Both the `preOffset` and `postOffset` functions offer the following attributes:

- `bytes`: The entire byte array being encoded or decoded.
- `preOffset`: The original and unaltered pre-offset.
- `wrapBytes`: A helper function that wraps the given offset around the byte array length. E.g. `wrapBytes(-1)` will refer to the last byte of the byte array.
- `bytes`: The entire byte array being encoded or decoded.
- `preOffset`: The original and unaltered pre-offset.
- `wrapBytes`: A helper function that wraps the given offset around the byte array length. E.g. `wrapBytes(-1)` will refer to the last byte of the byte array.

Additionally, the post-offset function also provides the following attributes:

- `newPreOffset`: The new pre-offset after the pre-offset function has been applied.
- `postOffset`: The original and unaltered post-offset.
- `newPreOffset`: The new pre-offset after the pre-offset function has been applied.
- `postOffset`: The original and unaltered post-offset.

Note that you may also decide to ignore these attributes to achieve absolute offsets. However, relative offsets are usually recommended as they won't break your codecs when composed with other codecs.

Expand Down Expand Up @@ -635,10 +635,10 @@ const getBigEndianU64Codec = () => combineCodec(getBigEndianU64Encoder(), getBig

This package also provides utility functions for managing bytes such as:

- `mergeBytes`: Concatenates an array of `Uint8Arrays` into a single `Uint8Array`.
- `padBytes`: Pads a `Uint8Array` with zeroes (to the right) to the specified length.
- `fixBytes`: Pads or truncates a `Uint8Array` so it has the specified length.
- `containsBytes`: Checks if a `Uint8Array` contains another `Uint8Array` at a given offset.
- `mergeBytes`: Concatenates an array of `Uint8Arrays` into a single `Uint8Array`.
- `padBytes`: Pads a `Uint8Array` with zeroes (to the right) to the specified length.
- `fixBytes`: Pads or truncates a `Uint8Array` so it has the specified length.
- `containsBytes`: Checks if a `Uint8Array` contains another `Uint8Array` at a given offset.

```ts
// Merge multiple Uint8Array buffers into one.
Expand Down
18 changes: 9 additions & 9 deletions packages/codecs-data-structures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ getArrayCodec(getU8Codec()).encode([1, 2, 3]);

However, you may use the `size` option to configure this behaviour. It can be one of the following three strategies:

- `Codec<number>`: When a number codec is provided, that codec will be used to encode and decode the size prefix.
- `number`: When a number is provided, the codec will expect a fixed number of items in the array. An error will be thrown when trying to encode an array of a different length.
- `"remainder"`: When the string `"remainder"` is passed as a size, the codec will use the remainder of the bytes to encode/decode its items. This means the size is not stored or known in advance but simply inferred from the rest of the buffer. For instance, if we have an array of `u16` numbers and 10 bytes remaining, we know there are 5 items in this array.
- `Codec<number>`: When a number codec is provided, that codec will be used to encode and decode the size prefix.
- `number`: When a number is provided, the codec will expect a fixed number of items in the array. An error will be thrown when trying to encode an array of a different length.
- `"remainder"`: When the string `"remainder"` is passed as a size, the codec will use the remainder of the bytes to encode/decode its items. This means the size is not stored or known in advance but simply inferred from the rest of the buffer. For instance, if we have an array of `u16` numbers and 10 bytes remaining, we know there are 5 items in this array.

```ts
getArrayCodec(getU8Codec(), { size: getU16Codec() }).encode([1, 2, 3]);
Expand Down Expand Up @@ -310,9 +310,9 @@ const value = getLiteralUnionDecoder(['left', 'right']).decode(bytes); // 'left'

In Rust, enums are powerful data types whose variants can be one of the following:

- An empty variant — e.g. `enum Message { Quit }`.
- A tuple variant — e.g. `enum Message { Write(String) }`.
- A struct variant — e.g. `enum Message { Move { x: i32, y: i32 } }`.
- An empty variant — e.g. `enum Message { Quit }`.
- A tuple variant — e.g. `enum Message { Write(String) }`.
- A struct variant — e.g. `enum Message { Move { x: i32, y: i32 } }`.

Whilst we do not have such powerful enums in JavaScript, we can emulate them in TypeScript using a union of objects such that each object is differentiated by a specific field. **We call this a discriminated union**.

Expand Down Expand Up @@ -434,9 +434,9 @@ The `getUnionCodec` is a lower-lever codec helper that can be used to encode/dec

It accepts the following arguments:

- An array of codecs, each defining a variant of the union.
- A `getIndexFromValue` function which, given a value of the union, returns the index of the codec that should be used to encode that value.
- A `getIndexFromBytes` function which, given the byte array to decode at a given offset, returns the index of the codec that should be used to decode the next bytes.
- An array of codecs, each defining a variant of the union.
- A `getIndexFromValue` function which, given a value of the union, returns the index of the codec that should be used to encode that value.
- A `getIndexFromBytes` function which, given the byte array to decode at a given offset, returns the index of the codec that should be used to decode the next bytes.

```ts
const codec: Codec<number | boolean> = getUnionCodec(
Expand Down
4 changes: 2 additions & 2 deletions packages/codecs-strings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ The `@solana/codecs-strings` package offers a variety of string codecs such as `

By default, all available string codecs will return a `VariableSizeCodec<string>` meaning that:

- When encoding a string, all bytes necessary to encode the string will be used.
- When decoding a byte array at a given offset, all bytes starting from that offset will be decoded as a string.
- When encoding a string, all bytes necessary to encode the string will be used.
- When decoding a byte array at a given offset, all bytes starting from that offset will be decoded as a string.

For instance, here's how you can encode/decode `utf8` strings without any size boundary:

Expand Down
Loading

0 comments on commit 63832f3

Please sign in to comment.