Example #1
0
        public void Test1()
        {
            Console.WriteLine("Test1====================");

            var buffer = new CodedBuffer();

            buffer.WriteBool(true);
            buffer.WriteInt(70);
            buffer.WriteInt(2423);
            buffer.WriteFloat(13.43F);
            buffer.WriteDouble(4242.432);
            buffer.WriteFloat(132.32434F, 2);
            buffer.WriteDouble(342254.653254, 2);
            buffer.WriteString("搭顺风车");
            buffer.WriteLong(long.MaxValue);
            buffer.WriteLong(long.MinValue);
            buffer.WriteTag(253);

            Console.WriteLine("buffer.ReadableCount:{0}", buffer.ReadableCount);

            // var fileStream = File.Open("D:\\buffer", FileMode.Open);
            // var bytes = new byte[fileStream.Length];
            // fileStream.Read(bytes, 0, bytes.Length);
            // Console.WriteLine($"bytes.Length={bytes.Length}");
            // buffer = new Buffer(bytes);

            Console.WriteLine(buffer.ReadBool());
            Console.WriteLine(buffer.ReadInt());
            Console.WriteLine(buffer.ReadInt());
            Console.WriteLine(buffer.ReadFloat());
            Console.WriteLine(buffer.ReadDouble());
            Console.WriteLine(buffer.ReadFloat(2));
            Console.WriteLine(buffer.ReadDouble(2));
            Console.WriteLine(buffer.ReadString());
            Console.WriteLine(buffer.ReadLong());
            Console.WriteLine(buffer.ReadLong());
            Console.WriteLine(buffer.ReadTag());
        }
Example #2
0
        protected static void SkipField(int tag, CodedBuffer buffer)
        {
            switch (tag & 0b11)
            {
            case 0:
                buffer.ReadLong();
                break;

            case 1:
                buffer.ReadFloat();
                break;

            case 2:
                buffer.ReadDouble();
                break;

            case 3:
                buffer.SkipBytes();
                break;
            }
        }