File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -922,7 +922,16 @@ export class OptClass<T> extends ConstructType<[T] | []> {
922922 case 0 :
923923 return [ ] ;
924924 case 1 :
925- return [ this . _type . decodeValue ( b , opt . _type ) ] ;
925+ let checkpoint = b . save ( ) ;
926+ try {
927+ let v = this . _type . decodeValue ( b , opt . _type )
928+ return [ v ] ;
929+ } catch ( e : any ) {
930+ b . restore ( checkpoint ) ;
931+ // skip value at wire typ (to advance b)
932+ let v = opt . _type . decodeValue ( b , opt . _type )
933+ return [ ] ;
934+ } ;
926935 default :
927936 throw new Error ( 'Not an option value' ) ;
928937 }
Original file line number Diff line number Diff line change @@ -38,6 +38,20 @@ export class PipeArrayBuffer {
3838 */
3939 private _view : Uint8Array ;
4040
41+ /**
42+ * Save a checkpoint of the reading view (for backtracking)
43+ */
44+ public save ( ) : Uint8Array {
45+ return this . _view ;
46+ } ;
47+
48+ /**
49+ * Restore a checkpoint of the reading view (for backtracking)
50+ */
51+ public restore ( checkPoint : Uint8Array ) {
52+ this . _view = checkPoint ;
53+ } ;
54+
4155 /**
4256 * The actual buffer containing the bytes.
4357 * @private
You can’t perform that action at this time.
0 commit comments