/// <summary> /// Writes a group field value, including tag, to the stream. /// </summary> public void WriteGroup(int fieldNumber, string fieldName, IMessageLite value) { output.WriteLine("{0}: {{", fieldName); output.Indent(); value.WriteTo(this); output.Outdent(); output.WriteLine("}"); }
private static void PrintSingleField(FieldDescriptor field, Object value, TextGenerator generator) { if (field.IsExtension) { generator.Print("["); // We special-case MessageSet elements for compatibility with proto1. if (field.ContainingType.Options.MessageSetWireFormat && field.FieldType == FieldType.Message && field.IsOptional // object equality (TODO(jonskeet): Work out what this comment means!) && field.ExtensionScope == field.MessageType) { generator.Print(field.MessageType.FullName); } else { generator.Print(field.FullName); } generator.Print("]"); } else { if (field.FieldType == FieldType.Group) { // Groups must be serialized with their original capitalization. generator.Print(field.MessageType.Name); } else { generator.Print(field.Name); } } if (field.MappedType == MappedType.Message) { generator.Print(" {\n"); generator.Indent(); } else { generator.Print(": "); } PrintFieldValue(field, value, generator); if (field.MappedType == MappedType.Message) { generator.Outdent(); generator.Print("}"); } generator.Print("\n"); }
private static void PrintUnknownFields(UnknownFieldSet unknownFields, TextGenerator generator) { foreach (KeyValuePair <int, UnknownField> entry in unknownFields.FieldDictionary) { String prefix = entry.Key.ToString() + ": "; UnknownField field = entry.Value; foreach (ulong value in field.VarintList) { generator.Print(prefix); generator.Print(value.ToString()); generator.Print("\n"); } foreach (uint value in field.Fixed32List) { generator.Print(prefix); generator.Print(string.Format("0x{0:x8}", value)); generator.Print("\n"); } foreach (ulong value in field.Fixed64List) { generator.Print(prefix); generator.Print(string.Format("0x{0:x16}", value)); generator.Print("\n"); } foreach (ByteString value in field.LengthDelimitedList) { generator.Print(entry.Key.ToString()); generator.Print(": \""); generator.Print(EscapeBytes(value)); generator.Print("\"\n"); } foreach (UnknownFieldSet value in field.GroupList) { generator.Print(entry.Key.ToString()); generator.Print(" {\n"); generator.Indent(); PrintUnknownFields(value, generator); generator.Outdent(); generator.Print("}\n"); } } }
private static void PrintUnknownFields(UnknownFieldSet unknownFields, TextGenerator generator) { foreach (KeyValuePair<int, UnknownField> entry in unknownFields.FieldDictionary) { String prefix = entry.Key.ToString() + ": "; UnknownField field = entry.Value; foreach (ulong value in field.VarintList) { generator.Print(prefix); generator.Print(value.ToString()); generator.Print("\n"); } foreach (uint value in field.Fixed32List) { generator.Print(prefix); generator.Print(string.Format("0x{0:x8}", value)); generator.Print("\n"); } foreach (ulong value in field.Fixed64List) { generator.Print(prefix); generator.Print(string.Format("0x{0:x16}", value)); generator.Print("\n"); } foreach (ByteString value in field.LengthDelimitedList) { generator.Print(entry.Key.ToString()); generator.Print(": \""); generator.Print(EscapeBytes(value)); generator.Print("\"\n"); } foreach (UnknownFieldSet value in field.GroupList) { generator.Print(entry.Key.ToString()); generator.Print(" {\n"); generator.Indent(); PrintUnknownFields(value, generator); generator.Outdent(); generator.Print("}\n"); } } }