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); }
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); }
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())); }
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); }
public static InvertedIndexEntry DeserializeInvertedIndexEntry(this ReadOnlySpan <byte> buffer) { var context = new DeserializeContext(ref buffer); return(DeserializeInvertedIndexEntry(context, ref buffer)); }