예제 #1
0
        // Decode
        public static PinkPillPayload FromEncoded(Span <byte> encodedBytes)
        {
            var  walker = new PinkPillWalker(encodedBytes);
            byte version;

            try
            {
                walker.SkipUntil(Header[0x0]); // 别倒垃圾
                var header = walker.ReadBlock(Header.Length);
                if (!header.SequenceEqual(Header))
                {
                    throw new PPPDecodeException("Invalid header.");
                }
                version = walker.Read();
            }
            catch (EndOfBytesException)
            {
                throw new PPPDecodeException("Invalid header");
            }

            var instance = new PinkPillPayload();

            switch (version)
            {
            case 0x1:
                DecodeVersion1(ref instance, walker);
                break;

            default:
                throw new PPPDecodeException("Invalid version");
            }

            return(instance);
        }
예제 #2
0
 static void DecodeVersion1(ref PinkPillPayload payload, PinkPillWalker walker)
 {
     payload.EncryptMethod = walker.Read();
     payload.Data          = walker.ReadToEnd().ToArray();
 }