[Groonga-commit] groonga/grnxx at 65c5755 [master] Update grnxx::Storage to use grnxx::CommonHeader.

Back to archive index

susumu.yata null+****@clear*****
Mon Jul 8 16:17:21 JST 2013


susumu.yata	2013-07-08 16:17:21 +0900 (Mon, 08 Jul 2013)

  New Revision: 65c5755d3f170f0dc3c973db076d88d347bf49ab
  https://github.com/groonga/grnxx/commit/65c5755d3f170f0dc3c973db076d88d347bf49ab

  Message:
    Update grnxx::Storage to use grnxx::CommonHeader.

  Modified files:
    lib/grnxx/storage/header.cpp
    lib/grnxx/storage/header.hpp

  Modified: lib/grnxx/storage/header.cpp (+7 -9)
===================================================================
--- lib/grnxx/storage/header.cpp    2013-07-08 16:05:27 +0900 (26c5c2b)
+++ lib/grnxx/storage/header.cpp    2013-07-08 16:17:21 +0900 (0a2af79)
@@ -22,20 +22,18 @@
 #include "grnxx/grnxx.hpp"
 #include "grnxx/storage.hpp"
 
-#define GRNXX_STORAGE_HEADER_FORMAT  "grnxx::Storage"
-
 namespace grnxx {
 namespace storage {
 namespace {
 
-// For comparison.
-constexpr char HEADER_FORMAT[HEADER_FORMAT_SIZE] = GRNXX_STORAGE_HEADER_FORMAT;
+// The format string.
+constexpr char STORAGE_FORMAT[CommonHeader::FORMAT_SIZE] =
+    "grnxx::Storage";
 
 }  // namespace
 
 Header::Header()
-    : format{},
-      version{},
+    : common_header(),
       max_file_size(0),
       max_num_files(0),
       num_body_chunks(0),
@@ -54,18 +52,18 @@ Header::Header()
       data_mutex(),
       file_mutex(),
       reserved_2{} {
-  std::strcpy(version, Grnxx::version());
   for (size_t i = 0; i < NUM_IDLE_NODE_LISTS; ++i) {
     oldest_idle_node_ids[i] = STORAGE_INVALID_NODE_ID;
   }
 }
 
 Header::operator bool() const {
-  return std::memcmp(format, HEADER_FORMAT, HEADER_FORMAT_SIZE) == 0;
+  return common_header.format() ==
+         Bytes(STORAGE_FORMAT, CommonHeader::FORMAT_SIZE);
 }
 
 void Header::validate() {
-  std::memcpy(format, HEADER_FORMAT, HEADER_FORMAT_SIZE);
+  common_header = CommonHeader(STORAGE_FORMAT);
 }
 
 }  // namespace storage

  Modified: lib/grnxx/storage/header.hpp (+4 -10)
===================================================================
--- lib/grnxx/storage/header.hpp    2013-07-08 16:05:27 +0900 (4d434bb)
+++ lib/grnxx/storage/header.hpp    2013-07-08 16:17:21 +0900 (83fc932)
@@ -20,6 +20,7 @@
 
 #include "grnxx/features.hpp"
 
+#include "grnxx/common_header.hpp"
 #include "grnxx/mutex.hpp"
 #include "grnxx/types.hpp"
 
@@ -30,18 +31,11 @@ namespace storage {
 // sizeof(Header) must not be greater than this value.
 constexpr size_t HEADER_SIZE         = 512;
 
-// The buffer size allocated for the format identifier.
-constexpr size_t HEADER_FORMAT_SIZE  = 32;
-// The buffer size allocated for the version string.
-constexpr size_t HEADER_VERSION_SIZE = 32;
-
 constexpr size_t NUM_IDLE_NODE_LISTS = 64;
 
 struct Header {
-  // The identifier for checking the file format.
-  char format[HEADER_FORMAT_SIZE];
-  // The grnxx version.
-  char version[HEADER_VERSION_SIZE];
+  // The file format and the grnxx version.
+  CommonHeader common_header;
   // The maximum size of each file.
   uint64_t max_file_size;
   // The maximum number of files.
@@ -78,7 +72,7 @@ struct Header {
   Mutex data_mutex;
   // A mutex object for exclusively update files.
   Mutex file_mutex;
-  uint8_t reserved_2[120];
+  uint8_t reserved_2[88];
 
   // Initialize the members except "format".
   Header();
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index