| 287 | } |
| 288 | |
| 289 | void TTextProcessingCollection::Load(IInputStream* stream) { |
| 290 | DefaultInit(stream); |
| 291 | auto guidId = CreateComponentGuidsMapping(); |
| 292 | |
| 293 | ui64 headerSize; |
| 294 | while (TryLoad(stream, headerSize)) { |
| 295 | TArrayHolder<ui8> buffer(new ui8[headerSize]); |
| 296 | const ui32 loadedBytes = stream->Load(buffer.Get(), headerSize); |
| 297 | CB_ENSURE( |
| 298 | loadedBytes == headerSize, |
| 299 | "Failed to deserialize: Failed to load collection part" |
| 300 | ); |
| 301 | |
| 302 | auto collectionPart = flatbuffers::GetRoot<NCatBoostFbs::TCollectionPart>(buffer.Get()); |
| 303 | const auto partId = GuidFromFbs(collectionPart->Id()); |
| 304 | |
| 305 | if (collectionPart->PartType() == NCatBoostFbs::EPartType_Tokenizer) { |
| 306 | auto tokenizer = MakeIntrusive<TTokenizer>(); |
| 307 | tokenizer->Load(stream); |
| 308 | CB_ENSURE( |
| 309 | partId == tokenizer->Id(), |
| 310 | "Failed to deserialize: TokenizerId not equal to PartId" |
| 311 | ); |
| 312 | |
| 313 | Digitizers[guidId[partId]].Tokenizer = std::move(tokenizer); |
| 314 | } else if (collectionPart->PartType() == NCatBoostFbs::EPartType_Dictionary) { |
| 315 | auto dictionary = MakeIntrusive<TDictionaryProxy>(); |
| 316 | dictionary->Load(stream); |
| 317 | CB_ENSURE( |
| 318 | partId == dictionary->Id(), |
| 319 | "Failed to deserialize: DictionaryId not equal to PartId" |
| 320 | ); |
| 321 | |
| 322 | Digitizers[guidId[partId]].Dictionary = std::move(dictionary); |
| 323 | } else if (collectionPart->PartType() == NCatBoostFbs::EPartType_FeatureCalcer) { |
| 324 | TTextFeatureCalcerPtr calcer = TTextCalcerSerializer::Load(stream); |
| 325 | FeatureCalcers[guidId[partId]] = calcer; |
| 326 | CB_ENSURE(partId == calcer->Id(), "Failed to deserialize: CalcerId not equal to PartId"); |
| 327 | } else if (collectionPart->PartType() == NCatBoostFbs::EPartType_Terminate){ |
| 328 | break; |
| 329 | } else { |
| 330 | CB_ENSURE(false, "Failed to deserialize: Unknown part type"); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | CheckForMissingParts(); |
| 335 | CalcRuntimeData(); |
| 336 | CheckPerFeatureIdx(); |
| 337 | } |
| 338 | |
| 339 | void TTextProcessingCollection::LoadNonOwning(TMemoryInput* in) { |
| 340 | DefaultInit(in); |
no test coverage detected