public UnknownFieldSetTest() { descriptor = TestAllTypes.Descriptor; allFields = TestUtil.GetAllSet(); allFieldsData = allFields.ToByteString(); emptyMessage = TestEmptyMessage.ParseFrom(allFieldsData); unknownFields = emptyMessage.UnknownFields; }
/// <summary> /// Asserts that the given field sets are not equal and have different /// hash codes. /// </summary> /// <remarks> /// It's valid for non-equal objects to have the same hash code, so /// this test is stricter than it needs to be. However, this should happen /// relatively rarely. /// </remarks> /// <param name="s1"></param> /// <param name="s2"></param> private static void CheckNotEqual(UnknownFieldSet s1, UnknownFieldSet s2) { String equalsError = string.Format("{0} should not be equal to {1}", s1, s2); Assert.IsFalse(s1.Equals(s2), equalsError); Assert.IsFalse(s2.Equals(s1), equalsError); Assert.IsFalse(s1.GetHashCode() == s2.GetHashCode(), string.Format("{0} should have a different hash code from {1}", s1, s2)); }
/** * Asserts that the given field sets are equal and have identical hash codes. */ private static void CheckEqualsIsConsistent(UnknownFieldSet set) { // Object should be equal to itself. Assert.AreEqual(set, set); // Object should be equal to a copy of itself. UnknownFieldSet copy = UnknownFieldSet.CreateBuilder(set).Build(); Assert.AreEqual(set, copy); Assert.AreEqual(copy, set); Assert.AreEqual(set.GetHashCode(), copy.GetHashCode()); }
public void WriteUnknownGroup(int fieldNumber, UnknownFieldSet value) { WriteTag(fieldNumber, WireFormat.WireType.StartGroup); value.WriteTo(this); WriteTag(fieldNumber, WireFormat.WireType.EndGroup); }
/// <summary> /// Adds an embedded group. /// </summary> /// <param name="value"></param> /// <returns></returns> public Builder AddGroup(UnknownFieldSet value) { groupList = Add(groupList, value); return(this); }
/// <summary> /// Reads a group field value from the stream and merges it into the given /// UnknownFieldSet. /// </summary> public void ReadUnknownGroup(int fieldNumber, UnknownFieldSet.Builder builder) { if (recursionDepth >= recursionLimit) { throw InvalidProtocolBufferException.RecursionLimitExceeded(); } ++recursionDepth; builder.MergeFrom(this); CheckLastTagWas(WireFormat.MakeTag(fieldNumber, WireFormat.WireType.EndGroup)); --recursionDepth; }
/// <summary> /// Outputs a textual representation of <paramref name="fields" /> to <paramref name="output"/>. /// </summary> public static void Print(UnknownFieldSet fields, TextWriter output) { TextGenerator generator = new TextGenerator(output, "\n"); PrintUnknownFields(fields, generator); }
/// <summary> /// Creates a DynamicMessage with the given FieldSet. /// </summary> /// <param name="type"></param> /// <param name="fields"></param> /// <param name="unknownFields"></param> private DynamicMessage(MessageDescriptor type, FieldSet fields, UnknownFieldSet unknownFields) { this.type = type; this.fields = fields; this.unknownFields = unknownFields; }
public void WriteUnknownGroup(int fieldNumber, UnknownFieldSet value) { WriteTag(fieldNumber, WireFormat.WireType.StartGroup); value.WriteTo(this); WriteTag(fieldNumber, WireFormat.WireType.EndGroup); }
/// <summary> /// Replaces the set of unknown fields for this message. This should /// only be used before a message is built, by the builder. (In the /// Java code it is private, but the builder is nested so has access /// to it.) /// </summary> internal void SetUnknownFields(UnknownFieldSet fieldSet) { unknownFields = fieldSet; }
internal Builder(MessageDescriptor type) { this.type = type; this.fields = FieldSet.CreateInstance(); this.unknownFields = UnknownFieldSet.DefaultInstance; }
public TBuilder SetUnknownFields(UnknownFieldSet fields) { UnknownFields = fields; return(ThisBuilder); }
/// <summary> /// Creates a new unknown field set builder /// and initialize it from <paramref name="original"/>. /// </summary> public static Builder CreateBuilder(UnknownFieldSet original) { return(new Builder().MergeFrom(original)); }
/// <summary> /// Compute the number of bytes that would be needed to encode a /// group field represented by an UnknownFieldSet, including the tag. /// </summary> public static int ComputeUnknownGroupSize(int fieldNumber, UnknownFieldSet value) { return(ComputeTagSize(fieldNumber) * 2 + value.SerializedSize); }
/// <summary> /// Creates a new unknown field set builder /// and initialize it from <paramref name="original"/>. /// </summary> public static Builder CreateBuilder(UnknownFieldSet original) { return new Builder().MergeFrom(original); }
/// <summary> /// Compute the number of bytes that would be needed to encode a /// group field represented by an UnknownFieldSet, including the tag. /// </summary> public static int ComputeUnknownGroupSize(int fieldNumber, UnknownFieldSet value) { return ComputeTagSize(fieldNumber) * 2 + value.SerializedSize; }
/// <summary> /// Merges the fields from <paramref name="other"/> into this set. /// If a field number exists in both sets, the values in <paramref name="other"/> /// will be appended to the values in this set. /// </summary> public Builder MergeFrom(UnknownFieldSet other) { if (other != DefaultInstance) { foreach(KeyValuePair<int, UnknownField> entry in other.fields) { MergeField(entry.Key, entry.Value); } } return this; }
/// <summary> /// Compute the number of bytes that would be needed to encode a /// group field represented by an UnknownFieldSet, including the tag. /// </summary> public static int ComputeUnknownGroupSizeNoTag(UnknownFieldSet value) { return value.SerializedSize; }
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"); } } }
/// <summary> /// Outputs a textual representation of <paramref name="fields" /> to <paramref name="output"/>. /// </summary> public static void Print(UnknownFieldSet fields, TextWriter output) { TextGenerator generator = new TextGenerator(output, "\n"); PrintUnknownFields(fields, generator); }
public static string PrintToString(UnknownFieldSet fields) { StringWriter text = new StringWriter(); Print(fields, text); return text.ToString(); }
/// <summary> /// Compute the number of bytes that would be needed to encode a /// group field represented by an UnknownFieldSet, including the tag. /// </summary> public static int ComputeUnknownGroupSizeNoTag(UnknownFieldSet value) { return(value.SerializedSize); }