Microsoft Windows SYSTEMTIME structure: C++/STL parsing library

Microsoft Windows SYSTEMTIME structure, stores individual components of date and time as individual fields, up to millisecond precision.

KS implementation details

License: CC0-1.0

This page hosts a formal specification of Microsoft Windows SYSTEMTIME structure using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Usage

Using Kaitai Struct in C++/STL usually consists of 3 steps.

  1. We need to create an STL input stream (std::istream).
    • One can open a stream for reading from a local file:
      #include <fstream>
      
      std::ifstream is("path/to/local/file.windows_systemtime", std::ifstream::binary);
    • Or one can prepare a stream for reading from existing std::string str:
      #include <sstream>
      
      std::istringstream is(str);
    • Or one can parse arbitrary char* buffer in memory, given that we know its size:
      #include <sstream>
      
      const char buf[] = { ... };
      std::string str(buf, sizeof buf);
      std::istringstream is(str);
  2. We need to wrap our input stream into Kaitai stream:
    #include <kaitai/kaitaistream.h>
    
    kaitai::kstream ks(&is);
  3. And finally, we can invoke the parsing:
    windows_systemtime_t data(&ks);

After that, one can get various attributes from the structure by invoking getter methods like:

data.year() // => Year

C++/STL source code to parse Microsoft Windows SYSTEMTIME structure

windows_systemtime.h

#ifndef WINDOWS_SYSTEMTIME_H_
#define WINDOWS_SYSTEMTIME_H_

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

#include "kaitai/kaitaistruct.h"

#include <stdint.h>

#if KAITAI_STRUCT_VERSION < 7000L
#error "Incompatible Kaitai Struct C++/STL API: version 0.7 or later is required"
#endif

/**
 * Microsoft Windows SYSTEMTIME structure, stores individual components
 * of date and time as individual fields, up to millisecond precision.
 * \sa Source
 */

class windows_systemtime_t : public kaitai::kstruct {

public:

    windows_systemtime_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, windows_systemtime_t* p__root = 0);

private:
    void _read();

public:
    ~windows_systemtime_t();

private:
    uint16_t m_year;
    uint16_t m_month;
    uint16_t m_dow;
    uint16_t m_day;
    uint16_t m_hour;
    uint16_t m_min;
    uint16_t m_sec;
    uint16_t m_msec;
    windows_systemtime_t* m__root;
    kaitai::kstruct* m__parent;

public:

    /**
     * Year
     */
    uint16_t year() const { return m_year; }

    /**
     * Month (January = 1)
     */
    uint16_t month() const { return m_month; }

    /**
     * Day of week (Sun = 0)
     */
    uint16_t dow() const { return m_dow; }

    /**
     * Day of month
     */
    uint16_t day() const { return m_day; }

    /**
     * Hours
     */
    uint16_t hour() const { return m_hour; }

    /**
     * Minutes
     */
    uint16_t min() const { return m_min; }

    /**
     * Seconds
     */
    uint16_t sec() const { return m_sec; }

    /**
     * Milliseconds
     */
    uint16_t msec() const { return m_msec; }
    windows_systemtime_t* _root() const { return m__root; }
    kaitai::kstruct* _parent() const { return m__parent; }
};

#endif  // WINDOWS_SYSTEMTIME_H_

windows_systemtime.cpp

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

#include "windows_systemtime.h"



windows_systemtime_t::windows_systemtime_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, windows_systemtime_t* p__root) : kaitai::kstruct(p__io) {
    m__parent = p__parent;
    m__root = this;
    _read();
}

void windows_systemtime_t::_read() {
    m_year = m__io->read_u2le();
    m_month = m__io->read_u2le();
    m_dow = m__io->read_u2le();
    m_day = m__io->read_u2le();
    m_hour = m__io->read_u2le();
    m_min = m__io->read_u2le();
    m_sec = m__io->read_u2le();
    m_msec = m__io->read_u2le();
}

windows_systemtime_t::~windows_systemtime_t() {
}