@@ -82,7 +82,7 @@ export class BatchedTokenRequest {
8282
8383 static deserialize ( bytes : Uint8Array ) : BatchedTokenRequest {
8484 let offset = 0 ;
85- const input = new DataView ( bytes . buffer ) ;
85+ const input = new DataView ( bytes . buffer , bytes . byteOffset , bytes . byteLength ) ;
8686
8787 const { value : length , usize } = varint . read ( input , offset ) ;
8888 offset += usize ;
@@ -94,9 +94,9 @@ export class BatchedTokenRequest {
9494 const batchedTokenRequests : TokenRequest [ ] = [ ] ;
9595
9696 while ( offset < bytes . length ) {
97- const tokenTypeEntry = tokenRequestToTokenTypeEntry ( bytes ) ;
97+ const tokenTypeEntry = tokenRequestToTokenTypeEntry ( bytes . subarray ( offset ) ) ;
9898 const len = tokenEntryToSerializedLength ( tokenTypeEntry ) ;
99- const b = new Uint8Array ( input . buffer . slice ( offset , offset + len ) ) ;
99+ const b = bytes . subarray ( offset , offset + len ) ;
100100 offset += len ;
101101
102102 batchedTokenRequests . push ( TokenRequest . deserialize ( b ) ) ;
@@ -111,7 +111,12 @@ export class BatchedTokenRequest {
111111 let length = 0 ;
112112 for ( const tokenRequest of this . tokenRequests ) {
113113 const tokenRequestSerialized = tokenRequest . serialize ( ) ;
114- output . push ( tokenRequestSerialized . buffer ) ;
114+ output . push (
115+ ( tokenRequestSerialized . buffer as ArrayBuffer ) . slice (
116+ tokenRequestSerialized . byteOffset ,
117+ tokenRequestSerialized . byteOffset + tokenRequestSerialized . byteLength ,
118+ ) ,
119+ ) ;
115120 length += tokenRequestSerialized . length ;
116121 }
117122
@@ -217,7 +222,7 @@ export class GenericBatchTokenResponse {
217222
218223 static deserialize ( bytes : Uint8Array ) : GenericBatchTokenResponse {
219224 let offset = 0 ;
220- const input = new DataView ( bytes . buffer ) ;
225+ const input = new DataView ( bytes . buffer , bytes . byteOffset , bytes . byteLength ) ;
221226
222227 const { value : length , usize } = varint . read ( input , offset ) ;
223228 offset += usize ;
@@ -229,7 +234,7 @@ export class GenericBatchTokenResponse {
229234 const batchedTokenResponses : OptionalTokenResponse [ ] = [ ] ;
230235
231236 while ( offset < bytes . length ) {
232- const otr = OptionalTokenResponse . deserialize ( bytes . slice ( offset ) ) ;
237+ const otr = OptionalTokenResponse . deserialize ( bytes . subarray ( offset ) ) ;
233238 offset += otr . length ( ) ;
234239 batchedTokenResponses . push ( otr ) ;
235240 }
@@ -244,7 +249,12 @@ export class GenericBatchTokenResponse {
244249 for ( const tokenResponse of this . tokenResponses ) {
245250 const tokenResponseSerialized = tokenResponse . serialize ( ) ;
246251
247- output . push ( tokenResponseSerialized ) ;
252+ output . push (
253+ ( tokenResponseSerialized . buffer as ArrayBuffer ) . slice (
254+ tokenResponseSerialized . byteOffset ,
255+ tokenResponseSerialized . byteOffset + tokenResponseSerialized . byteLength ,
256+ ) ,
257+ ) ;
248258 length += tokenResponseSerialized . length ;
249259 }
250260
0 commit comments