skiff_ut.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. #include <library/cpp/testing/unittest/registar.h>
  2. #include <library/cpp/skiff/skiff.h>
  3. #include <library/cpp/skiff/skiff_schema.h>
  4. #include <util/stream/buffer.h>
  5. #include <util/string/hex.h>
  6. using namespace NSkiff;
  7. ////////////////////////////////////////////////////////////////////////////////
  8. static TString HexEncode(const TBuffer& buffer)
  9. {
  10. auto result = HexEncode(buffer.Data(), buffer.Size());
  11. result.to_lower();
  12. return result;
  13. }
  14. Y_UNIT_TEST_SUITE(Skiff)
  15. {
  16. Y_UNIT_TEST(TestInt8)
  17. {
  18. TBufferStream bufferStream;
  19. auto schema = CreateSimpleTypeSchema(EWireType::Int8);
  20. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  21. tokenWriter.WriteInt8(42);
  22. tokenWriter.WriteInt8(-42);
  23. tokenWriter.Finish();
  24. UNIT_ASSERT_VALUES_EQUAL(HexEncode(bufferStream.Buffer()),
  25. "2a"
  26. "d6");
  27. TCheckedSkiffParser parser(schema, &bufferStream);
  28. UNIT_ASSERT_VALUES_EQUAL(parser.ParseInt8(), 42);
  29. UNIT_ASSERT_VALUES_EQUAL(parser.ParseInt8(), -42);
  30. }
  31. Y_UNIT_TEST(TestInt16)
  32. {
  33. TBufferStream bufferStream;
  34. auto schema = CreateSimpleTypeSchema(EWireType::Int16);
  35. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  36. tokenWriter.WriteInt16(0x1234);
  37. tokenWriter.WriteInt16(-0x1234);
  38. tokenWriter.Finish();
  39. UNIT_ASSERT_VALUES_EQUAL(HexEncode(bufferStream.Buffer()),
  40. "3412"
  41. "cced");
  42. TCheckedSkiffParser parser(schema, &bufferStream);
  43. UNIT_ASSERT_VALUES_EQUAL(parser.ParseInt16(), 0x1234);
  44. UNIT_ASSERT_VALUES_EQUAL(parser.ParseInt16(), -0x1234);
  45. }
  46. Y_UNIT_TEST(TestInt32)
  47. {
  48. TBufferStream bufferStream;
  49. auto schema = CreateSimpleTypeSchema(EWireType::Int32);
  50. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  51. tokenWriter.WriteInt32(0x12345678);
  52. tokenWriter.WriteInt32(-0x12345678);
  53. tokenWriter.Finish();
  54. UNIT_ASSERT_VALUES_EQUAL(HexEncode(bufferStream.Buffer()),
  55. "78563412"
  56. "88a9cbed");
  57. TCheckedSkiffParser parser(schema, &bufferStream);
  58. UNIT_ASSERT_VALUES_EQUAL(parser.ParseInt32(), 0x12345678);
  59. UNIT_ASSERT_VALUES_EQUAL(parser.ParseInt32(), -0x12345678);
  60. }
  61. Y_UNIT_TEST(TestInt64)
  62. {
  63. TBufferStream bufferStream;
  64. auto schema = CreateSimpleTypeSchema(EWireType::Int64);
  65. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  66. tokenWriter.WriteInt64(-42);
  67. tokenWriter.WriteInt64(100500);
  68. tokenWriter.WriteInt64(-0x123456789abcdef0);
  69. tokenWriter.Finish();
  70. UNIT_ASSERT_VALUES_EQUAL(HexEncode(bufferStream.Buffer()),
  71. "d6ffffffffffffff"
  72. "9488010000000000"
  73. "1021436587a9cbed");
  74. TCheckedSkiffParser parser(schema, &bufferStream);
  75. UNIT_ASSERT_VALUES_EQUAL(parser.ParseInt64(), -42);
  76. UNIT_ASSERT_VALUES_EQUAL(parser.ParseInt64(), 100500);
  77. UNIT_ASSERT_VALUES_EQUAL(parser.ParseInt64(), -0x123456789abcdef0);
  78. }
  79. Y_UNIT_TEST(TestUint8)
  80. {
  81. TBufferStream bufferStream;
  82. auto schema = CreateSimpleTypeSchema(EWireType::Uint8);
  83. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  84. tokenWriter.WriteUint8(42);
  85. tokenWriter.WriteUint8(200);
  86. tokenWriter.Finish();
  87. UNIT_ASSERT_VALUES_EQUAL(HexEncode(bufferStream.Buffer()),
  88. "2a"
  89. "c8");
  90. TCheckedSkiffParser parser(schema, &bufferStream);
  91. UNIT_ASSERT_VALUES_EQUAL(parser.ParseUint8(), 42);
  92. UNIT_ASSERT_VALUES_EQUAL(parser.ParseUint8(), 200);
  93. }
  94. Y_UNIT_TEST(TestUint16)
  95. {
  96. TBufferStream bufferStream;
  97. auto schema = CreateSimpleTypeSchema(EWireType::Uint16);
  98. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  99. tokenWriter.WriteUint16(0x1234);
  100. tokenWriter.WriteUint16(0xfedc);
  101. tokenWriter.Finish();
  102. UNIT_ASSERT_VALUES_EQUAL(HexEncode(bufferStream.Buffer()),
  103. "3412"
  104. "dcfe");
  105. TCheckedSkiffParser parser(schema, &bufferStream);
  106. UNIT_ASSERT_VALUES_EQUAL(parser.ParseUint16(), 0x1234);
  107. UNIT_ASSERT_VALUES_EQUAL(parser.ParseUint16(), 0xfedc);
  108. }
  109. Y_UNIT_TEST(TestUint32)
  110. {
  111. TBufferStream bufferStream;
  112. auto schema = CreateSimpleTypeSchema(EWireType::Uint32);
  113. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  114. tokenWriter.WriteUint32(0x12345678);
  115. tokenWriter.WriteUint32(0x87654321);
  116. tokenWriter.Finish();
  117. UNIT_ASSERT_VALUES_EQUAL(HexEncode(bufferStream.Buffer()),
  118. "78563412"
  119. "21436587");
  120. TCheckedSkiffParser parser(schema, &bufferStream);
  121. UNIT_ASSERT_VALUES_EQUAL(parser.ParseUint32(), 0x12345678);
  122. UNIT_ASSERT_VALUES_EQUAL(parser.ParseUint32(), 0x87654321);
  123. }
  124. Y_UNIT_TEST(TestUint64)
  125. {
  126. TBufferStream bufferStream;
  127. auto schema = CreateSimpleTypeSchema(EWireType::Uint64);
  128. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  129. tokenWriter.WriteUint64(42);
  130. tokenWriter.WriteUint64(100500);
  131. tokenWriter.WriteUint64(0x123456789abcdef0);
  132. tokenWriter.Finish();
  133. UNIT_ASSERT_VALUES_EQUAL(HexEncode(bufferStream.Buffer()),
  134. "2a00000000000000"
  135. "9488010000000000"
  136. "f0debc9a78563412");
  137. TCheckedSkiffParser parser(schema, &bufferStream);
  138. UNIT_ASSERT_VALUES_EQUAL(parser.ParseUint64(), 42);
  139. UNIT_ASSERT_VALUES_EQUAL(parser.ParseUint64(), 100500);
  140. UNIT_ASSERT_VALUES_EQUAL(parser.ParseUint64(), 0x123456789abcdef0);
  141. }
  142. Y_UNIT_TEST(TestInt128)
  143. {
  144. TBufferStream bufferStream;
  145. auto schema = CreateSimpleTypeSchema(EWireType::Int128);
  146. const TInt128 val1 = {0x1924cd4aeb9ced82, 0x0885e83f456d6a7e};
  147. const TInt128 val2 = {0xe9ba36585eccae1a, -0x7854b6f9ce448be9};
  148. TCheckedSkiffWriter writer(schema, &bufferStream);
  149. writer.WriteInt128(val1);
  150. writer.WriteInt128(val2);
  151. writer.Finish();
  152. UNIT_ASSERT_VALUES_EQUAL(HexEncode(bufferStream.Buffer()),
  153. "82ed9ceb4acd2419" "7e6a6d453fe88508"
  154. "1aaecc5e5836bae9" "1774bb310649ab87");
  155. TCheckedSkiffParser parser(schema, &bufferStream);
  156. UNIT_ASSERT_EQUAL(parser.ParseInt128(), val1);
  157. UNIT_ASSERT_EQUAL(parser.ParseInt128(), val2);
  158. }
  159. Y_UNIT_TEST(TestUint128)
  160. {
  161. TBufferStream bufferStream;
  162. auto schema = CreateSimpleTypeSchema(EWireType::Uint128);
  163. const auto val1 = TUint128{0x1924cd4aeb9ced82, 0x0885e83f456d6a7e};
  164. const auto val2 = TUint128{0xe9ba36585eccae1a, 0x8854b6f9ce448be9};
  165. TCheckedSkiffWriter writer(schema, &bufferStream);
  166. writer.WriteUint128(val1);
  167. writer.WriteUint128(val2);
  168. writer.Finish();
  169. UNIT_ASSERT_VALUES_EQUAL(HexEncode(bufferStream.Buffer()),
  170. "82ed9ceb4acd2419" "7e6a6d453fe88508"
  171. "1aaecc5e5836bae9" "e98b44cef9b65488");
  172. TCheckedSkiffParser parser(schema, &bufferStream);
  173. UNIT_ASSERT_EQUAL(parser.ParseUint128(), val1);
  174. UNIT_ASSERT_EQUAL(parser.ParseUint128(), val2);
  175. }
  176. Y_UNIT_TEST(TestBoolean)
  177. {
  178. auto schema = CreateSimpleTypeSchema(EWireType::Boolean);
  179. TBufferStream bufferStream;
  180. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  181. tokenWriter.WriteBoolean(true);
  182. tokenWriter.WriteBoolean(false);
  183. tokenWriter.Finish();
  184. TCheckedSkiffParser parser(schema, &bufferStream);
  185. UNIT_ASSERT_VALUES_EQUAL(parser.ParseBoolean(), true);
  186. UNIT_ASSERT_VALUES_EQUAL(parser.ParseBoolean(), false);
  187. {
  188. TBufferStream bufferStream;
  189. bufferStream.Write('\x02');
  190. TCheckedSkiffParser parser(schema, &bufferStream);
  191. UNIT_ASSERT_EXCEPTION(parser.ParseBoolean(), std::exception);
  192. }
  193. }
  194. Y_UNIT_TEST(TestVariant8)
  195. {
  196. auto schema = CreateVariant8Schema({
  197. CreateSimpleTypeSchema(EWireType::Nothing),
  198. CreateSimpleTypeSchema(EWireType::Uint64),
  199. });
  200. {
  201. TBufferStream bufferStream;
  202. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  203. UNIT_ASSERT_EXCEPTION(tokenWriter.WriteUint64(42), std::exception);
  204. }
  205. {
  206. TBufferStream bufferStream;
  207. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  208. tokenWriter.WriteVariant8Tag(0);
  209. UNIT_ASSERT_EXCEPTION(tokenWriter.WriteUint64(42), std::exception);
  210. }
  211. {
  212. TBufferStream bufferStream;
  213. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  214. tokenWriter.WriteVariant8Tag(1);
  215. UNIT_ASSERT_EXCEPTION(tokenWriter.WriteInt64(42), std::exception);
  216. }
  217. TBufferStream bufferStream;
  218. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  219. tokenWriter.WriteVariant8Tag(0);
  220. tokenWriter.WriteVariant8Tag(1);
  221. tokenWriter.WriteUint64(42);
  222. tokenWriter.Finish();
  223. TCheckedSkiffParser parser(schema, &bufferStream);
  224. UNIT_ASSERT_VALUES_EQUAL(parser.ParseVariant8Tag(), 0);
  225. UNIT_ASSERT_VALUES_EQUAL(parser.ParseVariant8Tag(), 1);
  226. UNIT_ASSERT_VALUES_EQUAL(parser.ParseUint64(), 42);
  227. parser.ValidateFinished();
  228. }
  229. Y_UNIT_TEST(TestTuple)
  230. {
  231. auto schema = CreateTupleSchema({
  232. CreateSimpleTypeSchema(EWireType::Int64),
  233. CreateSimpleTypeSchema(EWireType::String32),
  234. });
  235. {
  236. TBufferStream bufferStream;
  237. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  238. tokenWriter.WriteInt64(42);
  239. tokenWriter.WriteString32("foobar");
  240. tokenWriter.Finish();
  241. TCheckedSkiffParser parser(schema, &bufferStream);
  242. UNIT_ASSERT_VALUES_EQUAL(parser.ParseInt64(), 42);
  243. UNIT_ASSERT_VALUES_EQUAL(parser.ParseString32(), "foobar");
  244. parser.ValidateFinished();
  245. }
  246. }
  247. Y_UNIT_TEST(TestString)
  248. {
  249. auto schema = CreateSimpleTypeSchema(EWireType::String32);
  250. {
  251. TBufferStream bufferStream;
  252. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  253. tokenWriter.WriteString32("foo");
  254. tokenWriter.Finish();
  255. TCheckedSkiffParser parser(schema, &bufferStream);
  256. UNIT_ASSERT_VALUES_EQUAL(parser.ParseString32(), "foo");
  257. parser.ValidateFinished();
  258. }
  259. {
  260. TBufferStream bufferStream;
  261. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  262. tokenWriter.WriteString32("foo");
  263. tokenWriter.Finish();
  264. TCheckedSkiffParser parser(schema, &bufferStream);
  265. UNIT_ASSERT_EXCEPTION(parser.ParseInt64(), std::exception);
  266. }
  267. }
  268. Y_UNIT_TEST(TestRepeatedVariant8)
  269. {
  270. auto schema = CreateRepeatedVariant8Schema({
  271. CreateSimpleTypeSchema(EWireType::Int64),
  272. CreateSimpleTypeSchema(EWireType::Uint64),
  273. });
  274. {
  275. TBufferStream bufferStream;
  276. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  277. // row 0
  278. tokenWriter.WriteVariant8Tag(0);
  279. tokenWriter.WriteInt64(-8);
  280. // row 2
  281. tokenWriter.WriteVariant8Tag(1);
  282. tokenWriter.WriteUint64(42);
  283. // end
  284. tokenWriter.WriteVariant8Tag(EndOfSequenceTag<ui8>());
  285. tokenWriter.Finish();
  286. {
  287. TBufferInput input(bufferStream.Buffer());
  288. TCheckedSkiffParser parser(schema, &input);
  289. // row 1
  290. UNIT_ASSERT_VALUES_EQUAL(parser.ParseVariant8Tag(), 0);
  291. UNIT_ASSERT_VALUES_EQUAL(parser.ParseInt64(), -8);
  292. // row 2
  293. UNIT_ASSERT_VALUES_EQUAL(parser.ParseVariant8Tag(), 1);
  294. UNIT_ASSERT_VALUES_EQUAL(parser.ParseUint64(), 42);
  295. // end
  296. UNIT_ASSERT_VALUES_EQUAL(parser.ParseVariant8Tag(), EndOfSequenceTag<ui8>());
  297. parser.ValidateFinished();
  298. }
  299. {
  300. TBufferInput input(bufferStream.Buffer());
  301. TCheckedSkiffParser parser(schema, &input);
  302. UNIT_ASSERT_EXCEPTION(parser.ParseInt64(), std::exception);
  303. }
  304. {
  305. TBufferInput input(bufferStream.Buffer());
  306. TCheckedSkiffParser parser(schema, &input);
  307. parser.ParseVariant8Tag();
  308. UNIT_ASSERT_EXCEPTION(parser.ParseUint64(), std::exception);
  309. }
  310. {
  311. TBufferInput input(bufferStream.Buffer());
  312. TCheckedSkiffParser parser(schema, &input);
  313. parser.ParseVariant8Tag();
  314. parser.ParseInt64();
  315. UNIT_ASSERT_EXCEPTION(parser.ValidateFinished(), std::exception);
  316. }
  317. }
  318. {
  319. TBufferStream bufferStream;
  320. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  321. tokenWriter.WriteVariant8Tag(0);
  322. UNIT_ASSERT_EXCEPTION(tokenWriter.WriteUint64(5), std::exception);
  323. }
  324. {
  325. TBufferStream bufferStream;
  326. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  327. tokenWriter.WriteVariant8Tag(1);
  328. tokenWriter.WriteUint64(5);
  329. UNIT_ASSERT_EXCEPTION(tokenWriter.Finish(), std::exception);
  330. }
  331. }
  332. Y_UNIT_TEST(TestRepeatedVariant16)
  333. {
  334. auto schema = CreateRepeatedVariant16Schema({
  335. CreateSimpleTypeSchema(EWireType::Int64),
  336. CreateSimpleTypeSchema(EWireType::Uint64),
  337. });
  338. {
  339. TBufferStream bufferStream;
  340. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  341. // row 0
  342. tokenWriter.WriteVariant16Tag(0);
  343. tokenWriter.WriteInt64(-8);
  344. // row 2
  345. tokenWriter.WriteVariant16Tag(1);
  346. tokenWriter.WriteUint64(42);
  347. // end
  348. tokenWriter.WriteVariant16Tag(EndOfSequenceTag<ui16>());
  349. tokenWriter.Finish();
  350. TCheckedSkiffParser parser(schema, &bufferStream);
  351. // row 1
  352. UNIT_ASSERT_VALUES_EQUAL(parser.ParseVariant16Tag(), 0);
  353. UNIT_ASSERT_VALUES_EQUAL(parser.ParseInt64(), -8);
  354. // row 2
  355. UNIT_ASSERT_VALUES_EQUAL(parser.ParseVariant16Tag(), 1);
  356. UNIT_ASSERT_VALUES_EQUAL(parser.ParseUint64(), 42);
  357. // end
  358. UNIT_ASSERT_VALUES_EQUAL(parser.ParseVariant16Tag(), EndOfSequenceTag<ui16>());
  359. parser.ValidateFinished();
  360. }
  361. {
  362. TBufferStream bufferStream;
  363. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  364. tokenWriter.WriteVariant16Tag(0);
  365. UNIT_ASSERT_EXCEPTION(tokenWriter.WriteUint64(5), std::exception);
  366. }
  367. {
  368. TBufferStream bufferStream;
  369. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  370. tokenWriter.WriteVariant16Tag(1);
  371. tokenWriter.WriteUint64(5);
  372. UNIT_ASSERT_EXCEPTION(tokenWriter.Finish(), std::exception);
  373. }
  374. {
  375. TBufferStream bufferStream;
  376. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  377. // row 0
  378. tokenWriter.WriteVariant16Tag(0);
  379. tokenWriter.WriteInt64(-8);
  380. // row 2
  381. tokenWriter.WriteVariant16Tag(1);
  382. tokenWriter.WriteUint64(42);
  383. // end
  384. tokenWriter.WriteVariant16Tag(EndOfSequenceTag<ui16>());
  385. tokenWriter.Finish();
  386. {
  387. TBufferInput input(bufferStream.Buffer());
  388. TCheckedSkiffParser parser(schema, &input);
  389. UNIT_ASSERT_EXCEPTION(parser.ParseInt64(), std::exception);
  390. }
  391. {
  392. TBufferInput input(bufferStream.Buffer());
  393. TCheckedSkiffParser parser(schema, &input);
  394. parser.ParseVariant16Tag();
  395. UNIT_ASSERT_EXCEPTION(parser.ParseUint64(), std::exception);
  396. }
  397. {
  398. TBufferInput input(bufferStream.Buffer());
  399. TCheckedSkiffParser parser(schema, &input);
  400. parser.ParseVariant16Tag();
  401. parser.ParseInt64();
  402. UNIT_ASSERT_EXCEPTION(parser.ValidateFinished(), std::exception);
  403. }
  404. }
  405. }
  406. Y_UNIT_TEST(TestStruct)
  407. {
  408. TBufferStream bufferStream;
  409. auto schema = CreateRepeatedVariant16Schema(
  410. {
  411. CreateSimpleTypeSchema(EWireType::Nothing),
  412. CreateTupleSchema({
  413. CreateVariant8Schema({
  414. CreateSimpleTypeSchema(EWireType::Nothing),
  415. CreateSimpleTypeSchema(EWireType::Int64)
  416. }),
  417. CreateSimpleTypeSchema(EWireType::Uint64),
  418. })
  419. }
  420. );
  421. {
  422. TCheckedSkiffWriter tokenWriter(schema, &bufferStream);
  423. // row 0
  424. tokenWriter.WriteVariant16Tag(0);
  425. // row 1
  426. tokenWriter.WriteVariant16Tag(1);
  427. tokenWriter.WriteVariant8Tag(0);
  428. tokenWriter.WriteUint64(1);
  429. // row 2
  430. tokenWriter.WriteVariant16Tag(1);
  431. tokenWriter.WriteVariant8Tag(1);
  432. tokenWriter.WriteInt64(2);
  433. tokenWriter.WriteUint64(3);
  434. // end
  435. tokenWriter.WriteVariant16Tag(EndOfSequenceTag<ui16>());
  436. tokenWriter.Finish();
  437. }
  438. TCheckedSkiffParser parser(schema, &bufferStream);
  439. // row 0
  440. UNIT_ASSERT_VALUES_EQUAL(parser.ParseVariant16Tag(), 0);
  441. // row 1
  442. UNIT_ASSERT_VALUES_EQUAL(parser.ParseVariant16Tag(), 1);
  443. UNIT_ASSERT_VALUES_EQUAL(parser.ParseVariant8Tag(), 0);
  444. UNIT_ASSERT_VALUES_EQUAL(parser.ParseUint64(), 1);
  445. // row 2
  446. UNIT_ASSERT_VALUES_EQUAL(parser.ParseVariant16Tag(), 1);
  447. UNIT_ASSERT_VALUES_EQUAL(parser.ParseVariant8Tag(), 1);
  448. UNIT_ASSERT_VALUES_EQUAL(parser.ParseInt64(), 2);
  449. UNIT_ASSERT_VALUES_EQUAL(parser.ParseUint64(), 3);
  450. // end
  451. UNIT_ASSERT_VALUES_EQUAL(parser.ParseVariant16Tag(), EndOfSequenceTag<ui16>());
  452. parser.ValidateFinished();
  453. }
  454. Y_UNIT_TEST(TestSimpleOutputStream)
  455. {
  456. TBufferStream bufferStream;
  457. auto schema = CreateSimpleTypeSchema(EWireType::Int8);
  458. TCheckedSkiffWriter tokenWriter(schema, static_cast<IOutputStream*>(&bufferStream));
  459. tokenWriter.WriteInt8(42);
  460. tokenWriter.WriteInt8(-42);
  461. tokenWriter.Finish();
  462. UNIT_ASSERT_VALUES_EQUAL(HexEncode(bufferStream.Buffer()),
  463. "2a"
  464. "d6");
  465. TCheckedSkiffParser parser(schema, &bufferStream);
  466. UNIT_ASSERT_VALUES_EQUAL(parser.ParseInt8(), 42);
  467. UNIT_ASSERT_VALUES_EQUAL(parser.ParseInt8(), -42);
  468. }
  469. }
  470. ////////////////////////////////////////////////////////////////////////////////