1 /* values.h: constants and functions for document value handling.
3 * Copyright (C) 2006,2010,2015 Olly Betts
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef OMEGA_INCLUDED_VALUES_H
21 #define OMEGA_INCLUDED_VALUES_H
29 // Include these to get htonl, etc.
30 #ifdef HAVE_ARPA_INET_H
31 # include <arpa/inet.h>
33 #ifdef HAVE_NETINET_IN_H
34 # include <netinet/in.h>
37 inline uint32_t htonl(uint32_t v
) {
38 return (v
<< 24) | ((v
& 0xff00) << 8) | ((v
>> 8) & 0xff00) | (v
>> 24);
40 # define ntohl(V) htonl(V)
44 VALUE_LASTMOD
= 0, // 4 byte big endian value - seconds since 1970.
45 VALUE_MD5
= 1, // 16 byte MD5 checksum of original document.
46 VALUE_SIZE
= 2, // sortable_serialise(<file size in bytes>).
47 VALUE_CTIME
= 3 // Like VALUE_LASTMOD, but for last metadata change.
50 inline uint32_t binary_string_to_int(const std::string
&s
)
52 if (s
.size() != 4) return (uint32_t)-1;
54 std::memcpy(&v
, s
.data(), 4);
58 inline std::string
int_to_binary_string(uint32_t v
)
61 return std::string(reinterpret_cast<const char*>(&v
), 4);