@@ -30,20 +30,17 @@ import { isNullOrUndefined } from '../util/types';
30
30
import { ExponentialBackoff } from './backoff' ;
31
31
import { Connection , Stream } from './connection' ;
32
32
import {
33
- fromBytes ,
34
33
fromVersion ,
35
34
fromWatchChange ,
36
35
fromWriteResults ,
37
36
getEncodedDatabaseId ,
38
37
JsonProtoSerializer ,
39
- toBytes ,
40
38
toListenRequestLabels ,
41
39
toMutation ,
42
40
toTarget ,
43
41
versionFromListenResponse
44
42
} from './serializer' ;
45
43
import { WatchChange } from './watch_change' ;
46
- import { ByteString } from '../util/byte_string' ;
47
44
48
45
const LOG_TAG = 'PersistentStream' ;
49
46
@@ -679,7 +676,7 @@ export class PersistentWriteStream extends PersistentStream<
679
676
* PersistentWriteStream manages propagating this value from responses to the
680
677
* next request.
681
678
*/
682
- private lastStreamToken : ByteString = ByteString . EMPTY_BYTE_STRING ;
679
+ private lastStreamToken : string | Uint8Array | undefined ;
683
680
684
681
/**
685
682
* Tracks whether or not a handshake has been successfully exchanged and
@@ -692,7 +689,7 @@ export class PersistentWriteStream extends PersistentStream<
692
689
// Override of PersistentStream.start
693
690
start ( ) : void {
694
691
this . handshakeComplete_ = false ;
695
- this . lastStreamToken = ByteString . EMPTY_BYTE_STRING ;
692
+ this . lastStreamToken = undefined ;
696
693
super . start ( ) ;
697
694
}
698
695
@@ -717,10 +714,7 @@ export class PersistentWriteStream extends PersistentStream<
717
714
! ! responseProto . streamToken ,
718
715
'Got a write response without a stream token'
719
716
) ;
720
- this . lastStreamToken = fromBytes (
721
- this . serializer ,
722
- responseProto . streamToken
723
- ) ;
717
+ this . lastStreamToken = responseProto . streamToken ;
724
718
725
719
if ( ! this . handshakeComplete_ ) {
726
720
// The first response is always the handshake response
@@ -754,7 +748,7 @@ export class PersistentWriteStream extends PersistentStream<
754
748
debugAssert ( this . isOpen ( ) , 'Writing handshake requires an opened stream' ) ;
755
749
debugAssert ( ! this . handshakeComplete_ , 'Handshake already completed' ) ;
756
750
debugAssert (
757
- this . lastStreamToken . isEqual ( ByteString . EMPTY_BYTE_STRING ) ,
751
+ ! this . lastStreamToken ,
758
752
'Stream token should be empty during handshake'
759
753
) ;
760
754
// TODO(dimond): Support stream resumption. We intentionally do not set the
@@ -772,12 +766,12 @@ export class PersistentWriteStream extends PersistentStream<
772
766
'Handshake must be complete before writing mutations'
773
767
) ;
774
768
debugAssert (
775
- this . lastStreamToken . approximateByteSize ( ) > 0 ,
769
+ ! ! this . lastStreamToken ,
776
770
'Trying to write mutation without a token'
777
771
) ;
778
772
779
773
const request : WriteRequest = {
780
- streamToken : toBytes ( this . serializer , this . lastStreamToken ) ,
774
+ streamToken : this . lastStreamToken ,
781
775
writes : mutations . map ( mutation => toMutation ( this . serializer , mutation ) )
782
776
} ;
783
777
0 commit comments