stevedlawrence commented on issue #974:
URL: 
https://github.com/apache/daffodil-vscode/issues/974#issuecomment-2711515697

   There is kindof two ways to do it. One option is to ask if the 
InputSourceDataInputStream has any data available, for example:
   
   ```scala
   val isdis = new InputSourceDataInputStream(data)
   val pr = dp.parse(isdis, infosetOutputter)
   if (!pr.isError) {
     if (isdis.hasData) {
       message("At least one bit of left over data found")
     }
   }
   ```
   
   Note that if your data is coming from an InputStream, then hasData will 
block until it either hits EOF or reads at least one byte. This doesn't tell 
you how much left over data there was or what the following data is in the 
stream, which can sometimes be a useful diagnostic. Unfortunately, the public 
Daffodil API doesn't help with this too much, which is why Main.scala does 
things a bit more complicatedly.
   
   What you could do, and essentially what Daffodil does, is get the bit or 
byte position (1-based) from the parse result, e.g.
   
   ```scala
   val endingBitPosition = pr.location.bitPos1b
   ```
   and compare that against how much data you provided to Daffodil. That's not 
too hard if your data is something with a fixed size like a `File` or 
`Array[Byte]`, but it's a bit tricker if your input is a generic `InputStream`. 
This has the added benefit that if your input is an File or Array, you can just 
jump to that location and output the next handful of bytes if you want a more 
verbose message.
   
   Note that even if you go with the first approach, outputing the ending bit 
position might be useful information to include in the message.


-- 
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