Beispiel #1
0
        public static WaterWell DeserializeLength(Stream stream, int length)
        {
            WaterWell waterWell = Pool.Get <WaterWell>();

            WaterWell.DeserializeLength(stream, length, waterWell, false);
            return(waterWell);
        }
Beispiel #2
0
        public static WaterWell DeserializeLength(Stream stream, int length, WaterWell instance, bool isDelta)
        {
            long position = stream.Position + (long)length;

            while (stream.Position < position)
            {
                int num = stream.ReadByte();
                if (num == -1)
                {
                    throw new EndOfStreamException();
                }
                if (num == 13)
                {
                    instance.pressure = ProtocolParser.ReadSingle(stream);
                }
                else if (num == 21)
                {
                    instance.waterLevel = ProtocolParser.ReadSingle(stream);
                }
                else
                {
                    Key key = ProtocolParser.ReadKey((byte)num, stream);
                    if (key.Field == 0)
                    {
                        throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
                    }
                    ProtocolParser.SkipKey(stream, key);
                }
            }
            if (stream.Position != position)
            {
                throw new ProtocolBufferException("Read past max limit");
            }
            return(instance);
        }
Beispiel #3
0
        public static WaterWell Deserialize(Stream stream)
        {
            WaterWell waterWell = Pool.Get <WaterWell>();

            WaterWell.Deserialize(stream, waterWell, false);
            return(waterWell);
        }
Beispiel #4
0
        public WaterWell Copy()
        {
            WaterWell waterWell = Pool.Get <WaterWell>();

            this.CopyTo(waterWell);
            return(waterWell);
        }
Beispiel #5
0
 public static WaterWell Deserialize(Stream stream, WaterWell instance, bool isDelta)
 {
     while (true)
     {
         int num = stream.ReadByte();
         if (num == -1)
         {
             break;
         }
         if (num == 13)
         {
             instance.pressure = ProtocolParser.ReadSingle(stream);
         }
         else if (num == 21)
         {
             instance.waterLevel = ProtocolParser.ReadSingle(stream);
         }
         else
         {
             Key key = ProtocolParser.ReadKey((byte)num, stream);
             if (key.Field == 0)
             {
                 throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
             }
             ProtocolParser.SkipKey(stream, key);
         }
     }
     return(instance);
 }
Beispiel #6
0
 public static WaterWell Deserialize(byte[] buffer, WaterWell instance, bool isDelta = false)
 {
     using (MemoryStream memoryStream = new MemoryStream(buffer))
     {
         WaterWell.Deserialize(memoryStream, instance, isDelta);
     }
     return(instance);
 }
Beispiel #7
0
 public virtual void WriteToStreamDelta(Stream stream, WaterWell previous)
 {
     if (previous == null)
     {
         WaterWell.Serialize(stream, this);
         return;
     }
     WaterWell.SerializeDelta(stream, this, previous);
 }
Beispiel #8
0
        public static WaterWell Deserialize(byte[] buffer)
        {
            WaterWell waterWell = Pool.Get <WaterWell>();

            using (MemoryStream memoryStream = new MemoryStream(buffer))
            {
                WaterWell.Deserialize(memoryStream, waterWell, false);
            }
            return(waterWell);
        }
Beispiel #9
0
 public static void ResetToPool(WaterWell instance)
 {
     if (!instance.ShouldPool)
     {
         return;
     }
     instance.pressure   = 0f;
     instance.waterLevel = 0f;
     Pool.Free <WaterWell>(ref instance);
 }
Beispiel #10
0
 public static byte[] SerializeToBytes(WaterWell instance)
 {
     byte[] array;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         WaterWell.Serialize(memoryStream, instance);
         array = memoryStream.ToArray();
     }
     return(array);
 }
Beispiel #11
0
        public static void Serialize(Stream stream, WaterWell instance)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            stream.WriteByte(13);
            ProtocolParser.WriteSingle(stream, instance.pressure);
            stream.WriteByte(21);
            ProtocolParser.WriteSingle(stream, instance.waterLevel);
            Pool.FreeMemoryStream(ref memoryStream);
        }
Beispiel #12
0
        public static void SerializeDelta(Stream stream, WaterWell instance, WaterWell previous)
        {
            MemoryStream memoryStream = Pool.Get <MemoryStream>();

            if (instance.pressure != previous.pressure)
            {
                stream.WriteByte(13);
                ProtocolParser.WriteSingle(stream, instance.pressure);
            }
            if (instance.waterLevel != previous.waterLevel)
            {
                stream.WriteByte(21);
                ProtocolParser.WriteSingle(stream, instance.waterLevel);
            }
            Pool.FreeMemoryStream(ref memoryStream);
        }
Beispiel #13
0
 public void CopyTo(WaterWell instance)
 {
     instance.pressure   = this.pressure;
     instance.waterLevel = this.waterLevel;
 }
Beispiel #14
0
 public virtual void WriteToStream(Stream stream)
 {
     WaterWell.Serialize(stream, this);
 }
Beispiel #15
0
 public void FromProto(Stream stream, bool isDelta = false)
 {
     WaterWell.Deserialize(stream, this, isDelta);
 }
Beispiel #16
0
 public static void SerializeLengthDelimited(Stream stream, WaterWell instance)
 {
     byte[] bytes = WaterWell.SerializeToBytes(instance);
     ProtocolParser.WriteUInt32(stream, (uint)bytes.Length);
     stream.Write(bytes, 0, (int)bytes.Length);
 }
Beispiel #17
0
 public void ResetToPool()
 {
     WaterWell.ResetToPool(this);
 }
Beispiel #18
0
 public byte[] ToProtoBytes()
 {
     return(WaterWell.SerializeToBytes(this));
 }
Beispiel #19
0
 public void ToProto(Stream stream)
 {
     WaterWell.Serialize(stream, this);
 }
Beispiel #20
0
 public virtual void ReadFromStream(Stream stream, int size, bool isDelta = false)
 {
     WaterWell.DeserializeLength(stream, size, this, isDelta);
 }