ObjFW
OFData.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #import "OFObject.h"
21 #import "OFMessagePackRepresentation.h"
22 
25 OF_ASSUME_NONNULL_BEGIN
26 
27 @class OFIRI;
28 @class OFString;
29 
35 typedef enum {
39 
50 @property (readonly, nonatomic) size_t itemSize;
51 
55 @property (readonly, nonatomic) size_t count;
56 
62 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) const void *items
63  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 
95 + (instancetype)data;
96 
103 + (instancetype)dataWithItemSize: (size_t)itemSize;
104 
112 + (instancetype)dataWithItems: (const void *)items count: (size_t)count;
113 
123 + (instancetype)dataWithItems: (const void *)items
124  count: (size_t)count
125  itemSize: (size_t)itemSize;
126 
140 + (instancetype)dataWithItemsNoCopy: (void *)items
141  count: (size_t)count
142  freeWhenDone: (bool)freeWhenDone;
143 
158 + (instancetype)dataWithItemsNoCopy: (void *)items
159  count: (size_t)count
160  itemSize: (size_t)itemSize
161  freeWhenDone: (bool)freeWhenDone;
162 
163 #ifdef OF_HAVE_FILES
164 
171 + (instancetype)dataWithContentsOfFile: (OFString *)path;
172 #endif
173 
181 + (instancetype)dataWithContentsOfIRI: (OFIRI *)IRI;
182 
192 + (instancetype)dataWithStringRepresentation: (OFString *)string;
193 
203 + (instancetype)dataWithBase64EncodedString: (OFString *)string;
204 
211 - (instancetype)init;
212 
220 - (instancetype)initWithItemSize: (size_t)itemSize;
221 
230 - (instancetype)initWithItems: (const void *)items count: (size_t)count;
231 
241 - (instancetype)initWithItems: (const void *)items
242  count: (size_t)count
243  itemSize: (size_t)itemSize;
244 
259 - (instancetype)initWithItemsNoCopy: (void *)items
260  count: (size_t)count
261  freeWhenDone: (bool)freeWhenDone;
262 
278 - (instancetype)initWithItemsNoCopy: (void *)items
279  count: (size_t)count
280  itemSize: (size_t)itemSize
281  freeWhenDone: (bool)freeWhenDone;
282 
283 #ifdef OF_HAVE_FILES
284 
291 - (instancetype)initWithContentsOfFile: (OFString *)path;
292 #endif
293 
301 - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI;
302 
312 - (instancetype)initWithStringRepresentation: (OFString *)string;
313 
323 - (instancetype)initWithBase64EncodedString: (OFString *)string;
324 
331 - (OFComparisonResult)compare: (OFData *)data;
332 
339 - (const void *)itemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER;
340 
347 - (OFData *)subdataWithRange: (OFRange)range;
348 
358 - (OFRange)rangeOfData: (OFData *)data
359  options: (OFDataSearchOptions)options
360  range: (OFRange)range;
361 
362 #ifdef OF_HAVE_FILES
363 
368 - (void)writeToFile: (OFString *)path;
369 #endif
370 
376 - (void)writeToIRI: (OFIRI *)IRI;
377 @end
378 
379 OF_ASSUME_NONNULL_END
380 
381 #import "OFMutableData.h"
382 #import "OFData+CryptographicHashing.h"
383 #import "OFData+MessagePackParsing.h"
const void * lastItem
The last item of the OFData or NULL.
Definition: OFData.h:75
A protocol for comparing objects.
Definition: OFObject.h:1388
The root class for all other classes inside ObjFW.
Definition: OFObject.h:690
OFDataSearchOptions
Options for searching in data.
Definition: OFData.h:35
size_t count
The number of items in the OFData.
Definition: OFData.h:55
const void * firstItem
The first item of the OFData or NULL.
Definition: OFData.h:69
A class for handling strings.
Definition: OFString.h:142
OFComparisonResult
A result of a comparison.
Definition: OFObject.h:58
instancetype data()
Creates a new OFData that is empty with an item size of 1.
Definition: OFData.m:150
OFString * stringRepresentation
The string representation of the data.
Definition: OFData.h:83
OFString * stringByBase64Encoding
A string containing the data in Base64 encoding.
Definition: OFData.h:88
A protocol implemented by classes that support encoding to a MessagePack representation.
Definition: OFMessagePackRepresentation.h:33
instancetype init()
Initializes an already allocated OFData to be empty with an item size of 1.
Definition: OFData.m:217
A class for representing IRIs, URIs, URLs and URNs, for parsing them as well as accessing parts of th...
Definition: OFIRI.h:39
A protocol for the creation of mutable copies.
Definition: OFObject.h:1371
A protocol for the creation of copies.
Definition: OFObject.h:1350
const void * items
All elements of the OFData as a C array.
Definition: OFData.h:63
A class for storing arbitrary data in an array.
Definition: OFData.h:45
size_t itemSize
The size of a single item in the OFData in bytes.
Definition: OFData.h:50
A range.
Definition: OFObject.h:110
Definition: OFData.h:37