Parse binary data by InterSystems ObjectScript
I am trying to read some binary data from a local file or through socket.
The binary data is like H.264 codec, I need to read data BYTE by BYTE (even BIT by BIT) and decide the next step based on the data read so far.
I check the documentation and it seems like most of the sample focus on human readable IO, ie: LINE by LINE.
Could I achieve my goal through COS?
Thanks.
you have the option to read by character using
READ *var
Then you read exactly 1 byte in its decimal representation
open file:"RS":0 else write "file not open", ! quit
for use file read *byte use 0 write byte,?5,"x\"_$ZHEX(byte),?12,"char:",$C(byte),!
Docs on READ
You may also use %File Class and use a Read method with length 1
You can use %Stream.FileBinary and %Stream.GlobalBinary classes.
In addition to other answers, if want to operate with bits, you can use functions:
If you are going to work with H.264, I would not recommend to try to implement it in COS, it will not be fast enough. I'm not very know with this technology but I'm sure I know, it is too complicated and encoding should work in GPU. But it is impossible with Caché. I don't know why exactly do you need it, but I would recommend you to look at external tool ffmpeg, which is very useful and leader on work with video. And I think you can connect ffmpeg.dll, to work from Caché with $zf functions.