Esempio n. 1
0
        /// <summary>
        /// Munges a single value and checks that the length ends up the same as it was before.
        /// </summary>
        private static object CheckedMungeValue(FieldDescriptor fieldDescriptor, object value)
        {
            int    currentSize = CodedOutputStream.ComputeFieldSize(fieldDescriptor.FieldType, fieldDescriptor.FieldNumber, value);
            object mungedValue = MungeValue(fieldDescriptor, value);
            int    mungedSize  = CodedOutputStream.ComputeFieldSize(fieldDescriptor.FieldType, fieldDescriptor.FieldNumber, mungedValue);

            // Exceptions log more easily than assertions
            if (currentSize != mungedSize)
            {
                throw new Exception("Munged value had wrong size. Field type: " + fieldDescriptor.FieldType
                                    + "; old value: " + value + "; new value: " + mungedValue);
            }
            return(mungedValue);
        }