ObjFW  Diff

Differences From Artifact [33ef9555ae]:

To Artifact [205f87096d]:


16
17
18
19
20
21
22

23
24
25
26
27
28
29
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30







+







#include "config.h"

#import "OFMessagePackExtension.h"
#import "OFData.h"
#import "OFString.h"

#import "OFInvalidArgumentException.h"
#import "OFOutOfRangeException.h"

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

+ (instancetype)extensionWithType: (int8_t)type data: (OFData *)data
{
	return [[[self alloc] initWithType: type data: data] autorelease];
96
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
134
135
136
137
138
139


140
141
142
143
144
145
146
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
134
135
136
137
138
139

140
141
142
143
144
145
146
147
148







-
+











-
+











-
+











-
+
+







	} else if (count == 16) {
		ret = [OFMutableData dataWithCapacity: 18];

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

		[ret addItem: &_type];
	} else if (count < 0x100) {
	} else if (count <= UINT8_MAX) {
		uint8_t length;

		ret = [OFMutableData dataWithCapacity: count + 3];

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

		length = (uint8_t)count;
		[ret addItem: &length];

		[ret addItem: &_type];
	} else if (count < 0x10000) {
	} else if (count <= UINT16_MAX) {
		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 {
	} else if (count <= UINT32_MAX) {
		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];
	}
	} else
		@throw [OFOutOfRangeException exception];

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

	return ret;
}