private static object GetValue(FieldProto fdp, UnknownField unknownField) { if (unknownField.VarintList.Count > 0) { return(unknownField.VarintList[0]); } if (unknownField.Fixed32List.Count > 0) { if (fdp.Type == Type.TYPE_FLOAT) { return(BitConverter.ToSingle(BitConverter.GetBytes(unknownField.Fixed32List[0]), 0)); } return(unknownField.Fixed32List[0]); } throw new Exception(); }
/// <summary> /// Adds a field to the unknown field set. If a field with the same /// number already exists, the two are merged. /// </summary> public Builder MergeField(int number, UnknownField field) { if (number == 0) { throw new ArgumentOutOfRangeException("number", "Zero is not a valid field number."); } if (HasField(number)) { GetFieldBuilder(number).MergeFrom(field); } else { // Optimization: We could call getFieldBuilder(number).mergeFrom(field) // in this case, but that would create a copy of the Field object. // We'd rather reuse the one passed to us, so call AddField() instead. AddField(number, field); } return this; }
/// <summary> /// Adds a field to the set. If a field with the same number already exists, it /// is replaced. /// </summary> public Builder AddField(int number, UnknownField field) { if (number == 0) { throw new ArgumentOutOfRangeException("number", "Zero is not a valid field number."); } if (lastField != null && lastFieldNumber == number) { // Discard this. lastField = null; lastFieldNumber = 0; } fields[number] = field; return this; }
private static object GetValue(FieldProto fdp, UnknownField unknownField) { if (unknownField.VarintList.Count > 0) return unknownField.VarintList[0]; if (unknownField.Fixed32List.Count > 0) { if (fdp.Type == Type.TYPE_FLOAT) return BitConverter.ToSingle(BitConverter.GetBytes(unknownField.Fixed32List[0]), 0); return unknownField.Fixed32List[0]; } throw new Exception(); }
public void Visit(UnknownField unknownField) { WriteWithColor("?", ConsoleColor.DarkGray); }