aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ic/java_src/com/ericsson/otp/ic/TermHelper.java
blob: 1a6271d9c03898a6daa9bc08c9020410657e6fd1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * %CopyrightBegin%
 * 
 * Copyright Ericsson AB 1999-2016. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * %CopyrightEnd%
 *
 */
package com.ericsson.otp.ic;
 
/**
  Helper class for Term.
  **/

public class TermHelper {

   // Constructors
   private TermHelper() {}
 
   // Methods
  /**
    Marshal method for the Term class, encodes the Term object to the output stream.
    **/
   public static void marshal(com.ericsson.otp.erlang.OtpOutputStream _out, Term _any)
     throws java.lang.Exception {
             
       _any.write_value(_out);
   }

  /**
    Unmarshal method for the Term class, decodes a Term object from the stream.
    @return Term, read from the input stream
    **/
  public static Term unmarshal(com.ericsson.otp.erlang.OtpInputStream _in)
    throws java.lang.Exception {

      Term _value = new Term();
      
      int tag = _in.peek();
      if (tag == com.ericsson.otp.erlang.OtpExternal.versionTag) {
	_in.read1();
	tag = _in.peek();      
      }    
      _value.tag = tag;


      // Allways save the object in OtpErlangObject form
      _in.mark(0);
      com.ericsson.otp.erlang.OtpErlangObject _obj = _in.read_any();
      _value.insert_Object(_obj);
      
      switch (tag) {
      case com.ericsson.otp.erlang.OtpExternal.smallIntTag:
      case com.ericsson.otp.erlang.OtpExternal.intTag:
      case com.ericsson.otp.erlang.OtpExternal.smallBigTag:
	_in.reset();
	_value.longV = _in.read_long();
	break;

      case com.ericsson.otp.erlang.OtpExternal.atomTag:
      case com.ericsson.otp.erlang.OtpExternal.atomUtf8Tag:
      case com.ericsson.otp.erlang.OtpExternal.smallAtomUtf8Tag:
	_in.reset();
	_value.atomV = _in.read_atom();
	break;

      case com.ericsson.otp.erlang.OtpExternal.floatTag:
	_in.reset();
	_value.doubleV = _in.read_double();
	break;

      case com.ericsson.otp.erlang.OtpExternal.refTag:
      case com.ericsson.otp.erlang.OtpExternal.newRefTag:
	_in.reset();
	com.ericsson.otp.erlang.OtpErlangRef _eref = 
	  _in.read_ref();  
	
	if (_eref.isNewRef())
	  _value.RefV = new Ref(_eref.node(),_eref.ids(),_eref.creation());
	else
	  _value.RefV = new Ref(_eref.node(),_eref.id(),_eref.creation());      

	break;

      case com.ericsson.otp.erlang.OtpExternal.portTag:
	_in.reset();
	com.ericsson.otp.erlang.OtpErlangPort _eport = 
	  _in.read_port(); 
	
	_value.PortV = new Port(_eport.node(),_eport.id(),_eport.creation());  
	break;

      case com.ericsson.otp.erlang.OtpExternal.pidTag:
	_in.reset();
	com.ericsson.otp.erlang.OtpErlangPid _epid = 
	  _in.read_pid(); 
	
	_value.PidV = new Pid(_epid.node(),_epid.id(),_epid.serial(),_epid.creation());  
	break;

      case com.ericsson.otp.erlang.OtpExternal.stringTag:
	_in.reset();
	_value.stringV = _in.read_string();
	break;

      case com.ericsson.otp.erlang.OtpExternal.listTag:
      case com.ericsson.otp.erlang.OtpExternal.nilTag:
      case com.ericsson.otp.erlang.OtpExternal.smallTupleTag:
      case com.ericsson.otp.erlang.OtpExternal.largeTupleTag:
      case com.ericsson.otp.erlang.OtpExternal.binTag:

	com.ericsson.otp.erlang.OtpOutputStream _os = 
	  new com.ericsson.otp.erlang.OtpOutputStream();

	_obj.encode(_os);
	_value.insert_Streamable(_os);
	break;
	
      case com.ericsson.otp.erlang.OtpExternal.largeBigTag:
      default:
	throw new com.ericsson.otp.erlang.OtpErlangDecodeException("Uknown data type: " + tag);
      }
      
      return _value;
  }
  
}