Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c58b7e2

Browse files
committed
use UINT32_MAX because the doc says max lengths are UINT32_MAX
1 parent 78837ef commit c58b7e2

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

‎src/Decoder.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { prettyByte } from "./utils/prettyByte";
22
import { ExtensionCodec, ExtensionCodecType } from "./ExtensionCodec";
3-
import { getInt64, getUint64 } from "./utils/int";
3+
import { getInt64, getUint64,UINT32_MAX } from "./utils/int";
44
import { utf8DecodeJs, TEXT_DECODER_THRESHOLD, utf8DecodeTD } from "./utils/utf8";
55
import { createDataView, ensureUint8Array } from "./utils/typedArrays";
66
import { CachedKeyDecoder, KeyDecoder } from "./CachedKeyDecoder";
@@ -57,8 +57,6 @@ export const DataViewIndexOutOfBoundsError: typeof Error = (() => {
5757

5858
const MORE_DATA = new DataViewIndexOutOfBoundsError("Insufficient data");
5959

60-
const DEFAULT_MAX_LENGTH = 0xffff_ffff; // uint32_max
61-
6260
const sharedCachedKeyDecoder = new CachedKeyDecoder();
6361

6462
export class Decoder<ContextType = undefined> {
@@ -73,11 +71,11 @@ export class Decoder<ContextType = undefined> {
7371
public constructor(
7472
private readonly extensionCodec: ExtensionCodecType<ContextType> = ExtensionCodec.defaultCodec as any,
7573
private readonly context: ContextType = undefined as any,
76-
private readonly maxStrLength = DEFAULT_MAX_LENGTH,
77-
private readonly maxBinLength = DEFAULT_MAX_LENGTH,
78-
private readonly maxArrayLength = DEFAULT_MAX_LENGTH,
79-
private readonly maxMapLength = DEFAULT_MAX_LENGTH,
80-
private readonly maxExtLength = DEFAULT_MAX_LENGTH,
74+
private readonly maxStrLength = UINT32_MAX,
75+
private readonly maxBinLength = UINT32_MAX,
76+
private readonly maxArrayLength = UINT32_MAX,
77+
private readonly maxMapLength = UINT32_MAX,
78+
private readonly maxExtLength = UINT32_MAX,
8179
private readonly keyDecoder: KeyDecoder | null = sharedCachedKeyDecoder,
8280
) {}
8381

‎src/utils/int.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Integer Utility
2+
3+
export const UINT32_MAX = 0xffff_ffff;
4+
15
// DataView extension to handle int64 / uint64,
26
// where the actual range is 53-bits integer (a.k.a. safe integer)
37

‎src/utils/utf8.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { UINT32_MAX } from "./int";
2+
13
const TEXT_ENCODING_AVAILABLE =
24
(typeof process === "undefined" || process.env["TEXT_ENCODING"] !== "never") &&
35
typeof TextEncoder !== "undefined" &&
46
typeof TextDecoder !== "undefined";
57

6-
const STR_SIZE_MAX = 0xffff_ffff; // uint32_max
7-
88
export function utf8Count(str: string): number {
99
const strLength = str.length;
1010

@@ -90,7 +90,7 @@ export function utf8EncodeJs(str: string, output: Uint8Array, outputOffset: numb
9090

9191
const sharedTextEncoder = TEXT_ENCODING_AVAILABLE ? new TextEncoder() : undefined;
9292
export const TEXT_ENCODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE
93-
? STR_SIZE_MAX
93+
? UINT32_MAX
9494
: typeof process !== "undefined" && process.env["TEXT_ENCODING"] !== "force"
9595
? 200
9696
: 0;
@@ -158,7 +158,7 @@ export function utf8DecodeJs(bytes: Uint8Array, inputOffset: number, byteLength:
158158

159159
const sharedTextDecoder = TEXT_ENCODING_AVAILABLE ? new TextDecoder() : null;
160160
export const TEXT_DECODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE
161-
? STR_SIZE_MAX
161+
? UINT32_MAX
162162
: typeof process !== "undefined" && process.env["TEXT_DECODER"] !== "force"
163163
? 200
164164
: 0;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /