/// <summary> /// Adds a field to the set. If a field with the same number already exists, it /// is replaced. /// </summary> internal UnknownFieldSet AddOrReplaceField(int number, UnknownField field) { if (number == 0) { throw new ArgumentOutOfRangeException("number", "Zero is not a valid field number."); } fields[number] = field; return(this); }
/// <summary> /// Merge the values in <paramref name="other" /> into this field. For each list /// of values, <paramref name="other"/>'s values are append to the ones in this /// field. /// </summary> internal UnknownField MergeFrom(UnknownField other) { varintList = AddAll(varintList, other.varintList); fixed32List = AddAll(fixed32List, other.fixed32List); fixed64List = AddAll(fixed64List, other.fixed64List); lengthDelimitedList = AddAll(lengthDelimitedList, other.lengthDelimitedList); groupList = AddAll(groupList, other.groupList); return(this); }
public void MergeUnknownFieldSet() { UnknownFieldSet unknownFields = new UnknownFieldSet(); UnknownField field = new UnknownField(); field.AddFixed32(123); unknownFields.AddOrReplaceField(1, field); UnknownFieldSet otherUnknownFields = new UnknownFieldSet(); Assert.IsFalse(otherUnknownFields.HasField(1)); UnknownFieldSet.MergeFrom(otherUnknownFields, unknownFields); Assert.IsTrue(otherUnknownFields.HasField(1)); }
/// <summary> /// Checks if two unknown field are equal. /// </summary> public override bool Equals(object other) { if (ReferenceEquals(this, other)) { return(true); } UnknownField otherField = other as UnknownField; return(otherField != null && Lists.Equals(varintList, otherField.varintList) && Lists.Equals(fixed32List, otherField.fixed32List) && Lists.Equals(fixed64List, otherField.fixed64List) && Lists.Equals(lengthDelimitedList, otherField.lengthDelimitedList)); }
/// <summary> /// Adds a field to the unknown field set. If a field with the same /// number already exists, the two are merged. /// </summary> private UnknownFieldSet MergeField(int number, UnknownField field) { if (number == 0) { throw new ArgumentOutOfRangeException("number", "Zero is not a valid field number."); } if (HasField(number)) { GetOrAddField(number).MergeFrom(field); } else { AddOrReplaceField(number, field); } return(this); }
private UnknownField GetOrAddField(int number) { if (lastField != null && number == lastFieldNumber) { return(lastField); } if (number == 0) { return(null); } if (fields.TryGetValue(number, out UnknownField existing)) { return(existing); } lastField = new UnknownField(); AddOrReplaceField(number, lastField); lastFieldNumber = number; return(lastField); }