Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BinaryType" /> class.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="readSchemas">Whether to read schemas.</param>
        public BinaryType(BinaryReader reader, bool readSchemas = false)
        {
            _typeId               = reader.ReadInt();
            _typeName             = reader.ReadString();
            _affinityKeyFieldName = reader.ReadString();

            int fieldsNum = reader.ReadInt();

            _fields = new Dictionary <string, BinaryField>(fieldsNum);

            for (int i = 0; i < fieldsNum; ++i)
            {
                string      name  = reader.ReadString();
                BinaryField field = new BinaryField(reader);

                _fields[name] = field;
            }

            _isEnum = reader.ReadBoolean();

            if (_isEnum)
            {
                var count = reader.ReadInt();

                _enumNameToValue = new Dictionary <string, int>(count);

                for (var i = 0; i < count; i++)
                {
                    _enumNameToValue[reader.ReadString()] = reader.ReadInt();
                }

                _enumValueToName = _enumNameToValue.ToDictionary(x => x.Value, x => x.Key);
            }

            if (readSchemas)
            {
                var cnt = reader.ReadInt();

                for (var i = 0; i < cnt; i++)
                {
                    var schemaId = reader.ReadInt();

                    var ids = new int[reader.ReadInt()];
                    for (var j = 0; j < ids.Length; j++)
                    {
                        ids[j] = reader.ReadInt();
                    }

                    _schema.Add(schemaId, ids);
                }
            }

            _marshaller = reader.Marshaller;
        }
Ejemplo n.º 2
0
        /** <inheritdoc /> */
        public void OnFieldWrite(int fieldId, string fieldName, int typeId)
        {
            if (!_ids.Contains(fieldId))
            {
                if (_fieldMap == null)
                {
                    _fieldMap = new Dictionary <string, BinaryField>();
                }

                if (!_fieldMap.ContainsKey(fieldName))
                {
                    _fieldMap[fieldName] = new BinaryField(typeId, fieldId);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BinaryType" /> class.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public BinaryType(IBinaryRawReader reader)
        {
            _typeId               = reader.ReadInt();
            _typeName             = reader.ReadString();
            _affinityKeyFieldName = reader.ReadString();

            int fieldsNum = reader.ReadInt();

            _fields = new Dictionary <string, BinaryField>(fieldsNum);

            for (int i = 0; i < fieldsNum; ++i)
            {
                string      name  = reader.ReadString();
                BinaryField field = new BinaryField(reader);

                _fields[name] = field;
            }

            _isEnum = reader.ReadBoolean();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BinaryType" /> class.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public BinaryType(BinaryReader reader)
        {
            _typeId               = reader.ReadInt();
            _typeName             = reader.ReadString();
            _affinityKeyFieldName = reader.ReadString();

            int fieldsNum = reader.ReadInt();

            _fields = new Dictionary <string, BinaryField>(fieldsNum);

            for (int i = 0; i < fieldsNum; ++i)
            {
                string      name  = reader.ReadString();
                BinaryField field = new BinaryField(reader);

                _fields[name] = field;
            }

            _isEnum = reader.ReadBoolean();

            if (_isEnum)
            {
                var count = reader.ReadInt();

                _enumNameToValue = new Dictionary <string, int>(count);

                for (var i = 0; i < count; i++)
                {
                    _enumNameToValue[reader.ReadString()] = reader.ReadInt();
                }

                _enumValueToName = _enumNameToValue.ToDictionary(x => x.Value, x => x.Key);
            }

            _marshaller = reader.Marshaller;
        }