@@ -4,6 +4,7 @@ import { getInt64, getUint64 } from "./utils/int";
44import { utf8DecodeJs , TEXT_DECODER_THRESHOLD , utf8DecodeTD } from "./utils/utf8" ;
55import { createDataView , ensureUint8Array } from "./utils/typedArrays" ;
66import { CachedKeyDecoder , KeyDecoder } from "./CachedKeyDecoder" ;
7+ import { DecodeError } from "./DecodeError" ;
78
89const enum State {
910 ARRAY ,
@@ -60,22 +61,6 @@ const DEFAULT_MAX_LENGTH = 0xffff_ffff; // uint32_max
6061
6162const sharedCachedKeyDecoder = new CachedKeyDecoder ( ) ;
6263
63- export class DecodeError extends Error {
64- constructor ( message : string ) {
65- super ( message ) ;
66-
67- // fix the prototype chain in a cross-platform way
68- const proto : typeof DecodeError . prototype = Object . create ( DecodeError . prototype ) ;
69- Object . setPrototypeOf ( this , proto ) ;
70-
71- Object . defineProperty ( this , "name" , {
72- configurable : true ,
73- enumerable : false ,
74- value : DecodeError . name ,
75- } ) ;
76- }
77- }
78-
7964export class Decoder < ContextType = undefined > {
8065 private totalPos = 0 ;
8166 private pos = 0 ;
@@ -133,6 +118,10 @@ export class Decoder<ContextType = undefined> {
133118 return new RangeError ( `Extra ${ view . byteLength - pos } of ${ view . byteLength } byte(s) found at buffer[${ posToShow } ]` ) ;
134119 }
135120
121+ /**
122+ * @throws {DecodeError }
123+ * @throws {RangeError }
124+ */
136125 public decode ( buffer : ArrayLike < number > | BufferSource ) : unknown {
137126 this . reinitializeState ( ) ;
138127 this . setBuffer ( buffer ) ;
0 commit comments