Ejemplo n.º 1
0
 public override string ToString()
 {
     return(String.Format(
                "Message: {0} fields, protocol {1}",
                (RootList != null) ? RootList.Count : 0,
                WaveMessage.ProtocolVersionToInfoString(ProtocolVersion)));
 }
Ejemplo n.º 2
0
        public void Parse()
        {
            if (IsEmpty)
            {
                return;
            }

            if (!hasHeader)
            {
                // determine protocol version
                WaveProtocolVersion version = WaveMessage.MagicNumberToProtocolVersion(buffer[0]);

                if (version != WaveProtocolVersion.Unknown)
                {
                    // check if we have entire header yet
                    int headerSize = 0;

                    switch (version)
                    {
                    case WaveProtocolVersion.Version2:
                    case WaveProtocolVersion.Version3:
                        headerSize = 7;
                        break;

                    case WaveProtocolVersion.Version4:
                        headerSize = 9;
                        break;
                    }

                    if ((headerSize != 0) && (buffer.Length >= headerSize))
                    {
                        // we have entire header, so let's determine entire message size
                        if (version == WaveProtocolVersion.Version4)
                        {
                            // message size is a 24 bit integer
                            byte[] temp = new byte[3] {
                                buffer[1], buffer[2], buffer[3]
                            };

                            ExpectedSize = DataHelper.BytesToInt24(temp);

                            if (ExpectedSize == -1)
                            {
                                ExpectedSize = 0; // 0 is our "undefined" value
                            }
                        }
                        else
                        {
                            // message size is a 16 bit integer
                            byte[] temp = new byte[2] {
                                buffer[1], buffer[2]
                            };

                            ExpectedSize = BitConverter.ToInt16(temp, 0);
                        }

                        // do not repeat this again
                        hasHeader = true;
                    }
                }
            }
        }