ObjFW  Check-in [3006cccbb9]

Overview
Comment:Add -[readDataArrayWithItemSize:andNItems:] to OFStream.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3006cccbb9afe5fb3e4fb0bbff586922108e4b44e64d29a4ff5e7e5894427ede
User & Date: js on 2010-04-08 23:26:00
Other Links: manifest | tags
Context
2010-04-08
23:37
Add -[readInt8] and -[readBigEndianInt{16,32,64}] to OFStream. check-in: c82e7f02f0 user: js tags: trunk
23:26
Add -[readDataArrayWithItemSize:andNItems:] to OFStream. check-in: 3006cccbb9 user: js tags: trunk
23:10
Add -[readExactlyNBytes:intoBuffer:] to OFStream. check-in: 96c8753847 user: js tags: trunk
Changes

Modified src/OFStream.h from [c52cf90821] to [11233aa834].

82
83
84
85
86
87
88










89
90
91
92
93
94
95
 *
 * \param buf The buffer into which the data is read
 * \param size The size of the data that should be read.
 *	       The buffer MUST be EXACTLY this big!
 */
- (void)readExactlyNBytes: (size_t)size
	       intoBuffer: (char*)buf;











/**
 * \return An OFDataArray with an item size of 1 with all the data of the
 *	   stream until the end of the stream is reached.
 */
- (OFDataArray*)readDataArrayTillEndOfStream;








>
>
>
>
>
>
>
>
>
>







82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
 *
 * \param buf The buffer into which the data is read
 * \param size The size of the data that should be read.
 *	       The buffer MUST be EXACTLY this big!
 */
- (void)readExactlyNBytes: (size_t)size
	       intoBuffer: (char*)buf;
/**
 * Reads nitems items with the specified item size from the stream and returns
 * them in an OFDataArray.
 *
 * \param itemsize The size of each item
 * \param nitems The number of iteams to read
 * \return An OFDataArray with at nitems items.
 */
- (OFDataArray*)readDataArrayWithItemSize: (size_t)itemsize
				andNItems: (size_t)nitems;

/**
 * \return An OFDataArray with an item size of 1 with all the data of the
 *	   stream until the end of the stream is reached.
 */
- (OFDataArray*)readDataArrayTillEndOfStream;

Modified src/OFStream.m from [c0dabeb17f] to [41f6ac1ebe].

97
98
99
100
101
102
103























104
105
106
107
108
109
110
{
	size_t len = 0;

	while (len < size)
		len += [self readNBytes: size - len
			     intoBuffer: buf + len];
}
























- (OFDataArray*)readDataArrayTillEndOfStream
{
	OFDataArray *a;
	char *buf;

	a = [OFDataArray dataArrayWithItemSize: 1];







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
{
	size_t len = 0;

	while (len < size)
		len += [self readNBytes: size - len
			     intoBuffer: buf + len];
}

- (OFDataArray*)readDataArrayWithItemSize: (size_t)itemsize
				andNItems: (size_t)nitems
{
	OFDataArray *da;
	char *tmp;

	da = [OFDataArray dataArrayWithItemSize: itemsize];
	tmp = [self allocMemoryForNItems: nitems
				withSize: itemsize];

	@try {
		[self readExactlyNBytes: nitems * itemsize
			     intoBuffer: tmp];

		[da addNItems: nitems
		   fromCArray: tmp];
	} @finally {
		[self freeMemory: tmp];
	}

	return da;
}

- (OFDataArray*)readDataArrayTillEndOfStream
{
	OFDataArray *a;
	char *buf;

	a = [OFDataArray dataArrayWithItemSize: 1];