Exemplo n.º 1
0
        public void SetAt(int index, object obj)
        {
            Type type   = obj.GetType();
            int  offset = GetByteOffset(index);

            byte[] bytes = (byte[])typeof(BitConverter)
                           .GetMethod("GetBytes", new Type[] { type })
                           .Invoke(null, new object[] { obj });
            System.Buffer.BlockCopy(bytes, 0, Buffer, offset, ByteCode.GetByteCount(type));
        }
Exemplo n.º 2
0
        private int GetByteOffset(int index)
        {
            int n = index / model.Count;

            int offset = 1 + n * modelByteCount;

            for (int i = 0; i < index % model.Count; i++)
            {
                offset += ByteCode.GetByteCount(model[i]);
            }

            return(offset);
        }
Exemplo n.º 3
0
        public Command(OpCode op, params object[] args)
        {
            model          = Utils.MODELS[op];
            modelByteCount = ByteCode.GetByteCount(model);

            // When we receive a Command the buffer is already populated
            if (Buffer == null)
            {
                // Repetitions of the model
                int n = 1;
                if (model.Count != 0)
                {
                    n = Math.Max(1, args.Length / model.Count);
                }
                Buffer    = new byte[1 + modelByteCount * n];
                Buffer[0] = (byte)op;

                for (int i = 0; i < args.Length; i++)
                {
                    SetAt(i, args[i]);
                }
            }
        }