| 223 | } |
| 224 | |
| 225 | TString 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 | |
| 260 | double ParseDoubleFromYsonString(const TYsonStringBuf& str) |
| 261 | { |
no test coverage detected