1 /*
2  * %CopyrightBegin%
3  *
4  * Copyright Ericsson AB 1998-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 #include <string.h>
21 #include "eidef.h"
22 #include "eiext.h"
23 #include "putget.h"
24 
ei_encode_port(char * buf,int * index,const erlang_port * p)25 int ei_encode_port(char *buf, int *index, const erlang_port *p)
26 {
27   char *s = buf + *index;
28 
29   ++(*index); /* skip ERL_PORT_EXT */
30   if (ei_encode_atom_len_as(buf, index, p->node, strlen(p->node), ERLANG_UTF8,
31 			    ERLANG_LATIN1|ERLANG_UTF8) < 0) {
32       return -1;
33   }
34   if (buf) {
35     put8(s, ERL_NEW_PORT_EXT);
36 
37     s = buf + *index;
38 
39     /* now the integers */
40     put32be(s,p->id & 0x0fffffff /* 28 bits */);
41     put32be(s, p->creation);
42   }
43   *index += 4 + 4;
44   return 0;
45 }
46 
47