implement session stat command

Implement the session stat command.

Change-Id: I1ff715dd32d963722182db84b475bc9adbfcc7ea
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/src/ipmiblob/blob_handler.cpp b/src/ipmiblob/blob_handler.cpp
index 74ecd02..0d31b3f 100644
--- a/src/ipmiblob/blob_handler.cpp
+++ b/src/ipmiblob/blob_handler.cpp
@@ -242,6 +242,37 @@
     return meta;
 }
 
+StatResponse BlobHandler::getStat(std::uint16_t session)
+{
+    StatResponse meta;
+    std::vector<std::uint8_t> resp;
+    std::vector<std::uint8_t> request;
+    auto addrSession = reinterpret_cast<const std::uint8_t*>(&session);
+    std::copy(addrSession, addrSession + sizeof(session),
+              std::back_inserter(request));
+
+    try
+    {
+        resp = sendIpmiPayload(BlobOEMCommands::bmcBlobSessionStat, request);
+    }
+    catch (const BlobException& b)
+    {
+        throw;
+    }
+
+    std::memcpy(&meta.blob_state, &resp[0], sizeof(meta.blob_state));
+    std::memcpy(&meta.size, &resp[sizeof(meta.blob_state)], sizeof(meta.size));
+    int offset = sizeof(meta.blob_state) + sizeof(meta.size);
+    std::uint8_t len = resp[offset];
+    if (len > 0)
+    {
+        std::copy(&resp[offset + 1], &resp[resp.size()],
+                  std::back_inserter(meta.metadata));
+    }
+
+    return meta;
+}
+
 std::uint16_t BlobHandler::openBlob(const std::string& id,
                                     std::uint16_t handlerFlags)
 {