ObjFW
OFData.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFObject.h"
18 #import "OFSerialization.h"
19 #import "OFMessagePackRepresentation.h"
20 
21 OF_ASSUME_NONNULL_BEGIN
22 
23 @class OFString;
24 @class OFURL;
25 
36 {
37  unsigned char *_items;
38  size_t _count, _itemSize;
39  bool _freeWhenDone;
40 }
41 
45 @property (readonly, nonatomic) size_t itemSize;
46 
54 + (instancetype)dataWithItems: (const void *)items
55  count: (size_t)count;
56 
66 + (instancetype)dataWithItems: (const void *)items
67  itemSize: (size_t)itemSize
68  count: (size_t)count;
69 
80 + (instancetype)dataWithItemsNoCopy: (const void *)items
81  count: (size_t)count
82  freeWhenDone: (bool)freeWhenDone;
83 
95 + (instancetype)dataWithItemsNoCopy: (const void *)items
96  itemSize: (size_t)itemSize
97  count: (size_t)count
98  freeWhenDone: (bool)freeWhenDone;
99 
100 #ifdef OF_HAVE_FILES
101 
108 + (instancetype)dataWithContentsOfFile: (OFString *)path;
109 #endif
110 
111 #if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS)
112 
119 + (instancetype)dataWithContentsOfURL: (OFURL *)URL;
120 #endif
121 
129 + (instancetype)dataWithStringRepresentation: (OFString *)string;
130 
138 + (instancetype)dataWithBase64EncodedString: (OFString *)string;
139 
140 - init OF_UNAVAILABLE;
141 
150 - initWithItems: (const void *)items
151  count: (size_t)count;
152 
162 - initWithItems: (const void *)items
163  itemSize: (size_t)itemSize
164  count: (size_t)count;
165 
177 - initWithItemsNoCopy: (const void *)items
178  count: (size_t)count
179  freeWhenDone: (bool)freeWhenDone;
180 
193 - initWithItemsNoCopy: (const void *)items
194  itemSize: (size_t)itemSize
195  count: (size_t)count
196  freeWhenDone: (bool)freeWhenDone;
197 
198 #ifdef OF_HAVE_FILES
199 
206 - initWithContentsOfFile: (OFString *)path;
207 #endif
208 
209 #if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS)
210 
217 - initWithContentsOfURL: (OFURL *)URL;
218 #endif
219 
227 - initWithStringRepresentation: (OFString *)string;
228 
236 - initWithBase64EncodedString: (OFString *)string;
237 
243 - (size_t)count;
244 
252 - (const void *)items OF_RETURNS_INNER_POINTER;
253 
260 - (const void *)itemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER;
261 
267 - (nullable const void *)firstItem OF_RETURNS_INNER_POINTER;
268 
274 - (nullable const void *)lastItem OF_RETURNS_INNER_POINTER;
275 
285 
292 
293 #ifdef OF_HAVE_FILES
294 
299 - (void)writeToFile: (OFString *)path;
300 #endif
301 @end
302 
303 OF_ASSUME_NONNULL_END
304 
305 #import "OFMutableData.h"
306 #import "OFData+CryptoHashing.h"
307 #import "OFData+MessagePackValue.h"
nullable const void * firstItem()
Returns the first item of the OFData.
Definition: OFData.m:466
nullable const void * lastItem()
Returns the last item of the OFData.
Definition: OFData.m:474
A protocol for the creation of mutable copies.
Definition: OFObject.h:935
A class for handling strings.
Definition: OFString.h:114
size_t itemSize
Definition: OFData.h:46
A class for parsing URLs and accessing parts of it.
Definition: OFURL.h:29
id init()
Initializes an already allocated object.
Definition: OFObject.m:488
A protocol implemented by classes that support encoding to a MessagePack representation.
Definition: OFMessagePackRepresentation.h:30
A protocol for the creation of copies.
Definition: OFObject.h:914
A protocol for comparing objects.
The root class for all other classes inside ObjFW.
Definition: OFObject.h:379
OFString * stringRepresentation()
Returns the string representation of the data.
Definition: OFData.m:576
const void * items()
Returns all items of the OFData as a C array.
Definition: OFData.m:453
A protocol for serializing objects.
Definition: OFSerialization.h:30
OFString * stringByBase64Encoding()
Returns a string containing the data in Base64 encoding.
Definition: OFData.m:588
A class for storing arbitrary data in an array.
Definition: OFData.h:34
size_t count()
Returns the number of items in the OFData.
Definition: OFData.m:448