ObjFW
OFData.h
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFObject.h"
17 #import "OFSerialization.h"
18 #import "OFMessagePackRepresentation.h"
19 
20 OF_ASSUME_NONNULL_BEGIN
21 
22 @class OFString;
23 @class OFURL;
24 
25 enum {
26  OF_DATA_SEARCH_BACKWARDS = 1
27 };
28 
39 {
40  unsigned char *_items;
41  size_t _count, _itemSize;
42  bool _freeWhenDone;
43 @private
44  OFData *_parentData;
45  OF_RESERVE_IVARS(OFData, 4)
46 }
47 
51 @property (readonly, nonatomic) size_t itemSize;
52 
56 @property (readonly, nonatomic) size_t count;
57 
63 @property (readonly, nonatomic) const void *items OF_RETURNS_INNER_POINTER;
64 
68 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) const void *firstItem
69  OF_RETURNS_INNER_POINTER;
70 
74 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) const void *lastItem
75  OF_RETURNS_INNER_POINTER;
76 
83 @property (readonly, nonatomic) OFString *stringRepresentation;
84 
88 @property (readonly, nonatomic) OFString *stringByBase64Encoding;
89 
97 + (instancetype)dataWithItems: (const void *)items count: (size_t)count;
98 
108 + (instancetype)dataWithItems: (const void *)items
109  count: (size_t)count
110  itemSize: (size_t)itemSize;
111 
122 + (instancetype)dataWithItemsNoCopy: (void *)items
123  count: (size_t)count
124  freeWhenDone: (bool)freeWhenDone;
125 
137 + (instancetype)dataWithItemsNoCopy: (void *)items
138  count: (size_t)count
139  itemSize: (size_t)itemSize
140  freeWhenDone: (bool)freeWhenDone;
141 
142 #ifdef OF_HAVE_FILES
150 + (instancetype)dataWithContentsOfFile: (OFString *)path;
151 #endif
152 
160 + (instancetype)dataWithContentsOfURL: (OFURL *)URL;
161 
169 + (instancetype)dataWithStringRepresentation: (OFString *)string;
170 
178 + (instancetype)dataWithBase64EncodedString: (OFString *)string;
179 
188 - (instancetype)initWithItems: (const void *)items count: (size_t)count;
189 
199 - (instancetype)initWithItems: (const void *)items
200  count: (size_t)count
201  itemSize: (size_t)itemSize;
202 
214 - (instancetype)initWithItemsNoCopy: (void *)items
215  count: (size_t)count
216  freeWhenDone: (bool)freeWhenDone;
217 
230 - (instancetype)initWithItemsNoCopy: (void *)items
231  count: (size_t)count
232  itemSize: (size_t)itemSize
233  freeWhenDone: (bool)freeWhenDone;
234 
235 #ifdef OF_HAVE_FILES
243 - (instancetype)initWithContentsOfFile: (OFString *)path;
244 #endif
245 
253 - (instancetype)initWithContentsOfURL: (OFURL *)URL;
254 
262 - (instancetype)initWithStringRepresentation: (OFString *)string;
263 
271 - (instancetype)initWithBase64EncodedString: (OFString *)string;
272 
279 - (const void *)itemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER;
280 
287 - (OFData *)subdataWithRange: (of_range_t)range;
288 
302 - (of_range_t)rangeOfData: (OFData *)data
303  options: (int)options
304  range: (of_range_t)range;
305 
306 #ifdef OF_HAVE_FILES
312 - (void)writeToFile: (OFString *)path;
313 #endif
314 
320 - (void)writeToURL: (OFURL *)URL;
321 @end
322 
323 OF_ASSUME_NONNULL_END
324 
325 #import "OFMutableData.h"
326 #import "OFData+ASN1DERParsing.h"
327 #import "OFData+CryptoHashing.h"
328 #import "OFData+MessagePackParsing.h"
A class for storing arbitrary data in an array.
Definition: OFData.h:40
The root class for all other classes inside ObjFW.
Definition: OFObject.h:520
A class for handling strings.
Definition: OFString.h:132
A class for parsing URLs and accessing parts of it.
Definition: OFURL.h:34
A protocol for comparing objects.
Definition: OFObject.h:1224
A protocol for the creation of copies.
Definition: OFObject.h:1187
A protocol implemented by classes that support encoding to a MessagePack representation.
Definition: OFMessagePackRepresentation.h:29
A protocol for the creation of mutable copies.
Definition: OFObject.h:1208
A protocol for serializing objects.
Definition: OFSerialization.h:29
A range.
Definition: OFObject.h:93