Exemplo n.º 1
0
 public PDUBuilder(PDUType type)
     : base(new MemoryStream(), true)
 {
     Write((byte)type); //pdu-type
     Write((byte)0);    //reserved - 0
     Write((uint)0);    //temp pdu-len
 }
Exemplo n.º 2
0
 /// <summary>
 /// Performs shallow copy.
 /// </summary>
 /// <param name="h"></param>
 public void Clone(Header h)
 {
     pDUType         = h.pDUType;
     protocolVersion = h.protocolVersion;
     exerciseID      = h.exerciseID;
     protocolFamily  = h.protocolFamily;
     timeStamp       = h.timeStamp;
     length          = h.length;
 }
Exemplo n.º 3
0
 public PDUHeader(PDUType type)
 {
     MajorVersion   = RPC_VERSION_MAJOR;
     MinorVersion   = RPC_VERSION_MINOR;
     Type           = type;
     Flags          = PDUFlags.None;
     DataRep        = new NdrDataRepresentation();
     FragmentLength = 0;
     AuthLength     = 0;
     CallId         = 0;
 }
Exemplo n.º 4
0
        /// <summary>
        /// All PDU of pduType will now be decoded using the supplied decoder.
        /// </summary>
        /// <param name="pduType"></param>
        /// <param name="decoder"></param>
        public void SetPduDecoder(PDUType pduType, IFactoryDecoder decoder)
        {
            DecoderAndEventPair dep;

            if (factoryDecoders.TryGetValue(pduType, out dep))
            {
                Debug.Log("Swapping out default decoder for " + pduType + " with " + decoder.GetType().ToString());
                dep.pduDecoder = decoder;
            }
            else
            {
                factoryDecoders.Add(pduType, new DecoderAndEventPair(decoder, null));
            }
        }
Exemplo n.º 5
0
        public static SpecialPDU CreatePDUBody(byte[] vs, int offset, PDUType pduType, int specialPDULength)
        {
            SpecialPDU pduBody = null;

            switch (pduType)
            {
            case PDUType.response: pduBody = Response.Parser(vs, offset, specialPDULength); break;

            case PDUType.bind_ack: pduBody = BindACK.Parser(vs, offset, specialPDULength); break;

            default: throw new NotImplementedException("unknow pdu type");
            }

            return(pduBody);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Decode network data.
        /// </summary>
        /// <param name="br"></param>
        public override void Decode(BinaryReader br)
        {
            isDirty         = true;
            protocolVersion = ( ProtocolVersion )br.ReadByte();
            exerciseID      = br.ReadByte();
            pDUType         = ( PDUType )br.ReadByte();
            protocolFamily  = ( ProtocolFamily )br.ReadByte();
            timeStamp       = new TimeStamp(br);
            length          = br.ReadUInt16();

            #if DIS_VERSION_7
            ownershipStatus = br.ReadByte();
            pduStatus       = br.ReadByte();
            #else
            br.BaseStream.Seek(2, SeekOrigin.Current);   // Skip padding
            #endif
        }
Exemplo n.º 7
0
 protected void Create(PDUType type) => Type = type;
Exemplo n.º 8
0
            //Protected
            protected void Create(PDUType type, PublicFunctionCodes functionCode, int startAddress, object value)
            {
                if (value.GetType() == typeof(short[]))
                {
                    short[] val = (short[])value;

                    Type = type;

                    Data.Add((byte)functionCode);

                    Data.Add(HighByte(startAddress));
                    Data.Add(LowByte(startAddress));

                    Data.Add(HighByte(val.Length));
                    Data.Add(LowByte(val.Length));

                    Data.Add((byte)(val.Length * 2));

                    for (int i = 0; i < val.Length; i++)
                    {
                        Data.Add(HighByte(val[i]));
                        Data.Add(LowByte(val[i]));
                    }
                }
                else if (value.GetType() == typeof(int[]))
                {
                    int[] val = (int[])value;

                    Type = type;

                    Data.Add((byte)functionCode);

                    Data.Add(HighByte(startAddress));
                    Data.Add(LowByte(startAddress));

                    Data.Add(HighByte(val.Length * 2));
                    Data.Add(LowByte(val.Length * 2));

                    Data.Add((byte)(val.Length * 4));

                    for (int i = 0; i < val.Length; i++)
                    {
                        Data.Add(HighByteHighWord(val[i]));
                        Data.Add(LowByteHighWord(val[i]));
                        Data.Add(HighByte(val[i]));
                        Data.Add(LowByte(val[i]));
                    }
                }
                else if (value.GetType() == typeof(float[]))
                {
                    float[] val = (float[])value;

                    Type = type;

                    Data.Add((byte)functionCode);

                    Data.Add(HighByte(startAddress));
                    Data.Add(LowByte(startAddress));

                    Data.Add(HighByte(val.Length * 2));
                    Data.Add(LowByte(val.Length * 2));

                    Data.Add((byte)(val.Length * 4));

                    for (int i = 0; i < val.Length; i++)
                    {
                        byte[] b = BitConverter.GetBytes(val[i]);
                        b = Reverse(b);
                        Data.AddRange(b);
                    }
                }
                else if (value.GetType() == typeof(int))
                {
                    Type = type;

                    Data.Add((byte)functionCode);

                    Data.Add(HighByte(startAddress));
                    Data.Add(LowByte(startAddress));

                    Data.Add(HighByte((int)value));
                    Data.Add(LowByte((int)value));
                }
                else if (value.GetType() == typeof(bool))
                {
                    Type = type;

                    Data.Add((byte)functionCode);

                    Data.Add(HighByte(startAddress));
                    Data.Add(LowByte(startAddress));

                    if ((bool)value)
                    {
                        Data.Add(0xFF);
                    }
                    else
                    {
                        Data.Add(0xFF);
                    }
                    Data.Add(0);
                }
            }
Exemplo n.º 9
0
 protected PDUBase(PDUType pdu_type)
 {
     PDUType = pdu_type;
 }
Exemplo n.º 10
0
 public static byte GetByte(this PDUType t)
 {
     return((byte)t);
 }