本文整理汇总了C#中ProtoBuf.ProtoReader.ReadString方法的典型用法代码示例。如果您正苦于以下问题:C# ProtoReader.ReadString方法的具体用法?C# ProtoReader.ReadString怎么用?C# ProtoReader.ReadString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProtoBuf.ProtoReader
的用法示例。
在下文中一共展示了ProtoReader.ReadString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadNetObject
/// <summary>
/// Reads an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
/// </summary>
public static object ReadNetObject(object value, ProtoReader source, int key, Type type, NetObjectOptions options)
{
#if FEAT_IKVM
throw new NotSupportedException();
#else
SubItemToken token = ProtoReader.StartSubItem(source);
int fieldNumber;
int newObjectKey = -1, newTypeKey = -1, tmp;
while ((fieldNumber = source.ReadFieldHeader()) > 0)
{
switch (fieldNumber)
{
case FieldExistingObjectKey:
tmp = source.ReadInt32();
value = source.NetCache.GetKeyedObject(tmp);
break;
case FieldNewObjectKey:
newObjectKey = source.ReadInt32();
break;
case FieldExistingTypeKey:
tmp = source.ReadInt32();
type = (Type)source.NetCache.GetKeyedObject(tmp);
key = source.GetTypeKey(ref type);
break;
case FieldNewTypeKey:
newTypeKey = source.ReadInt32();
break;
case FieldTypeName:
string typeName = source.ReadString();
type = source.DeserializeType(typeName);
if(type == null)
{
throw new ProtoException("Unable to resolve type: " + typeName + " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)");
}
if (type == typeof(string))
{
key = -1;
}
else
{
key = source.GetTypeKey(ref type);
if (key < 0)
throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
}
break;
case FieldObject:
bool isString = type == typeof(string);
bool wasNull = value == null;
bool lateSet = wasNull && (isString || ((options & NetObjectOptions.LateSet) != 0));
if (newObjectKey >= 0 && !lateSet)
{
if (value == null)
{
source.TrapNextObject(newObjectKey);
}
else
{
source.NetCache.SetKeyedObject(newObjectKey, value);
}
if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
}
object oldValue = value;
if (isString)
{
value = source.ReadString();
}
else
{
value = ProtoReader.ReadTypedObject(oldValue, key, source, type);
}
if (newObjectKey >= 0)
{
if(wasNull && !lateSet)
{ // this both ensures (via exception) that it *was* set, and makes sure we don't shout
// about changed references
oldValue = source.NetCache.GetKeyedObject(newObjectKey);
}
if (lateSet)
{
source.NetCache.SetKeyedObject(newObjectKey, value);
if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
}
}
if (newObjectKey >= 0 && !lateSet && !ReferenceEquals(oldValue, value))
{
throw new ProtoException("A reference-tracked object changed reference during deserialization");
}
if (newObjectKey < 0 && newTypeKey >= 0)
{ // have a new type, but not a new object
source.NetCache.SetKeyedObject(newTypeKey, type);
}
break;
default:
source.SkipField();
break;
//.........这里部分代码省略.........
示例2: BuildBody
//.........这里部分代码省略.........
.Replace("GC", string.Empty)
.Replace("k_", string.Empty)
.Replace("ESOMsg", string.Empty)
.TrimStart('_')
.Replace("EMsg", string.Empty);
if ( typeMsgName == "Create" || typeMsgName == "Destroy" || typeMsgName == "Update" )
typeMsgName = "SingleObject";
else if ( typeMsgName == "Multiple" )
typeMsgName = "MultipleObjects";
var possibleTypes = from type in typeof( CMClient ).Assembly.GetTypes()
from typePrefix in gcMsgPossibleTypePrefixes
where type.GetInterfaces().Contains( typeof ( IExtensible ) )
where type.FullName.StartsWith( typePrefix ) && type.FullName.EndsWith( typeMsgName )
select type;
foreach ( var type in possibleTypes )
{
var streamPos = str.Position;
try
{
return Deserialize( type, str );
}
catch ( Exception )
{
str.Position = streamPos;
}
}
if (!MsgUtil.IsProtoBuf(realEMsg))
return null;
// try reading it as a protobuf
using (ProtoReader reader = new ProtoReader(str, null, null))
{
var fields = new Dictionary<int, List<object>>();
while(true)
{
int field = reader.ReadFieldHeader();
if(field == 0)
break;
object fieldValue = null;
switch (reader.WireType)
{
case WireType.Variant:
case WireType.Fixed32:
case WireType.Fixed64:
case WireType.SignedVariant:
{
try
{
fieldValue = reader.ReadInt64();
}
catch (Exception)
{
fieldValue = "Unable to read Variant (debugme)";
}
break;
}
case WireType.String:
{
try
{
fieldValue = reader.ReadString();
}
catch (Exception)
{
fieldValue = "Unable to read String (debugme)";
}
break;
}
default:
{
fieldValue = string.Format( "{0} is not implemented", reader.WireType );
break;
}
}
if ( !fields.ContainsKey( field ) )
{
fields[ field ] = new List<object>();
}
fields[ field ].Add( fieldValue );
}
if (fields.Count > 0)
return fields;
}
return null;
}
示例3: ReadNetObject
/// <summary>
/// Reads an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
/// </summary>
public static object ReadNetObject(object value, ProtoReader source, int key, Type type, NetObjectOptions options)
{
SubItemToken token = ProtoReader.StartSubItem(source);
int fieldNumber;
int newObjectKey = -1, newTypeKey = -1, tmp;
while ((fieldNumber = source.ReadFieldHeader()) > 0)
{
switch (fieldNumber)
{
case FieldExistingObjectKey:
tmp = source.ReadInt32();
value = source.NetCache.GetKeyedObject(tmp);
break;
case FieldNewObjectKey:
newObjectKey = source.ReadInt32();
break;
case FieldExistingTypeKey:
tmp = source.ReadInt32();
type = (Type)source.NetCache.GetKeyedObject(tmp);
key = source.GetTypeKey(ref type);
break;
case FieldNewTypeKey:
newTypeKey = source.ReadInt32();
break;
case FieldTypeName:
string typeName = source.ReadString();
type = source.DeserializeType(typeName);
if(type == null)
{
throw new ProtoException("Unable to resolve type: " + typeName + " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)");
}
key = source.GetTypeKey(ref type);
if(key < 0) throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
break;
case FieldObject:
bool isString = type == typeof(string);
bool lateSet = value == null && isString;
if (value == null && !lateSet)
{
try
{
value = ((options & NetObjectOptions.UseConstructor) == 0)
? BclHelpers.GetUninitializedObject(type)
: (type.IsArray || type.IsInterface ? null : Activator.CreateInstance(type, true));
} catch (Exception ex)
{
throw new ProtoException("Unable to create type " + (type == null ? "<null>" : type.FullName) + ": " + ex.Message, ex);
}
}
if (newObjectKey >= 0 && !lateSet)
{
source.NetCache.SetKeyedObject(newObjectKey, value);
if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
}
object oldValue = value;
if (isString)
{
value = source.ReadString();
}
else
{
value = ProtoReader.ReadTypedObject(oldValue, key, source, type);
}
if (newObjectKey >= 0 && lateSet)
{
source.NetCache.SetKeyedObject(newObjectKey, value);
if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
}
if (newObjectKey >= 0 && !lateSet && !ReferenceEquals(oldValue, value) && type.FullName.StartsWith("System.Collections.Generic.Dictionary`2"))
{
throw new ProtoException("A reference-tracked object changed reference during deserialization");
}
if (newObjectKey < 0 && newTypeKey >= 0)
{ // have a new type, but not a new object
source.NetCache.SetKeyedObject(newTypeKey, type);
}
break;
default:
source.SkipField();
break;
}
}
if(newObjectKey >= 0 && (options & NetObjectOptions.AsReference) == 0)
{
throw new ProtoException("Object key in input stream, but reference-tracking was not expected");
}
ProtoReader.EndSubItem(token, source);
return value;
}
示例4: ReadNetObject
public static object ReadNetObject(object value, ProtoReader source, int key, Type type, BclHelpers.NetObjectOptions options)
{
SubItemToken token = ProtoReader.StartSubItem(source);
int num = -1;
int num2 = -1;
int num3;
while ((num3 = source.ReadFieldHeader()) > 0)
{
switch (num3)
{
case 1:
{
int key2 = source.ReadInt32();
value = source.NetCache.GetKeyedObject(key2);
continue;
}
case 2:
num = source.ReadInt32();
continue;
case 3:
{
int key2 = source.ReadInt32();
type = (Type)source.NetCache.GetKeyedObject(key2);
key = source.GetTypeKey(ref type);
continue;
}
case 4:
num2 = source.ReadInt32();
continue;
case 8:
{
string text = source.ReadString();
type = source.DeserializeType(text);
if (type == null)
{
throw new ProtoException("Unable to resolve type: " + text + " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)");
}
if (type == typeof(string))
{
key = -1;
}
else
{
key = source.GetTypeKey(ref type);
if (key < 0)
{
throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
}
}
continue;
}
case 10:
{
bool flag = type == typeof(string);
bool flag2 = value == null;
bool flag3 = flag2 && (flag || (byte)(options & BclHelpers.NetObjectOptions.LateSet) != 0);
if (num >= 0 && !flag3)
{
if (value == null)
{
source.TrapNextObject(num);
}
else
{
source.NetCache.SetKeyedObject(num, value);
}
if (num2 >= 0)
{
source.NetCache.SetKeyedObject(num2, type);
}
}
object obj = value;
if (flag)
{
value = source.ReadString();
}
else
{
value = ProtoReader.ReadTypedObject(obj, key, source, type);
}
if (num >= 0)
{
if (flag2 && !flag3)
{
obj = source.NetCache.GetKeyedObject(num);
}
if (flag3)
{
source.NetCache.SetKeyedObject(num, value);
if (num2 >= 0)
{
source.NetCache.SetKeyedObject(num2, type);
}
}
}
if (num >= 0 && !flag3 && !object.ReferenceEquals(obj, value))
{
throw new ProtoException("A reference-tracked object changed reference during deserialization");
}
if (num < 0 && num2 >= 0)
//.........这里部分代码省略.........
示例5: ReadNetObject
/// <summary>
/// Reads an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
/// </summary>
public static object ReadNetObject(object value, ProtoReader source, int key, Type type, NetObjectOptions options)
{
SubItemToken token = ProtoReader.StartSubItem(source);
int fieldNumber;
int newObjectKey = -1, newTypeKey = -1, tmp;
while ((fieldNumber = source.ReadFieldHeader()) > 0)
{
switch (fieldNumber)
{
case FieldExistingObjectKey:
tmp = source.ReadInt32();
value = source.NetCache.GetKeyedObject(tmp);
break;
case FieldNewObjectKey:
newObjectKey = source.ReadInt32();
break;
case FieldExistingTypeKey:
tmp = source.ReadInt32();
type = (Type)source.NetCache.GetKeyedObject(tmp);
key = source.GetTypeKey(ref type);
break;
case FieldNewTypeKey:
newTypeKey = source.ReadInt32();
break;
case FieldTypeName:
type = source.DeserializeType(source.ReadString());
key = source.GetTypeKey(ref type);
break;
case FieldObject:
bool isString = type == typeof(string);
bool lateSet = value == null && isString;
if (value == null && !lateSet)
{
value = ((options & NetObjectOptions.UseConstructor) == 0) ? BclHelpers.GetUninitializedObject(type) : Activator.CreateInstance(type);
}
if (newObjectKey >= 0 && !lateSet)
{
source.NetCache.SetKeyedObject(newObjectKey, value);
if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
}
object oldValue = value;
if (isString)
{
value = source.ReadString();
}
else
{
value = ProtoReader.ReadTypedObject(oldValue, key, source, type);
}
if (newObjectKey >= 0 && lateSet)
{
source.NetCache.SetKeyedObject(newObjectKey, value);
if (newTypeKey >= 0) source.NetCache.SetKeyedObject(newTypeKey, type);
}
if (!lateSet && !ReferenceEquals(oldValue, value))
{
throw new ProtoException("A reference-tracked object changed reference during deserialization");
}
break;
default:
source.SkipField();
break;
}
}
ProtoReader.EndSubItem(token, source);
return value;
}
示例6: ReadField
object ReadField(ProtoReader reader, Type memberT, string sClassName, CLS_Environment environment)
{
if (memberT == typeof(int))
{
return reader.ReadInt32();
}
else if (memberT == typeof(uint))
{
return reader.ReadUInt32();
}
else if (memberT == typeof(bool))
{
return reader.ReadBoolean();
}
else if (memberT == typeof(byte))
{
return reader.ReadByte();
}
else if (memberT == typeof(sbyte))
{
return reader.ReadSByte();
}
else if (memberT == typeof(float))
{
return reader.ReadSingle();
}
else if (memberT == typeof(double))
{
return reader.ReadDouble();
}
else if (memberT == typeof(short))
{
return reader.ReadInt16();
}
else if (memberT == typeof(ushort))
{
return reader.ReadUInt16();
}
else if (memberT == typeof(long))
{
return reader.ReadInt64();
}
else if (memberT == typeof(ulong))
{
return reader.ReadUInt64();
}
else if (memberT == typeof(string))
{
return reader.ReadString();
}
else if (memberT == typeof(byte[]))
{
return ProtoReader.AppendBytes(null, reader);
}
else if (memberT == typeof(SInstance))
{
SubItemToken st = ProtoReader.StartSubItem(reader);
CLS_Type_Class sClass = environment.GetTypeByKeywordQuiet(sClassName) as CLS_Type_Class;
if (!sClass.compiled)
RuntimeCompilerClass(sClassName);
CLS_Content content = CLS_Content.NewContent(environment);
CLS_Content.Value retVal = sClass.function.New(content, m_emptyParams);
CLS_Content.PoolContent(content);
SInstance sInstance = (SInstance)retVal.value;
ReadSInstance(reader, sInstance, environment);
ProtoReader.EndSubItem(st, reader);
return sInstance;
}
else
{
throw new NotImplementedException("未实现类型: " + memberT);
}
}
示例7: BuildBody
//.........这里部分代码省略.........
var gcMsg = Activator.CreateInstance( type ) as ISteamSerializableMessage;
return gcMsg.GetEMsg() == eMsg;
} );
string eMsgName = eMsg.ToString();
eMsgName = eMsgName.Replace( "Econ", "" ).Replace( "AM", "" );
// check name
if ( msgType == null )
msgType = GetSteamKitType( string.Format( "SteamKit2.Msg{0}", eMsgName ) );
if ( msgType != null )
{
var body = Activator.CreateInstance( msgType ) as ISteamSerializableMessage;
body.Deserialize( str );
return body;
}
msgType = GetSteamKitType( string.Format( "SteamKit2.CMsg{0}", eMsgName ) );
if ( msgType != null )
{
return Deserialize( msgType, str );
}
if ( eMsg == EMsg.ClientToGC || eMsg == EMsg.ClientFromGC )
{
return Serializer.Deserialize<CMsgGCClient>( str );
}
// try reading it as a protobuf
using (ProtoReader reader = new ProtoReader(str, null, null))
{
var fields = new Dictionary<int, List<object>>();
while(true)
{
int field = reader.ReadFieldHeader();
if(field == 0)
break;
object fieldValue = null;
switch (reader.WireType)
{
case WireType.Variant:
case WireType.Fixed32:
case WireType.Fixed64:
case WireType.SignedVariant:
{
try
{
fieldValue = reader.ReadInt64();
}
catch (Exception)
{
fieldValue = "Unable to read Variant (debugme)";
}
break;
}
case WireType.String:
{
try
{
fieldValue = reader.ReadString();
}
catch (Exception)
{
fieldValue = "Unable to read String (debugme)";
}
break;
}
default:
{
fieldValue = string.Format( "{0} is not implemented", reader.WireType );
break;
}
}
if ( !fields.ContainsKey( field ) )
{
fields[ field ] = new List<object>();
}
fields[ field ].Add( fieldValue );
}
if (fields.Count > 0)
return fields;
}
return null;
}
示例8: Read
/// <summary>
/// The read.
/// </summary>
/// <param name="compiledAsset">
/// The compiled asset.
/// </param>
/// <param name="protoReader">
/// The proto reader.
/// </param>
/// <returns>
/// The <see cref="CompiledAsset"/>.
/// </returns>
private static CompiledAsset Read(CompiledAsset compiledAsset, ProtoReader protoReader)
{
int num;
while ((num = protoReader.ReadFieldHeader()) > 0)
{
if (num != 1)
{
if (num != 3)
{
if (compiledAsset == null)
{
var expr_8A = new CompiledAsset();
ProtoReader.NoteObject(expr_8A, protoReader);
compiledAsset = expr_8A;
}
protoReader.SkipField();
}
else
{
if (compiledAsset == null)
{
var expr_4C = new CompiledAsset();
ProtoReader.NoteObject(expr_4C, protoReader);
compiledAsset = expr_4C;
}
PlatformData arg_63_0 = compiledAsset.PlatformData;
SubItemToken token = ProtoReader.StartSubItem(protoReader);
PlatformData arg_6F_0 = Read(arg_63_0, protoReader);
ProtoReader.EndSubItem(token, protoReader);
PlatformData platformData = arg_6F_0;
if (platformData != null)
{
compiledAsset.PlatformData = platformData;
}
}
}
else
{
if (compiledAsset == null)
{
var expr_19 = new CompiledAsset();
ProtoReader.NoteObject(expr_19, protoReader);
compiledAsset = expr_19;
}
string text = protoReader.ReadString();
if (text != null)
{
compiledAsset.Loader = text;
}
}
}
if (compiledAsset == null)
{
var expr_B2 = new CompiledAsset();
ProtoReader.NoteObject(expr_B2, protoReader);
compiledAsset = expr_B2;
}
return compiledAsset;
}
示例9: Read
private static Product Read(Product product1, ProtoReader reader1)
{
int num;
while ((num = reader1.ReadFieldHeader()) > 0)
{
switch (num)
{
case 1:
if (product1 == null)
{
product1 = new Product();
}
product1.ProductID = reader1.ReadInt32();
continue;
case 2:
if (product1 == null)
{
product1 = new Product();
}
product1.ProductName = reader1.ReadString();
continue;
case 3:
if (product1 == null)
{
product1 = new Product();
}
product1.SupplierID = new int?(reader1.ReadInt32());
continue;
}
}
return product1;
}
示例10: ReadProtobuf
public static Dictionary<int, List<object>> ReadProtobuf(Stream stream)
{
// try reading it as a protobuf
using (var reader = new ProtoReader(stream, null, null))
{
var fields = new Dictionary<int, List<object>>();
while (true)
{
int field = reader.ReadFieldHeader();
if (field == 0)
break;
object fieldValue = null;
switch (reader.WireType)
{
case WireType.Variant:
case WireType.Fixed32:
case WireType.Fixed64:
case WireType.SignedVariant:
{
try
{
fieldValue = reader.ReadInt64();
}
catch (Exception)
{
fieldValue = "Unable to read Variant (debugme)";
}
break;
}
case WireType.String:
{
try
{
fieldValue = reader.ReadString();
}
catch (Exception)
{
fieldValue = "Unable to read String (debugme)";
}
break;
}
default:
{
fieldValue = string.Format("{0} is not implemented", reader.WireType);
break;
}
}
if (!fields.ContainsKey(field))
{
fields[field] = new List<object>();
}
fields[field].Add(fieldValue);
}
if (fields.Count > 0)
return fields;
}
return null;
}