MCPcopy Create free account
hub / github.com/catboost/catboost / ParseStringFromYsonString

Function ParseStringFromYsonString

library/cpp/yt/yson_string/convert.cpp:225–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223}
224
225TString ParseStringFromYsonString(const TYsonStringBuf& str)
226{
227 YT_ASSERT(str.GetType() == EYsonType::Node);
228 auto strBuf = str.AsStringBuf();
229 TMemoryInput input(strBuf.data(), strBuf.length());
230 char ch;
231 if (!input.ReadChar(ch)) {
232 throw TYsonLiteralParseException("Missing type marker");
233 }
234 if (ch != NDetail::StringMarker) {
235 throw TYsonLiteralParseException(Format("Unexpected %v",
236 FormatUnexpectedMarker(ch)));
237 }
238 i64 length;
239 try {
240 ReadVarInt64(&input, &length);
241 } catch (const std::exception& ex) {
242 throw TYsonLiteralParseException(ex, "Failed to decode string length");
243 }
244 if (length < 0) {
245 throw TYsonLiteralParseException(Format(
246 "Negative string length %v",
247 length));
248 }
249 if (static_cast<i64>(input.Avail()) != length) {
250 throw TYsonLiteralParseException(Format("Incorrect remaining string length: expected %v, got %v",
251 length,
252 input.Avail()));
253 }
254 TString result;
255 result.ReserveAndResize(length);
256 YT_VERIFY(static_cast<i64>(input.Read(result.Detach(), length)) == length);
257 return result;
258}
259
260double ParseDoubleFromYsonString(const TYsonStringBuf& str)
261{

Callers 4

string>Method · 0.85

Calls 12

FormatUnexpectedMarkerFunction · 0.85
ReadCharMethod · 0.80
FormatFunction · 0.50
ReadVarInt64Function · 0.50
GetTypeMethod · 0.45
AsStringBufMethod · 0.45
dataMethod · 0.45
lengthMethod · 0.45
AvailMethod · 0.45
ReadMethod · 0.45
DetachMethod · 0.45

Tested by

no test coverage detected