MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / duration_example2

Function duration_example2

examples/src/cbor_examples.cpp:562–583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

560}
561
562void duration_example2()
563{
564 auto duration = std::chrono::system_clock::now().time_since_epoch();
565 auto time = std::chrono::duration_cast<std::chrono::duration<double>>(duration);
566
567 std::vector<uint8_t> data;
568 cbor::encode_cbor(time, data);
569
570 /*
571 c1, // Tag 1 (epoch time)
572 fb, // Double
573 41,d7,c8,ca,46,1c,0f,87 // 1596139800.43845
574 */
575
576 std::cout << "CBOR bytes:\n" << jsoncons::byte_string_view(data) << "\n\n";
577
578 auto seconds = cbor::decode_cbor<std::chrono::duration<double>>(data);
579 std::cout << "Time since epoch (seconds): " << seconds.count() << "\n";
580
581 auto milliseconds = cbor::decode_cbor<std::chrono::milliseconds>(data);
582 std::cout << "Time since epoch (milliseconds): " << milliseconds.count() << "\n";
583}
584
585void encode_with_raw_cbor_tags() // (since 1.2.0)
586{

Callers 1

mainFunction · 0.70

Calls 3

encode_cborFunction · 0.85
byte_string_viewClass · 0.85
countMethod · 0.45

Tested by

no test coverage detected