Compression.h
Go to the documentation of this file.
1 /****
2  * Compression.h
3  *
4  * Created on: 31 Aug 2018
5  *
6  * Copyright 2019 mikee47 <mike@sillyhouse.net>
7  *
8  * This file is part of the IFS Library
9  *
10  * This library is free software: you can redistribute it and/or modify it under the terms of the
11  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  * See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with this library.
18  * If not, see <https://www.gnu.org/licenses/>.
19  *
20  ****/
21 
22 #pragma once
23 
24 #include "Types.h"
25 
26 namespace IFS
27 {
31 #define IFS_COMPRESSION_TYPE_MAP(XX) \
32  XX(None, "Normal file, no compression") \
33  XX(GZip, "GZIP compressed for serving via HTTP")
34 
38 struct __attribute__((packed)) Compression {
39  enum class Type : uint8_t {
40 #define XX(_tag, _comment) _tag,
42 #undef XX
43  MAX
44  };
45  Type type;
46  uint32_t originalSize;
47 
48  bool operator==(const Compression& other) const
49  {
50  return type == other.type && originalSize == other.originalSize;
51  }
52 
53  bool operator!=(const Compression& other) const
54  {
55  return !operator==(other);
56  }
57 };
58 
59 static_assert(sizeof(Compression) == 5, "Compression wrong size");
60 
67 Compression::Type getCompressionType(const char* str, Compression::Type defaultValue = Compression::Type::None);
68 
69 inline Compression::Type getCompressionType(const String& str, Compression::Type defaultValue = Compression::Type::None)
70 {
71  return getCompressionType(str.c_str(), defaultValue);
72 }
73 
76 } // namespace IFS
77 
String toString(IFS::Compression::Type type)
Get the string representation for the given compression type.
The String class.
Definition: WString.h:136
#define str(s)
Definition: testrunner.h:124
#define IFS_COMPRESSION_TYPE_MAP(XX)
compression type
Definition: Compression.h:50
#define MAX(a, b)
Definition: spiffs_nucleus.h:541
Definition: DirectoryTemplate.h:36
@ type
or urn:{domain}:service:{serviceType}:{v}
Type
Definition: Resource.h:41
Compression::Type getCompressionType(const char *str, Compression::Type defaultValue=Compression::Type::None)
Type
Definition: Compression.h:58