1 /*
2 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2005 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * $COPYRIGHT$
13 *
14 * Additional copyrights may follow
15 *
16 * $HEADER$
17 */
18
19 #include "opal_config.h"
20
21 #include "opal/dss/dss_internal.h"
22
23 int opal_dss_peek(opal_buffer_t *buffer, opal_data_type_t *type,
24 int32_t *num_vals)
25 {
26 int ret;
27 opal_buffer_t tmp;
28 int32_t n=1;
29 opal_data_type_t local_type;
30
31 /* check for errors */
32 if (buffer == NULL) {
33 return OPAL_ERR_BAD_PARAM;
34 }
35
36 /* Double check and ensure that there is data left in the buffer. */
37
38 if (buffer->unpack_ptr >= buffer->base_ptr + buffer->bytes_used) {
39 *type = OPAL_NULL;
40 *num_vals = 0;
41 return OPAL_ERR_UNPACK_READ_PAST_END_OF_BUFFER;
42 }
43
44 /* if this is NOT a fully described buffer, then that is as much as
45 * we can do - there is no way we can tell the caller what type is
46 * in the buffer since that info wasn't stored.
47 */
48 if (OPAL_DSS_BUFFER_FULLY_DESC != buffer->type) {
49 *type = OPAL_UNDEF;
50 *num_vals = 0;
51 return OPAL_ERR_UNKNOWN_DATA_TYPE;
52 }
53
54 /* cheat: unpack from a copy of the buffer -- leaving all the
55 original pointers intact */
56 tmp = *buffer;
57
58 if (OPAL_SUCCESS != (ret = opal_dss_get_data_type(&tmp, &local_type))) {
59 *type = OPAL_NULL;
60 *num_vals = 0;
61 return ret;
62 }
63 if (OPAL_INT32 != local_type) { /* if the length wasn't first, then error */
64 *type = OPAL_NULL;
65 *num_vals = 0;
66 return OPAL_ERR_UNPACK_FAILURE;
67 }
68 if (OPAL_SUCCESS != (ret = opal_dss_unpack_int32(&tmp, num_vals, &n, OPAL_INT32))) {
69 *type = OPAL_NULL;
70 *num_vals = 0;
71 return ret;
72 }
73 if (OPAL_SUCCESS != (ret = opal_dss_get_data_type(&tmp, type))) {
74 *type = OPAL_NULL;
75 *num_vals = 0;
76 }
77
78 return ret;
79 }
80
81 int opal_dss_peek_type(opal_buffer_t *buffer, opal_data_type_t *type)
82 {
83 int ret;
84 opal_buffer_t tmp;
85
86 /* check for errors */
87 if (buffer == NULL) {
88 return OPAL_ERR_BAD_PARAM;
89 }
90
91 /* if this is NOT a fully described buffer, then there isn't anything
92 * we can do - there is no way we can tell the caller what type is
93 * in the buffer since that info wasn't stored.
94 */
95 if (OPAL_DSS_BUFFER_FULLY_DESC != buffer->type) {
96 *type = OPAL_UNDEF;
97 return OPAL_ERR_UNKNOWN_DATA_TYPE;
98 }
99 /* Double check and ensure that there is data left in the buffer. */
100
101 if (buffer->unpack_ptr >= buffer->base_ptr + buffer->bytes_used) {
102 *type = OPAL_UNDEF;
103 return OPAL_ERR_UNPACK_READ_PAST_END_OF_BUFFER;
104 }
105
106 /* cheat: unpack from a copy of the buffer -- leaving all the
107 original pointers intact */
108 tmp = *buffer;
109
110 if (OPAL_SUCCESS != (ret = opal_dss_get_data_type(&tmp, type))) {
111 *type = OPAL_UNDEF;
112 return ret;
113 }
114
115 return OPAL_SUCCESS;
116 }