Beispiel #1
0
        public JT808EscapeTest()
        {
            deEscapeBytes   = "7E02000026123456789012007D02000000010000000200BA7F0E07E4F11C0028003C00001810151010100104000000640202007D01137E".ToHexBytes();
            escapeBytesPoll = JT808ArrayPool.Rent(1024);
            var tmp = "7E02000026123456789012007E000000010000000200BA7F0E07E4F11C0028003C00001810151010100104000000640202007D137E".ToHexBytes();

            escapeLen = tmp.Length;
            Array.Copy(tmp, 0, escapeBytesPoll, 0, tmp.Length);
        }
Beispiel #2
0
        internal static ReadOnlySpan <byte> JT808DeEscape(ReadOnlySpan <byte> buf)
        {
            var bytes = JT808ArrayPool.Rent(buf.Length);

            try
            {
                int i      = 0;
                int offset = 0;
                int len    = 0 + buf.Length;
                while (i < len)
                {
                    if (buf[i] == 0x7d)
                    {
                        if (len > i + 1)
                        {
                            if (buf[i + 1] == 0x01)
                            {
                                bytes[offset++] = 0x7d;
                                i++;
                            }
                            else if (buf[i + 1] == 0x02)
                            {
                                bytes[offset++] = 0x7e;
                                i++;
                            }
                            else
                            {
                                bytes[offset++] = buf[i];
                            }
                        }
                    }
                    else
                    {
                        bytes[offset++] = buf[i];
                    }
                    i++;
                }
                return(bytes.AsSpan(0, offset).ToArray());
            }
            finally
            {
                JT808ArrayPool.Return(bytes);
            }
        }
Beispiel #3
0
 public void Dispose()
 {
     JT808ArrayPool.Return(escapeBytesPoll);
 }