コード例 #1
0
        public void ASCIIString()
        {
            List <Dictionary <string, string> > testasciis = settings.GetValues(MethodBase.GetCurrentMethod(), "ascii");

            if (testasciis != null)
            {
                foreach (Dictionary <string, string> dEntry in testasciis)
                {
                    DataOutput dataOutput = new DataOutput();
                    string     testascii  = dEntry["value"];
                    dataOutput.WriteUTF(testascii);
                    byte[] buffer = dataOutput.GetBuffer();
                    Assert.AreEqual(Util.String2Byte(dEntry["byte0"]), buffer[0]);
                    Assert.AreEqual(Util.String2Byte(dEntry["byte1"]), buffer[1]);
                    for (int i = 0; i < testascii.Length; i++)
                    {
                        Assert.AreEqual(testascii[i], buffer[i + 2]);
                    }

                    DataInput dataInput = new DataInput(buffer);
                    string    result    = dataInput.ReadUTF();
                    Assert.AreEqual(testascii.Length, result.Length);
                    Assert.AreEqual(testascii, result);
                }
            }
        }
コード例 #2
0
        public static IGeodeSerializable Duplicate(IGeodeSerializable orig)
        {
            DataOutput dout = CacheHelper.DCache.CreateDataOutput();

            orig.ToData(dout);

            DataInput          din = CacheHelper.DCache.CreateDataInput(dout.GetBuffer());
            IGeodeSerializable dup = (IGeodeSerializable)din.ReadObject();

            return(dup);
        }
コード例 #3
0
        public static IGFSerializable Duplicate(IGFSerializable orig)
        {
            DataOutput dout = new DataOutput();

            orig.ToData(dout);

            DataInput       din = new DataInput(dout.GetBuffer());
            IGFSerializable dup = (IGFSerializable)din.ReadObject();

            return(dup);
        }
コード例 #4
0
        public bool CompareTwoPositionObjects(TVal pos1, TVal pos2)
        {
            Position p1 = pos1 as Position;
            Position p2 = pos2 as Position;

            if (p1 == null || p2 == null)
            {
                Util.Log("The object(s) passed are not of Position type");
                return(false);
            }

            DataOutput o1 = m_cache.CreateDataOutput();
            DataOutput o2 = m_cache.CreateDataOutput();

            p1.ToData(o1);
            p2.ToData(o2);

            var len1 = o1.BufferLength;
            var len2 = o2.BufferLength;

            if (len1 != len2)
            {
                return(false);
            }

            byte[] ptr1 = o1.GetBuffer();
            byte[] ptr2 = o2.GetBuffer();

            if (ptr1.Length != ptr2.Length)
            {
                return(false);
            }

            for (int i = ptr1.Length; i < ptr1.Length; i++)
            {
                if (ptr1[i] != ptr2[i])
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #5
0
        public void Byte()
        {
            List <Dictionary <string, string> > testbytes = settings.GetValues(MethodBase.GetCurrentMethod(), "byte");

            if (testbytes != null)
            {
                foreach (Dictionary <string, string> dEntry in testbytes)
                {
                    DataOutput dataOutput = new DataOutput();
                    byte       testbyte   = Util.String2Byte(dEntry["value"]);
                    dataOutput.WriteByte(testbyte);
                    byte[] buffer = dataOutput.GetBuffer();
                    Assert.AreEqual(testbyte, buffer[0]);

                    DataInput dataInput = new DataInput(buffer);
                    byte      result    = dataInput.ReadByte();
                    Assert.AreEqual(testbyte, result);
                }
            }
        }
コード例 #6
0
        public void Int16()
        {
            List <Dictionary <string, string> > testshorts = settings.GetValues(MethodBase.GetCurrentMethod(), "short");

            if (testshorts != null)
            {
                foreach (Dictionary <string, string> dEntry in testshorts)
                {
                    DataOutput dataOutput = new DataOutput();
                    short      testshort  = Util.String2Int16(dEntry["value"]);
                    dataOutput.WriteInt16(testshort);
                    byte[] buffer        = dataOutput.GetBuffer();
                    byte[] expectedBytes = Util.String2Bytes(dEntry["bytes"]);
                    Util.CompareTestArrays(expectedBytes, buffer);

                    DataInput dataInput = new DataInput(buffer);
                    short     result    = dataInput.ReadInt16();
                    Assert.AreEqual(testshort, result);
                }
            }
        }
コード例 #7
0
        public void Boolean()
        {
            List <Dictionary <string, string> > testbools = settings.GetValues(MethodBase.GetCurrentMethod(), "bool");

            if (testbools != null)
            {
                foreach (Dictionary <string, string> dEntry in testbools)
                {
                    DataOutput dataOutput = new DataOutput();
                    bool       testbool   = bool.Parse(dEntry["value"]);
                    dataOutput.WriteBoolean(testbool);
                    byte[] buffer        = dataOutput.GetBuffer();
                    byte[] expectedBytes = Util.String2Bytes(dEntry["bytes"]);
                    Util.CompareTestArrays(expectedBytes, buffer);

                    DataInput dataInput = new DataInput(buffer);
                    bool      result    = dataInput.ReadBoolean();
                    Assert.AreEqual(testbool, result);
                }
            }
        }
コード例 #8
0
        public void Double()
        {
            List <Dictionary <string, string> > testdoubles = settings.GetValues(MethodBase.GetCurrentMethod(), "double");

            if (testdoubles != null)
            {
                foreach (Dictionary <string, string> dEntry in testdoubles)
                {
                    DataOutput dataOutput = new DataOutput();
                    double     testdouble = double.Parse(dEntry["value"]);
                    dataOutput.WriteDouble(testdouble);
                    byte[] buffer        = dataOutput.GetBuffer();
                    byte[] expectedBytes = Util.String2Bytes(dEntry["bytes"]);
                    Util.CompareTestArrays(expectedBytes, buffer);

                    DataInput dataInput = new DataInput(buffer);
                    double    result    = dataInput.ReadDouble();
                    Assert.AreEqual(testdouble, result);
                }
            }
        }
コード例 #9
0
        public void UTFString()
        {
            List <Dictionary <string, string> > testutfs = settings.GetValues(MethodBase.GetCurrentMethod(), "utf");

            if (testutfs != null)
            {
                foreach (Dictionary <string, string> dEntry in testutfs)
                {
                    DataOutput dataOutput = new DataOutput();
                    string     testutf    = Util.String2String(dEntry["value"]);
                    dataOutput.WriteUTF(testutf);
                    byte[] buffer        = dataOutput.GetBuffer();
                    byte[] expectedBytes = Util.String2Bytes(dEntry["bytes"]);
                    Util.CompareTestArrays(expectedBytes, buffer);

                    DataInput dataInput = new DataInput(buffer);
                    string    result    = dataInput.ReadUTF();
                    Assert.AreEqual(testutf.Length, result.Length);
                    Assert.AreEqual(testutf, result);
                }
            }
        }
コード例 #10
0
        public static byte[] Init(Int32 size, bool encodeKey, bool encodeTimestamp)
        {
            if (encodeKey)
            {
                //using (DataOutput dos = new DataOutput())
                //{
                dos.Reset();
                try
                {
                    Int32 index = 1234;
                    dos.WriteInt32(index);
                    //dos.Write(index);
                    if (encodeTimestamp)
                    {
                        DateTime startTime = DateTime.Now;
                        long     timestamp = startTime.Ticks * (1000000 / TimeSpan.TicksPerMillisecond);
                        //dos.Write(timestamp);
                        dos.WriteInt64(timestamp);
                    }
                }
                catch (Exception e)
                {
                    //FwkException("Unable to write to stream {0}", e.Message);
                    throw new Exception(e.Message);
                }

                /*
                 * byte[] b = baos.GetBuffer();
                 * if (b.Length > size)
                 * {
                 * throw new Exception("Unable to encode into byte array of size");
                 * }
                 * byte[] result = new byte[size];
                 * System.Array.Copy(b, 0, result, 0, b.Length);
                 * return CacheableBytes.Create(result);
                 * //return result;
                 */

                Int32  bufSize = size;
                byte[] buf     = new byte[bufSize];

                for (int i = 0; i < bufSize; i++)
                {
                    buf[i] = 123;
                }
                //buf.CopyTo(dos.GetBuffer(), (int)dos.BufferLength);
                System.Array.Copy(dos.GetBuffer(), 0, buf, 0, dos.BufferLength);
                //Console.WriteLine("rjk: size of byte array is {0} , dataoutput lenght {1} and object is {2}", sizeof(byte) * buf.Length, dos.BufferLength, buf.ToString());
                Int32 rsiz = (bufSize <= 20) ? bufSize : 20;
                return(buf);

                //}
            }
            else if (encodeTimestamp)
            {
                throw new Exception("Should not happen");
                //FwkException("Should not happen");
            }
            else
            {
                return(new byte[size]);
                //return new byte[size];
            }
        }