1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
/*
* Copyright (c) 2017 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*/
#include <config.h>
#include <stdio.h>
#include <parc/algol/parc_Object.h>
#include <parc/algol/parc_Buffer.h>
#include <parc/algol/parc_ReadOnlyBuffer.h>
#include <parc/algol/parc_DisplayIndented.h>
struct parc_readonly_buffer {
PARCBuffer *buffer;
};
static void
_readOnlyBuffer_Finalize(PARCReadOnlyBuffer **bufferPtr)
{
PARCReadOnlyBuffer *buffer = *bufferPtr;
parcBuffer_Release(&buffer->buffer);
}
parcObject_ExtendPARCObject(PARCReadOnlyBuffer, _readOnlyBuffer_Finalize, parcReadOnlyBuffer_Copy,
parcReadOnlyBuffer_ToString, parcReadOnlyBuffer_Equals, NULL, parcReadOnlyBuffer_HashCode, NULL);
PARCReadOnlyBuffer *
parcReadOnlyBuffer_Create(PARCBuffer *buffer)
{
PARCReadOnlyBuffer *result = NULL;
if (buffer != NULL) {
result = parcObject_CreateInstance(PARCReadOnlyBuffer);
if (result != NULL) {
result->buffer = parcBuffer_WrapByteArray(parcBuffer_Array(buffer), parcBuffer_Position(buffer), parcBuffer_Limit(buffer));
}
}
return result;
}
PARCReadOnlyBuffer *
parcReadOnlyBuffer_Wrap(uint8_t *array, size_t arrayLength, size_t position, size_t limit)
{
PARCReadOnlyBuffer *result = parcObject_CreateInstance(PARCReadOnlyBuffer);
if (result != NULL) {
result->buffer = parcBuffer_Wrap(array, arrayLength, position, limit);
}
return result;
}
parcObject_ImplementAcquire(parcReadOnlyBuffer, PARCReadOnlyBuffer);
parcObject_ImplementRelease(parcReadOnlyBuffer, PARCReadOnlyBuffer);
size_t
parcReadOnlyBuffer_Capacity(const PARCReadOnlyBuffer *buffer)
{
return parcBuffer_Capacity(buffer->buffer);
}
PARCReadOnlyBuffer *
parcReadOnlyBuffer_Clear(PARCReadOnlyBuffer *buffer)
{
parcBuffer_Clear(buffer->buffer);
return buffer;
}
bool
parcReadOnlyBuffer_Equals(const PARCReadOnlyBuffer *x, const PARCReadOnlyBuffer *y)
{
if (x == y) {
return true;
}
if (x == NULL || y == NULL) {
return false;
}
return parcBuffer_Equals(x->buffer, y->buffer);
}
PARCByteArray *
parcReadOnlyBuffer_Array(const PARCReadOnlyBuffer *buffer)
{
return parcBuffer_Array(buffer->buffer);
}
PARCReadOnlyBuffer *
parcReadOnlyBuffer_Copy(const PARCReadOnlyBuffer *original)
{
PARCReadOnlyBuffer *result = parcObject_CreateInstance(PARCReadOnlyBuffer);
if (result != NULL) {
result->buffer = parcBuffer_Copy(original->buffer);
}
return result;
}
size_t
parcReadOnlyBuffer_ArrayOffset(const PARCReadOnlyBuffer *buffer)
{
return parcBuffer_ArrayOffset(buffer->buffer);
}
PARCReadOnlyBuffer *
parcReadOnlyBuffer_Rewind(PARCReadOnlyBuffer *buffer)
{
parcBuffer_Rewind(buffer->buffer);
return buffer;
}
PARCReadOnlyBuffer *
parcReadOnlyBuffer_Reset(PARCReadOnlyBuffer *buffer)
{
parcBuffer_Reset(buffer->buffer);
return buffer;
}
size_t
parcReadOnlyBuffer_Limit(const PARCReadOnlyBuffer *buffer)
{
return parcBuffer_Limit(buffer->buffer);
}
PARCReadOnlyBuffer *
parcReadOnlyBuffer_Mark(PARCReadOnlyBuffer *buffer)
{
parcBuffer_Mark(buffer->buffer);
return buffer;
}
PARCReadOnlyBuffer *
parcReadOnlyBuffer_SetLimit(PARCReadOnlyBuffer *buffer, size_t newLimit)
{
parcBuffer_SetLimit(buffer->buffer, newLimit);
return buffer;
}
void *
parcReadOnlyBuffer_Overlay(PARCReadOnlyBuffer *buffer, size_t length)
{
return parcBuffer_Overlay(buffer->buffer, length);
}
size_t
parcReadOnlyBuffer_Position(const PARCReadOnlyBuffer *buffer)
{
return parcBuffer_Position(buffer->buffer);
}
PARCReadOnlyBuffer *
parcReadOnlyBuffer_SetPosition(PARCReadOnlyBuffer *buffer, size_t newPosition)
{
parcBuffer_SetPosition(buffer->buffer, newPosition);
return buffer;
}
size_t
parcReadOnlyBuffer_Remaining(const PARCReadOnlyBuffer *buffer)
{
return parcBuffer_Remaining(buffer->buffer);
}
bool
parcReadOnlyBuffer_HasRemaining(const PARCReadOnlyBuffer *buffer)
{
return parcBuffer_HasRemaining(buffer->buffer);
}
PARCReadOnlyBuffer *
parcReadOnlyBuffer_Flip(PARCReadOnlyBuffer *buffer)
{
parcBuffer_Flip(buffer->buffer);
return buffer;
}
uint8_t
parcReadOnlyBuffer_GetAtIndex(const PARCReadOnlyBuffer *buffer, size_t index)
{
return parcBuffer_GetAtIndex(buffer->buffer, index);
}
PARCReadOnlyBuffer *
parcReadOnlyBuffer_GetArray(PARCReadOnlyBuffer *buffer, uint8_t *array, size_t length)
{
parcBuffer_GetBytes(buffer->buffer, length, array);
return buffer;
}
uint8_t
parcReadOnlyBuffer_GetUint8(PARCReadOnlyBuffer *buffer)
{
return parcBuffer_GetUint8(buffer->buffer);
}
uint16_t
parcReadOnlyBuffer_GetUint16(PARCReadOnlyBuffer *buffer)
{
return parcBuffer_GetUint16(buffer->buffer);
}
uint32_t
parcReadOnlyBuffer_GetUint32(PARCReadOnlyBuffer *buffer)
{
return parcBuffer_GetUint32(buffer->buffer);
}
uint64_t
parcReadOnlyBuffer_GetUint64(PARCReadOnlyBuffer *buffer)
{
return parcBuffer_GetUint64(buffer->buffer);
}
PARCHashCode
parcReadOnlyBuffer_HashCode(const PARCReadOnlyBuffer *buffer)
{
return parcBuffer_HashCode(buffer->buffer);
}
char *
parcReadOnlyBuffer_ToString(const PARCReadOnlyBuffer *buffer)
{
return parcBuffer_ToString(buffer->buffer);
}
void
parcReadOnlyBuffer_Display(const PARCReadOnlyBuffer *buffer, int indentation)
{
parcDisplayIndented_PrintLine(indentation, "PARCReadOnlyBuffer@%p {\n", (void *) buffer);
parcBuffer_Display(buffer->buffer, indentation + 1);
parcDisplayIndented_PrintLine(indentation, "}\n");
}
|