Difference between revisions of "Deserialize Raw Data"

From SICDB Doc
Jump to navigation Jump to search
(Created page with "== 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...")
 
Line 13: Line 13:
             for(int i = 0; i < data.Length; i += 4)
             for(int i = 0; i < data.Length; i += 4)
             {
             {
               
                 buf[0] = data[i];
                 buf[0] = data[i];
                 buf[1] = data[i+1];
                 buf[1] = data[i+1];

Revision as of 16:25, 8 October 2022

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] = BitConverter.ToSingle(buf);
           }
           return ret;
       }