ObjFW  Diff

Differences From Artifact [2e0b603741]:

To Artifact [28a9f74124]:


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#import "OFString.h"

#import "OFInvalidArgumentException.h"

@implementation OFMessagePackExtension
@synthesize type = _type, data = _data;

+ (instancetype)extensionWithType: (int8_t)type
			     data: (OFData *)data
{
	return [[[self alloc] initWithType: type
				      data: data] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithType: (int8_t)type
			data: (OFData *)data
{
	self = [super init];

	@try {
		if (data == nil || data.itemSize != 1)
			@throw [OFInvalidArgumentException exception];








|
<

|
<







|
<







20
21
22
23
24
25
26
27

28
29

30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
#import "OFString.h"

#import "OFInvalidArgumentException.h"

@implementation OFMessagePackExtension
@synthesize type = _type, data = _data;

+ (instancetype)extensionWithType: (int8_t)type data: (OFData *)data

{
	return [[[self alloc] initWithType: type data: data] autorelease];

}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithType: (int8_t)type data: (OFData *)data

{
	self = [super init];

	@try {
		if (data == nil || data.itemSize != 1)
			@throw [OFInvalidArgumentException exception];

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
		uint16_t length;

		ret = [OFMutableData dataWithCapacity: count + 4];

		prefix = 0xC8;
		[ret addItem: &prefix];

		length = OF_BSWAP16_IF_LE((uint16_t)count);
		[ret addItems: &length
			count: 2];

		[ret addItem: &_type];
	} else {
		uint32_t length;

		ret = [OFMutableData dataWithCapacity: count + 6];

		prefix = 0xC9;
		[ret addItem: &prefix];

		length = OF_BSWAP32_IF_LE((uint32_t)count);
		[ret addItems: &length
			count: 4];

		[ret addItem: &_type];
	}

	[ret addItems: _data.items
		count: _data.count];

	[ret makeImmutable];

	return ret;
}

- (OFString *)description
{







|
|
<










|
|
<




|
<
<







116
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132
133
134
135
136

137
138
139
140
141


142
143
144
145
146
147
148
		uint16_t length;

		ret = [OFMutableData dataWithCapacity: count + 4];

		prefix = 0xC8;
		[ret addItem: &prefix];

		length = OFToBigEndian16((uint16_t)count);
		[ret addItems: &length count: 2];


		[ret addItem: &_type];
	} else {
		uint32_t length;

		ret = [OFMutableData dataWithCapacity: count + 6];

		prefix = 0xC9;
		[ret addItem: &prefix];

		length = OFToBigEndian32((uint32_t)count);
		[ret addItems: &length count: 4];


		[ret addItem: &_type];
	}

	[ret addItems: _data.items count: _data.count];


	[ret makeImmutable];

	return ret;
}

- (OFString *)description
{
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
		return false;

	return true;
}

- (unsigned long)hash
{
	uint32_t hash;

	OF_HASH_INIT(hash);

	OF_HASH_ADD(hash, (uint8_t)_type);
	OF_HASH_ADD_HASH(hash, _data.hash);

	OF_HASH_FINALIZE(hash);

	return hash;
}

- (id)copy
{
	return [self retain];
}
@end







|

|

|
|

|









166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
		return false;

	return true;
}

- (unsigned long)hash
{
	unsigned long hash;

	OFHashInit(&hash);

	OFHashAdd(&hash, (uint8_t)_type);
	OFHashAddHash(&hash, _data.hash);

	OFHashFinalize(&hash);

	return hash;
}

- (id)copy
{
	return [self retain];
}
@end