ObjFW
OFData.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2023 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 "OFMessagePackRepresentation.h"
18 
21 OF_ASSUME_NONNULL_BEGIN
22 
23 @class OFIRI;
24 @class OFString;
25 
31 typedef enum {
35 
46 @property (readonly, nonatomic) size_t itemSize;
47 
51 @property (readonly, nonatomic) size_t count;
52 
58 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) const void *items
59  OF_RETURNS_INNER_POINTER;
60 
64 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) const void *firstItem
65  OF_RETURNS_INNER_POINTER;
66 
70 @property OF_NULLABLE_PROPERTY (readonly, nonatomic) const void *lastItem
71  OF_RETURNS_INNER_POINTER;
72 
79 @property (readonly, nonatomic) OFString *stringRepresentation;
80 
84 @property (readonly, nonatomic) OFString *stringByBase64Encoding;
85 
91 + (instancetype)data;
92 
99 + (instancetype)dataWithItemSize: (size_t)itemSize;
100 
108 + (instancetype)dataWithItems: (const void *)items count: (size_t)count;
109 
119 + (instancetype)dataWithItems: (const void *)items
120  count: (size_t)count
121  itemSize: (size_t)itemSize;
122 
136 + (instancetype)dataWithItemsNoCopy: (void *)items
137  count: (size_t)count
138  freeWhenDone: (bool)freeWhenDone;
139 
154 + (instancetype)dataWithItemsNoCopy: (void *)items
155  count: (size_t)count
156  itemSize: (size_t)itemSize
157  freeWhenDone: (bool)freeWhenDone;
158 
159 #ifdef OF_HAVE_FILES
160 
167 + (instancetype)dataWithContentsOfFile: (OFString *)path;
168 #endif
169 
177 + (instancetype)dataWithContentsOfIRI: (OFIRI *)IRI;
178 
188 + (instancetype)dataWithStringRepresentation: (OFString *)string;
189 
199 + (instancetype)dataWithBase64EncodedString: (OFString *)string;
200 
207 - (instancetype)init;
208 
216 - (instancetype)initWithItemSize: (size_t)itemSize;
217 
226 - (instancetype)initWithItems: (const void *)items count: (size_t)count;
227 
237 - (instancetype)initWithItems: (const void *)items
238  count: (size_t)count
239  itemSize: (size_t)itemSize;
240 
255 - (instancetype)initWithItemsNoCopy: (void *)items
256  count: (size_t)count
257  freeWhenDone: (bool)freeWhenDone;
258 
274 - (instancetype)initWithItemsNoCopy: (void *)items
275  count: (size_t)count
276  itemSize: (size_t)itemSize
277  freeWhenDone: (bool)freeWhenDone;
278 
279 #ifdef OF_HAVE_FILES
280 
287 - (instancetype)initWithContentsOfFile: (OFString *)path;
288 #endif
289 
297 - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI;
298 
308 - (instancetype)initWithStringRepresentation: (OFString *)string;
309 
319 - (instancetype)initWithBase64EncodedString: (OFString *)string;
320 
327 - (OFComparisonResult)compare: (OFData *)data;
328 
335 - (const void *)itemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER;
336 
343 - (OFData *)subdataWithRange: (OFRange)range;
344 
354 - (OFRange)rangeOfData: (OFData *)data
355  options: (OFDataSearchOptions)options
356  range: (OFRange)range;
357 
358 #ifdef OF_HAVE_FILES
359 
364 - (void)writeToFile: (OFString *)path;
365 #endif
366 
372 - (void)writeToIRI: (OFIRI *)IRI;
373 @end
374 
375 OF_ASSUME_NONNULL_END
376 
377 #import "OFMutableData.h"
378 #import "OFData+CryptographicHashing.h"
379 #import "OFData+MessagePackParsing.h"
const void * lastItem
The last item of the OFData or NULL.
Definition: OFData.h:71
A protocol for comparing objects.
Definition: OFObject.h:1383
The root class for all other classes inside ObjFW.
Definition: OFObject.h:686
OFDataSearchOptions
Options for searching in data.
Definition: OFData.h:31
size_t count
The number of items in the OFData.
Definition: OFData.h:51
const void * firstItem
The first item of the OFData or NULL.
Definition: OFData.h:65
A class for handling strings.
Definition: OFString.h:134
OFComparisonResult
A result of a comparison.
Definition: OFObject.h:54
instancetype data()
Creates a new OFData that is empty with an item size of 1.
Definition: OFData.m:146
OFString * stringRepresentation
The string representation of the data.
Definition: OFData.h:79
OFString * stringByBase64Encoding
A string containing the data in Base64 encoding.
Definition: OFData.h:84
A protocol implemented by classes that support encoding to a MessagePack representation.
Definition: OFMessagePackRepresentation.h:29
instancetype init()
Initializes an already allocated OFData to be empty with an item size of 1.
Definition: OFData.m:213
A class for representing IRIs, URIs, URLs and URNs, for parsing them as well as accessing parts of th...
Definition: OFIRI.h:35
A protocol for the creation of mutable copies.
Definition: OFObject.h:1367
A protocol for the creation of copies.
Definition: OFObject.h:1346
const void * items
All elements of the OFData as a C array.
Definition: OFData.h:59
A class for storing arbitrary data in an array.
Definition: OFData.h:41
size_t itemSize
The size of a single item in the OFData in bytes.
Definition: OFData.h:46
A range.
Definition: OFObject.h:106
Definition: OFData.h:33