Deserialize Raw Data

From SICDB Doc
Revision as of 16:27, 8 October 2022 by Salkin (talk | contribs)
Jump to navigation Jump to search

Theory

The raw data field is a stream of 60 little endian IEEE 754 floats, so it has exactly 240 bytes. The first 4 bytes represent the first minute of the hour and so on. Note that 0x000000 is defined to be NULL (no value).


C# example

       public static float?[] GetRawValues(byte[] data)
       {
           var elements = data.Length / 4;
           byte[] buf = new byte[4];
           float?[] ret = new float?[elements];
           for(int i = 0; i < data.Length; i += 4)
           {
               buf[0] = data[i];
               buf[1] = data[i+1];
               buf[2] = data[i+2];
               buf[3] = data[i+3];
               if (buf[0] == 0 && buf[1] == 0 && buf[2] == 0 && buf[3] == 0) continue; // ret[i/4] will be null
               ret[i / 4] = BitConverter.ToSingle(buf); // note: if you are on a BigEndian machine you need to flip buf
           }
           return ret;
       }