コード例 #1
0
        public static TokenSet DeserializeTokenSet(this DeserializeContext context, ref ReadOnlySpan <byte> buffer)
        {
            var builder = new TokenSet.Builder();
            var count   = context.ReadInt32(ref buffer);

            for (var i = 0; i < count; i++)
            {
                var word = context.ReadString(ref buffer);
                builder.Insert(word);
            }
            return(builder.Root);
        }
コード例 #2
0
        public static InvertedIndex DeserializeInvertedIndex(this ReadOnlySpan <byte> buffer)
        {
            var invertedIndex = new InvertedIndex();
            var context       = new DeserializeContext(ref buffer);
            var count         = context.ReadInt32(ref buffer);

            for (var i = 0; i < count; i++)
            {
                var key   = context.ReadString(ref buffer);
                var value = DeserializeInvertedIndexEntry(context, ref buffer);
                invertedIndex.Add(key, value);
            }

            return(invertedIndex);
        }
コード例 #3
0
        public static Vector DeserializeFieldVector(this ReadOnlySpan <byte> buffer)
        {
            var context = new DeserializeContext(ref buffer);

            var count = context.ReadInt32(ref buffer);

            var values = new List <(int, double)>();

            for (var i = 0; i < count; i++)
            {
                var index = context.ReadDouble(ref buffer);
                var value = context.ReadDouble(ref buffer);
                values.Add(((int)index, value));
            }

            return(new Vector(values.ToArray()));
        }
コード例 #4
0
        public static InvertedIndexEntry DeserializeInvertedIndexEntry(this DeserializeContext context, ref ReadOnlySpan <byte> buffer)
        {
            var entry = new InvertedIndexEntry();

            entry.Index = context.ReadInt32(ref buffer);
            var fieldMatchesCount = context.ReadInt32(ref buffer);

            for (var i = 0; i < fieldMatchesCount; i++)
            {
                var fieldMatches = new FieldMatches();

                var fieldMatchesKey = context.ReadString(ref buffer);
                var fieldMatchCount = context.ReadInt32(ref buffer);

                for (var j = 0; j < fieldMatchCount; j++)
                {
                    var fieldMatchMeta = new FieldMatchMetadata();

                    var fieldMatchMetaKey   = context.ReadString(ref buffer);
                    var fieldMatchMetaCount = context.ReadInt32(ref buffer);

                    for (var k = 0; k < fieldMatchMetaCount; k++)
                    {
                        var fieldMatchMetaValueKey   = context.ReadString(ref buffer);
                        var fieldMatchMetaValueCount = context.ReadInt32(ref buffer);

                        var meta = new List <object?>(fieldMatchMetaValueCount);

                        for (var l = 0; l < fieldMatchMetaValueCount; l++)
                        {
                            if (context.ReadBoolean(ref buffer))
                            {
                                var typeName = context.ReadString(ref buffer);
                                var type     = Type.GetType(typeName);
                                if (type == null)
                                {
                                    throw new SerializationException($"no type named '{typeName}' found in loaded assemblies");
                                }

                                if (!SerializeContext.KnownTypes.TryGetValue(type, out var serializer))
                                {
                                    throw new SerializationException($"no serializer registered for '{type.Name}'");
                                }

                                var data         = context.ReadBytes(ref buffer);
                                var deserialized = serializer.Item2(data.ToArray());
                                meta.Add(deserialized);
                            }
                            else
                            {
                                meta.Add(null);
                            }
                        }

                        fieldMatchMeta.Add(fieldMatchMetaValueKey, meta);
                    }

                    fieldMatches.Add(fieldMatchMetaKey, fieldMatchMeta);
                }

                entry.Add(fieldMatchesKey, fieldMatches);
            }

            return(entry);
        }
コード例 #5
0
        public static InvertedIndexEntry DeserializeInvertedIndexEntry(this ReadOnlySpan <byte> buffer)
        {
            var context = new DeserializeContext(ref buffer);

            return(DeserializeInvertedIndexEntry(context, ref buffer));
        }