robertwb commented on code in PR #22137:
URL: https://github.com/apache/beam/pull/22137#discussion_r917016828


##########
sdks/typescript/src/apache_beam/coders/standard_coders.ts:
##########
@@ -123,9 +123,9 @@ export class DoubleCoder implements Coder<number> {
   }
 
   decode(reader: Reader, context: Context): number {
-    const barr = new Uint8Array(reader.buf, reader.pos, 8);
-    const dView = new DataView(barr.buffer);
-    reader.float();
+    const barr = new Uint8Array(reader.buf);
+    const dView = new DataView(barr.buffer.slice(reader.pos, reader.pos + 8));

Review Comment:
   The problem was that despite constructing the `barr` as new 
`Uint8Array(reader.buf, reader.pos, 8)`, `barr.buffer` still refers to the 
entire (non-cropped) underlying buffer. This means the coder failed whenever 
the value was not the first element in the stream (as it is in js_coders, hence 
the added test, as well as in iterables, as a second element, etc.) I didn't 
see a way to avoid the extra copy, but it's only 8 bytes (as opposed to an 
unbounded amount) so hopefully that should be relatively cheap. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to