NewFromBytes() public static method

Returns a specific Ssm2Packet type based on given content. Does not validate the packet, so manually call the Check method afterwards!
public static NewFromBytes ( byte bytes ) : Ssm2Packet
bytes byte /// A containing the packet. /// The packet must start at index 0 though the array may be larger than needed. ///
return Ssm2Packet
Exemplo n.º 1
0
        public void Parse1()
        {
            byte[] expected = TestPacket1;

            // Static method NewFromBytes () analyzes packet type,
            // and returns a specific packet object.
            // Based on given data in this case we know upfront,
            // it'll be an read-addresses-request.
            Ssm2ReadAddressesRequest p;

            p = (Ssm2ReadAddressesRequest)Ssm2Packet.NewFromBytes(expected);

            // check standard properties
            Assert.AreEqual(expected.Length, p.Size, "Size");
            Assert.AreEqual(true, p.Check(), "Check()");
            Assert.AreEqual(Ssm2Device.Engine10, p.Destination, "Destination");
            Assert.AreEqual(Ssm2Device.DiagnosticToolF0, p.Source, "Source");
            Assert.AreEqual(Ssm2Command.ReadAddressesRequestA8, p.Command, "Command");

            // check packet type specifics
            IList <int> addresses = p.Addresses;

            Assert.AreEqual(1, addresses.Count, "addrList.Count");
            Assert.AreEqual(1, p.AddressesCount, "AddressesCount");
            Assert.AreEqual(0x123456, addresses[0], "adr[0]");
        }
Exemplo n.º 2
0
        public void NewFromBytes()
        {
            // best for parsing as it does not allocate anything
            var p = (Ssm2ReadBlockRequest)Ssm2Packet.NewFromBytes(TestPacket1);

            // Same static method can also be accessed like this:
            // Ssm2InitRequest.NewFromBytes (...)

            AssertData1(p);
        }
Exemplo n.º 3
0
        public void NewFromBytes()
        {
            byte[] packetData = EcuInit1;
            // best for parsing as it does not allocate anything
            Ssm2InitRequest p = (Ssm2InitRequest)Ssm2Packet.NewFromBytes(packetData);

            // Same static method can also be accessed like this:
            // Ssm2InitRequest.NewFromBytes (...)

            AssertProperties1(p);
        }