public static string Dump(ProtoStream stream) { StringBuilder sb = new StringBuilder(); dump(sb, stream, 0); return(sb.ToString()); }
private static void dump(StringBuilder sb, ProtoStream stream, int level) { sb.AppendLine(); short fieldCount = stream.ReadFixedShort(); while (fieldCount-- > 0) { dumpField(sb, stream, level); } }
public virtual void Encode(ProtoStream stream) { }
private static void dumpField(StringBuilder sb, ProtoStream stream, int level) { int tagAndType = stream.ReadInt(); int tag = (tagAndType >> ProtoDefine.TAG_TYPE_BITS); ProtoType type = (ProtoType)(tagAndType & ProtoDefine.TAG_TYPE_MASK); for (int i = 0; i < level; i++) { sb.Append("\t"); } sb.AppendFormat("T:{0}\tTYPE:{1} = ", tag, type); switch (type) { case ProtoType.VarInt: { sb.Append(stream.ReadInt()); break; } case ProtoType.VarLong: { sb.Append(stream.ReadLong()); break; } case ProtoType.String: { sb.Append(stream.ReadString()); break; } case ProtoType.Object: { dump(sb, stream, level + 1); break; } case ProtoType.VarIntList: { int count = stream.ReadInt(); sb.Append(" COUNT:" + count + "["); for (int i = 0; i < count; i++) { sb.Append(stream.ReadInt()); if (i < count - 1) { sb.Append(","); } } sb.Append("]"); break; } case ProtoType.VarLongList: { int count = stream.ReadInt(); sb.Append(" COUNT:" + count + "["); for (int i = 0; i < count; i++) { sb.Append(stream.ReadLong()); if (i < count - 1) { sb.Append(","); } } sb.Append("]"); break; } case ProtoType.StringList: { int count = stream.ReadInt(); sb.Append(" COUNT:" + count + "["); for (int i = 0; i < count; i++) { sb.Append(stream.ReadString()); if (i < count - 1) { sb.Append(","); } } sb.Append("]"); break; } case ProtoType.ObjectList: { int count = stream.ReadInt(); sb.Append(" COUNT:" + count + "["); for (int i = 0; i < count; i++) { dump(sb, stream, level + 1); } sb.Append("\t]"); break; } default: break; } sb.AppendLine(); }