| 220 | } |
| 221 | |
| 222 | UCHAR ClumpletReader::getBufferTag() const |
| 223 | { |
| 224 | const UCHAR* const buffer_end = getBufferEnd(); |
| 225 | const UCHAR* buffer_start = getBuffer(); |
| 226 | |
| 227 | switch (kind) |
| 228 | { |
| 229 | case Tpb: |
| 230 | case Tagged: |
| 231 | case WideTagged: |
| 232 | if (buffer_end - buffer_start == 0) |
| 233 | { |
| 234 | invalid_structure("empty buffer"); |
| 235 | return 0; |
| 236 | } |
| 237 | return buffer_start[0]; |
| 238 | case SpbStart: |
| 239 | case UnTagged: |
| 240 | case WideUnTagged: |
| 241 | case SpbSendItems: |
| 242 | case SpbReceiveItems: |
| 243 | case SpbResponse: |
| 244 | case InfoResponse: |
| 245 | case InfoItems: |
| 246 | usage_mistake("buffer is not tagged"); |
| 247 | return 0; |
| 248 | case SpbAttach: |
| 249 | if (buffer_end - buffer_start == 0) |
| 250 | { |
| 251 | invalid_structure("empty buffer"); |
| 252 | return 0; |
| 253 | } |
| 254 | switch (buffer_start[0]) |
| 255 | { |
| 256 | case isc_spb_version1: |
| 257 | // This is old SPB format, it's almost like DPB - |
| 258 | // buffer's tag is the first byte. |
| 259 | return buffer_start[0]; |
| 260 | case isc_spb_version: |
| 261 | // Buffer's tag is the second byte |
| 262 | if (buffer_end - buffer_start == 1) |
| 263 | { |
| 264 | invalid_structure("buffer too short", 1); |
| 265 | return 0; |
| 266 | } |
| 267 | return buffer_start[1]; |
| 268 | case isc_spb_version3: |
| 269 | // This is wide SPB attach format - buffer's tag is the first byte. |
| 270 | return buffer_start[0]; |
| 271 | default: |
| 272 | invalid_structure("spb in service attach should begin with isc_spb_version1 or isc_spb_version", buffer_start[0]); |
| 273 | return 0; |
| 274 | } |
| 275 | default: |
| 276 | fb_assert(false); |
| 277 | return 0; |
| 278 | } |
| 279 | } |
no test coverage detected