WriteString() public static method

Writes a string to the stream; supported wire-types: String
public static WriteString ( string value, ProtoWriter writer ) : void
value string
writer ProtoWriter
return void
コード例 #1
0
        /// <summary>
        /// Writes an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
        /// </summary>
        public static void WriteNetObject(object value, ProtoWriter dest, int key, NetObjectOptions options)
        {
#if FEAT_IKVM
            throw new NotSupportedException();
#else
            Helpers.DebugAssert(value != null);
            bool dynamicType         = (options & NetObjectOptions.DynamicType) != 0,
                 asReference         = (options & NetObjectOptions.AsReference) != 0;
            WireType     wireType    = dest.WireType;
            SubItemToken token       = ProtoWriter.StartSubItem(null, dest);
            bool         writeObject = true;
            if (asReference)
            {
                bool existing;
                int  objectKey = dest.NetCache.AddObjectKey(value, out existing);
                ProtoWriter.WriteFieldHeader(existing ? FieldExistingObjectKey : FieldNewObjectKey, WireType.Variant, dest);
                ProtoWriter.WriteInt32(objectKey, dest);
                if (existing)
                {
                    writeObject = false;
                }
            }

            if (writeObject)
            {
                if (dynamicType)
                {
                    bool existing;
                    Type type = value.GetType();

                    if (!(value is string))
                    {
                        key = dest.GetTypeKey(ref type);
                        if (key < 0)
                        {
                            throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
                        }
                    }
                    int typeKey = dest.NetCache.AddObjectKey(type, out existing);
                    ProtoWriter.WriteFieldHeader(existing ? FieldExistingTypeKey : FieldNewTypeKey, WireType.Variant, dest);
                    ProtoWriter.WriteInt32(typeKey, dest);
                    if (!existing)
                    {
                        ProtoWriter.WriteFieldHeader(FieldTypeName, WireType.String, dest);
                        ProtoWriter.WriteString(dest.SerializeType(type), dest);
                    }
                }
                ProtoWriter.WriteFieldHeader(FieldObject, wireType, dest);
                if (value is string)
                {
                    ProtoWriter.WriteString((string)value, dest);
                }
                else
                {
                    ProtoWriter.WriteObject(value, key, dest);
                }
            }
            ProtoWriter.EndSubItem(token, dest);
#endif
        }
コード例 #2
0
        public static void WriteNetObject(object value, ProtoWriter dest, int key, BclHelpers.NetObjectOptions options)
        {
            bool flag;
            bool flag1;

            if (dest == null)
            {
                throw new ArgumentNullException("dest");
            }
            bool         flag2        = (byte)(options & BclHelpers.NetObjectOptions.DynamicType) != 0;
            bool         flag3        = (byte)(options & BclHelpers.NetObjectOptions.AsReference) != 0;
            WireType     wireType     = dest.WireType;
            SubItemToken subItemToken = ProtoWriter.StartSubItem(null, dest);
            bool         flag4        = true;

            if (flag3)
            {
                int num = dest.NetCache.AddObjectKey(value, out flag);
                ProtoWriter.WriteFieldHeader((flag ? 1 : 2), WireType.Variant, dest);
                ProtoWriter.WriteInt32(num, dest);
                if (flag)
                {
                    flag4 = false;
                }
            }
            if (flag4)
            {
                if (flag2)
                {
                    Type type = value.GetType();
                    if (!(value is string))
                    {
                        key = dest.GetTypeKey(ref type);
                        if (key < 0)
                        {
                            throw new InvalidOperationException(string.Concat("Dynamic type is not a contract-type: ", type.Name));
                        }
                    }
                    int num1 = dest.NetCache.AddObjectKey(type, out flag1);
                    ProtoWriter.WriteFieldHeader((flag1 ? 3 : 4), WireType.Variant, dest);
                    ProtoWriter.WriteInt32(num1, dest);
                    if (!flag1)
                    {
                        ProtoWriter.WriteFieldHeader(8, WireType.String, dest);
                        ProtoWriter.WriteString(dest.SerializeType(type), dest);
                    }
                }
                ProtoWriter.WriteFieldHeader(10, wireType, dest);
                if (!(value is string))
                {
                    ProtoWriter.WriteObject(value, key, dest);
                }
                else
                {
                    ProtoWriter.WriteString((string)value, dest);
                }
            }
            ProtoWriter.EndSubItem(subItemToken, dest);
        }
コード例 #3
0
 public static void WriteType(Type value, ProtoWriter writer)
 {
     if (writer == null)
     {
         throw new ArgumentNullException("writer");
     }
     ProtoWriter.WriteString(writer.SerializeType(value), writer);
 }
コード例 #4
0
ファイル: BclHelpers.cs プロジェクト: x1234xx/Mystery_Stealer
        public static void WriteNetObject(object value, ProtoWriter dest, int key, NetObjectOptions options)
        {
            if (dest == null)
            {
                throw new ArgumentNullException("dest");
            }
            bool         flag     = (options & NetObjectOptions.DynamicType) != 0;
            bool         num      = (options & NetObjectOptions.AsReference) != 0;
            WireType     wireType = dest.WireType;
            SubItemToken token    = ProtoWriter.StartSubItem(null, dest);
            bool         flag2    = true;

            if (num)
            {
                bool existing;
                int  value2 = dest.NetCache.AddObjectKey(value, out existing);
                ProtoWriter.WriteFieldHeader(existing ? 1 : 2, WireType.Variant, dest);
                ProtoWriter.WriteInt32(value2, dest);
                if (existing)
                {
                    flag2 = false;
                }
            }
            if (flag2)
            {
                if (flag)
                {
                    Type type = value.GetType();
                    if (!(value is string))
                    {
                        key = dest.GetTypeKey(ref type);
                        if (key < 0)
                        {
                            throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
                        }
                    }
                    bool existing2;
                    int  value3 = dest.NetCache.AddObjectKey(type, out existing2);
                    ProtoWriter.WriteFieldHeader(existing2 ? 3 : 4, WireType.Variant, dest);
                    ProtoWriter.WriteInt32(value3, dest);
                    if (!existing2)
                    {
                        ProtoWriter.WriteFieldHeader(8, WireType.String, dest);
                        ProtoWriter.WriteString(dest.SerializeType(type), dest);
                    }
                }
                ProtoWriter.WriteFieldHeader(10, wireType, dest);
                if (value is string)
                {
                    ProtoWriter.WriteString((string)value, dest);
                }
                else
                {
                    ProtoWriter.WriteObject(value, key, dest);
                }
            }
            ProtoWriter.EndSubItem(token, dest);
        }
コード例 #5
0
        public static void WriteNetObject(object value, ProtoWriter dest, int key, BclHelpers.NetObjectOptions options)
        {
            if (dest == null)
            {
                throw new ArgumentNullException("dest");
            }
            bool         flag     = (byte)(options & BclHelpers.NetObjectOptions.DynamicType) != 0;
            bool         flag2    = (byte)(options & BclHelpers.NetObjectOptions.AsReference) != 0;
            WireType     wireType = dest.WireType;
            SubItemToken token    = ProtoWriter.StartSubItem(null, dest);
            bool         flag3    = true;

            if (flag2)
            {
                bool flag4;
                int  value2 = dest.NetCache.AddObjectKey(value, out flag4);
                ProtoWriter.WriteFieldHeader((!flag4) ? 2 : 1, WireType.Variant, dest);
                ProtoWriter.WriteInt32(value2, dest);
                if (flag4)
                {
                    flag3 = false;
                }
            }
            if (flag3)
            {
                if (flag)
                {
                    Type type = value.GetType();
                    if (!(value is string))
                    {
                        key = dest.GetTypeKey(ref type);
                        if (key < 0)
                        {
                            throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.get_Name());
                        }
                    }
                    bool flag5;
                    int  value3 = dest.NetCache.AddObjectKey(type, out flag5);
                    ProtoWriter.WriteFieldHeader((!flag5) ? 4 : 3, WireType.Variant, dest);
                    ProtoWriter.WriteInt32(value3, dest);
                    if (!flag5)
                    {
                        ProtoWriter.WriteFieldHeader(8, WireType.String, dest);
                        ProtoWriter.WriteString(dest.SerializeType(type), dest);
                    }
                }
                ProtoWriter.WriteFieldHeader(10, wireType, dest);
                if (value is string)
                {
                    ProtoWriter.WriteString((string)value, dest);
                }
                else
                {
                    ProtoWriter.WriteObject(value, key, dest);
                }
            }
            ProtoWriter.EndSubItem(token, dest);
        }
コード例 #6
0
        /// <summary>
        /// Writes an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
        /// </summary>
        public static void WriteNetObject(object value, ProtoWriter dest, int key, bool dynamicType, bool asReference)
        {
            Helpers.DebugAssert(value != null);
            WireType     wireType    = dest.WireType;
            SubItemToken token       = ProtoWriter.StartSubItem(null, dest);
            bool         writeObject = true;

            if (asReference)
            {
                bool existing;
                int  objectKey = dest.NetCache.AddObjectKey(value, out existing);
                ProtoWriter.WriteFieldHeader(existing ? FieldExistingObjectKey : FieldNewObjectKey, WireType.Variant, dest);
                ProtoWriter.WriteInt32(objectKey, dest);
                if (existing)
                {
                    writeObject = false;
                }
            }

            if (writeObject)
            {
                if (dynamicType)
                {
                    bool existing;
                    Type type = value.GetType();
                    key = dest.GetTypeKey(ref type);
                    int typeKey = dest.NetCache.AddObjectKey(type, out existing);
                    ProtoWriter.WriteFieldHeader(existing ? FieldExistingTypeKey : FieldNewTypeKey, WireType.Variant, dest);
                    ProtoWriter.WriteInt32(typeKey, dest);
                    if (!existing)
                    {
                        ProtoWriter.WriteFieldHeader(FieldTypeName, WireType.String, dest);
                        ProtoWriter.WriteString(dest.SerializeType(type), dest);
                    }
                }
                ProtoWriter.WriteFieldHeader(FieldObject, wireType, dest);
                if (value is string)
                {
                    ProtoWriter.WriteString((string)value, dest);
                }
                else
                {
                    ProtoWriter.WriteObject(value, key, dest);
                }
            }
            ProtoWriter.EndSubItem(token, dest);
        }