1 /*
2  * %CopyrightBegin%
3  *
4  * Copyright Ericsson AB 1998-2016. 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 #include "eidef.h"
21 #include "eiext.h"
22 #include "putget.h"
23 
ei_encode_tuple_header(char * buf,int * index,int arity)24 int ei_encode_tuple_header(char *buf, int *index, int arity)
25 {
26   char *s = buf + *index;
27   char *s0 = s;
28 
29   if (arity < 0) return -1;
30 
31   if (arity <= 0xff) {
32     if (!buf) s += 2;
33     else {
34       put8(s,ERL_SMALL_TUPLE_EXT);
35       put8(s,arity);
36     }
37   }
38   else {
39     if (!buf) s += 5;
40     else {
41       put8(s,ERL_LARGE_TUPLE_EXT);
42       put32be(s,arity);
43     }
44   }
45 
46   *index += s-s0;
47 
48   return 0;
49 }
50 
ei_encode_map_header(char * buf,int * index,int arity)51 int ei_encode_map_header(char *buf, int *index, int arity)
52 {
53   char *s = buf + *index;
54   char *s0 = s;
55 
56   if (arity < 0) return -1;
57 
58   if (!buf) s += 5;
59   else {
60       put8(s,ERL_MAP_EXT);
61       put32be(s,arity);
62   }
63 
64   *index += s-s0;
65 
66   return 0;
67 }
68