コード例 #1
0
ファイル: PresenceField.cs プロジェクト: DZilli/mooege
        public bnet.protocol.presence.Field GetField(bnet.protocol.attribute.Variant variantValue)
        {
            var fieldKey = FieldKeyHelper.Create(Program, OriginatingClass, FieldNumber, Index);
            var field    = bnet.protocol.presence.Field.CreateBuilder().SetKey(fieldKey).SetValue(variantValue).Build();

            return(field);
        }
コード例 #2
0
        public static void Serialize(Stream stream, bnet.protocol.attribute.Variant instance)
        {
            BinaryWriter binaryWriter = new BinaryWriter(stream);

            if (instance.HasBoolValue)
            {
                stream.WriteByte(16);
                ProtocolParser.WriteBool(stream, instance.BoolValue);
            }
            if (instance.HasIntValue)
            {
                stream.WriteByte(24);
                ProtocolParser.WriteUInt64(stream, (ulong)instance.IntValue);
            }
            if (instance.HasFloatValue)
            {
                stream.WriteByte(33);
                binaryWriter.Write(instance.FloatValue);
            }
            if (instance.HasStringValue)
            {
                stream.WriteByte(42);
                ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.StringValue));
            }
            if (instance.HasBlobValue)
            {
                stream.WriteByte(50);
                ProtocolParser.WriteBytes(stream, instance.BlobValue);
            }
            if (instance.HasMessageValue)
            {
                stream.WriteByte(58);
                ProtocolParser.WriteBytes(stream, instance.MessageValue);
            }
            if (instance.HasFourccValue)
            {
                stream.WriteByte(66);
                ProtocolParser.WriteBytes(stream, Encoding.UTF8.GetBytes(instance.FourccValue));
            }
            if (instance.HasUintValue)
            {
                stream.WriteByte(72);
                ProtocolParser.WriteUInt64(stream, instance.UintValue);
            }
            if (instance.HasEntityidValue)
            {
                stream.WriteByte(82);
                ProtocolParser.WriteUInt32(stream, instance.EntityidValue.GetSerializedSize());
                EntityId.Serialize(stream, instance.EntityidValue);
            }
        }
コード例 #3
0
 public override bool Equals(object obj)
 {
     bnet.protocol.attribute.Variant variant = obj as bnet.protocol.attribute.Variant;
     if (variant == null)
     {
         return(false);
     }
     if (this.HasBoolValue != variant.HasBoolValue || this.HasBoolValue && !this.BoolValue.Equals(variant.BoolValue))
     {
         return(false);
     }
     if (this.HasIntValue != variant.HasIntValue || this.HasIntValue && !this.IntValue.Equals(variant.IntValue))
     {
         return(false);
     }
     if (this.HasFloatValue != variant.HasFloatValue || this.HasFloatValue && !this.FloatValue.Equals(variant.FloatValue))
     {
         return(false);
     }
     if (this.HasStringValue != variant.HasStringValue || this.HasStringValue && !this.StringValue.Equals(variant.StringValue))
     {
         return(false);
     }
     if (this.HasBlobValue != variant.HasBlobValue || this.HasBlobValue && !this.BlobValue.Equals(variant.BlobValue))
     {
         return(false);
     }
     if (this.HasMessageValue != variant.HasMessageValue || this.HasMessageValue && !this.MessageValue.Equals(variant.MessageValue))
     {
         return(false);
     }
     if (this.HasFourccValue != variant.HasFourccValue || this.HasFourccValue && !this.FourccValue.Equals(variant.FourccValue))
     {
         return(false);
     }
     if (this.HasUintValue != variant.HasUintValue || this.HasUintValue && !this.UintValue.Equals(variant.UintValue))
     {
         return(false);
     }
     if (this.HasEntityidValue == variant.HasEntityidValue && (!this.HasEntityidValue || this.EntityidValue.Equals(variant.EntityidValue)))
     {
         return(true);
     }
     return(false);
 }
コード例 #4
0
 public void SetValue(bnet.protocol.attribute.Variant val)
 {
     this.Value = val;
 }
コード例 #5
0
        public static bnet.protocol.attribute.Variant DeserializeLengthDelimited(Stream stream, bnet.protocol.attribute.Variant instance)
        {
            long position = (long)ProtocolParser.ReadUInt32(stream);

            position += stream.Position;
            return(bnet.protocol.attribute.Variant.Deserialize(stream, instance, position));
        }
コード例 #6
0
 public static bnet.protocol.attribute.Variant DeserializeLengthDelimited(Stream stream)
 {
     bnet.protocol.attribute.Variant variant = new bnet.protocol.attribute.Variant();
     bnet.protocol.attribute.Variant.DeserializeLengthDelimited(stream, variant);
     return(variant);
 }
コード例 #7
0
        public static bnet.protocol.attribute.Variant Deserialize(Stream stream, bnet.protocol.attribute.Variant instance, long limit)
        {
            BinaryReader binaryReader = new BinaryReader(stream);

            while (true)
            {
                if (limit < (long)0 || stream.Position < limit)
                {
                    int num = stream.ReadByte();
                    if (num == -1)
                    {
                        if (limit >= (long)0)
                        {
                            throw new EndOfStreamException();
                        }
                        break;
                    }
                    else if (num == 16)
                    {
                        instance.BoolValue = ProtocolParser.ReadBool(stream);
                    }
                    else if (num == 24)
                    {
                        instance.IntValue = (long)ProtocolParser.ReadUInt64(stream);
                    }
                    else if (num == 33)
                    {
                        instance.FloatValue = binaryReader.ReadDouble();
                    }
                    else if (num == 42)
                    {
                        instance.StringValue = ProtocolParser.ReadString(stream);
                    }
                    else if (num == 50)
                    {
                        instance.BlobValue = ProtocolParser.ReadBytes(stream);
                    }
                    else if (num == 58)
                    {
                        instance.MessageValue = ProtocolParser.ReadBytes(stream);
                    }
                    else if (num == 66)
                    {
                        instance.FourccValue = ProtocolParser.ReadString(stream);
                    }
                    else if (num == 72)
                    {
                        instance.UintValue = ProtocolParser.ReadUInt64(stream);
                    }
                    else if (num != 82)
                    {
                        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);
                    }
                    else if (instance.EntityidValue != null)
                    {
                        EntityId.DeserializeLengthDelimited(stream, instance.EntityidValue);
                    }
                    else
                    {
                        instance.EntityidValue = EntityId.DeserializeLengthDelimited(stream);
                    }
                }
                else
                {
                    if (stream.Position != limit)
                    {
                        throw new ProtocolBufferException("Read past max limit");
                    }
                    break;
                }
            }
            return(instance);
        }
コード例 #8
0
 public static bnet.protocol.attribute.Variant Deserialize(Stream stream, bnet.protocol.attribute.Variant instance)
 {
     return(bnet.protocol.attribute.Variant.Deserialize(stream, instance, (long)-1));
 }