0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DirEntry.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #include <Common/Compat.h>
23 #include "DirEntry.h"
24 
25 #include <Common/Serialization.h>
26 #include <Common/Logger.h>
27 
28 using namespace Hypertable;
29 using namespace Serialization;
30 
31 namespace Hyperspace {
32 
33  size_t encoded_length_dir_entry(const DirEntry &dir_entry) {
34  return 1 + encoded_length_vstr(dir_entry.name);
35  }
36 
37  void encode_dir_entry(uint8_t **bufp, const DirEntry &dir_entry) {
38  encode_bool(bufp, dir_entry.is_dir);
39  encode_vstr(bufp, dir_entry.name);
40  }
41 
42  DirEntry &
43  decode_dir_entry(const uint8_t **bufp, size_t *remainp,
44  DirEntry &dir_entry) {
45  HT_TRY("decoding dir entry",
46  dir_entry.is_dir = decode_bool(bufp, remainp);
47  dir_entry.name = decode_vstr(bufp, remainp));
48  return dir_entry;
49  }
50 }
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
DirEntry & decode_dir_entry(const uint8_t **bufp, size_t *remainp, DirEntry &dir_entry)
Decodes (unserializes) a directory entry from a buffer.
Definition: DirEntry.cc:43
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
Hyperspace definitions
bool decode_bool(const uint8_t **bufp, size_t *remainp)
Decodes a boolean value from the given buffer.
Definition: Serialization.h:96
Logging routines and macros.
Compatibility Macros for C/C++.
Functions to serialize/deserialize primitives to/from a memory buffer.
void encode_dir_entry(uint8_t **bufp, const DirEntry &dir_entry)
Encodes (serializes) the given directory entry to a buffer.
Definition: DirEntry.cc:37
Definition: DirEntry.h:34
void encode_vstr(uint8_t **bufp, const void *buf, size_t len)
Encode a buffer as variable length string (vint64, data, null)
Hypertable definitions
void encode_bool(uint8_t **bufp, bool bval)
Encodes a boolean into the given buffer.
Definition: Serialization.h:84
bool is_dir
Boolean value indicating whether or not this entry is a directory.
Definition: DirEntry.h:38
size_t encoded_length_dir_entry(const DirEntry &dir_entry)
Returns the number of bytes required to encode (serialize) the given directory entry.
Definition: DirEntry.cc:33
#define HT_TRY(_s_, _code_)
Definition: Error.h:517
std::string name
Directory entry name.
Definition: DirEntry.h:36