1 /*
2 * %CopyrightBegin%
3 *
4 * Copyright Ericsson AB 2020-2020. All Rights Reserved.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * %CopyrightEnd%
19 *
20 */
21 #include <ic.h>
22
ic_get_type(const char * buf,const int * index,ic_erlang_type * ictype,int * len)23 int ic_get_type(const char *buf, const int *index, ic_erlang_type *ictype, int *len)
24 {
25 int retVal;
26 int type;
27
28 retVal = ei_get_type(buf, index, &type, len);
29 if(retVal)
30 return retVal;
31
32 switch(type) {
33
34 case ERL_SMALL_INTEGER_EXT:
35 case ERL_INTEGER_EXT:
36 case ERL_SMALL_BIG_EXT:
37 case ERL_LARGE_BIG_EXT:
38 *ictype = ic_integer;
39 break;
40
41 case ERL_FLOAT_EXT:
42 *ictype = ic_float;
43 break;
44
45 case ERL_ATOM_EXT:
46 *ictype = ic_atom;
47 break;
48
49 case ERL_STRING_EXT:
50 *ictype = ic_string;
51 break;
52
53 case ERL_PID_EXT:
54 *ictype = ic_pid;
55 break;
56
57 case ERL_PORT_EXT:
58 *ictype = ic_port;
59 break;
60
61 case ERL_NEW_REFERENCE_EXT:
62 *ictype = ic_ref;
63 break;
64
65 case ERL_SMALL_TUPLE_EXT:
66 case ERL_LARGE_TUPLE_EXT:
67 *ictype = ic_tuple;
68 break;
69
70 case ERL_NIL_EXT: /* List of length 0 */
71 case ERL_LIST_EXT:
72 *ictype = ic_list;
73 break;
74
75 case ERL_BINARY_EXT:
76 *ictype = ic_binary;
77 break;
78
79 default: /* ic term doesn't handle maps, bit binaries, funs ... */
80 retVal = -1;
81 break;
82 }
83
84 return retVal;
85 }
86