コード例 #1
0
        private static void RegisterSubType(Type type)
        {
            if (GrpcUtils.IgnoreTypeModel(type))
            {
                return;
            }

            var baseMetaType = GrpcUtils.Register(type.BaseType);
            // need to generate predictable fieldIds, allow specifying with [Id(n)] or use MurmurHash2 hash function % 2^29-1,
            var idAttr  = type.FirstAttribute <IdAttribute>();
            var fieldId = idAttr?.Id ?? Math.Abs(unchecked ((int)MurmurHash2.Hash(GetTypeName(type))));

            fieldId = fieldId % MaxFieldId;

            if (fieldId == default || (idAttr == null && fieldId < 50)) // min = 1, avoid hash conflicts with real field ids
            {
                fieldId += 50;
            }