SDL_Android/SmartDeviceLinkAndroidProxy - added the correct version of the proxy
[profile/ivi/smartdevicelink.git] / SDL_Android / SmartDeviceLinkProxyAndroid / src / com / smartdevicelink / protocol / BinaryFrameHeader.java
1 package com.smartdevicelink.protocol;\r
2 \r
3 import com.smartdevicelink.util.BitConverter;\r
4 \r
5 public class BinaryFrameHeader {\r
6         private byte _rpcType;\r
7         private int _functionID;\r
8         private int _correlationID;\r
9         private int _jsonSize;\r
10         \r
11         private byte[] _jsonData;\r
12         private byte[] _bulkData;\r
13         \r
14         public BinaryFrameHeader() {}\r
15         \r
16         public static BinaryFrameHeader parseBinaryHeader(byte[] binHeader) {\r
17                 BinaryFrameHeader msg = new BinaryFrameHeader();\r
18                 \r
19                 byte RPC_Type = (byte) (binHeader[0] >>> 4);\r
20                 msg.setRPCType(RPC_Type);\r
21                 \r
22                 int _functionID = (BitConverter.intFromByteArray(binHeader, 0) & 0x0FFFFFFF);\r
23                 msg.setFunctionID(_functionID);\r
24                 \r
25                 int corrID = BitConverter.intFromByteArray(binHeader, 4);\r
26                 msg.setCorrID(corrID);\r
27                 \r
28                 int _jsonSize = BitConverter.intFromByteArray(binHeader, 8);\r
29                 msg.setJsonSize(_jsonSize);\r
30                 \r
31                 if (_jsonSize > 0) {\r
32                         byte[] _jsonData = new byte[_jsonSize];\r
33                         System.arraycopy(binHeader, 12, _jsonData, 0, _jsonSize);\r
34                         msg.setJsonData(_jsonData);\r
35                 }\r
36                 \r
37                 if (binHeader.length - _jsonSize - 12 > 0) {\r
38                         byte[] _bulkData = new byte[binHeader.length - _jsonSize - 12];\r
39                         System.arraycopy(binHeader, 12 + _jsonSize, _bulkData, 0, _bulkData.length);\r
40                         msg.setBulkData(_bulkData);\r
41                 }               \r
42                 \r
43                 return msg;\r
44         }\r
45         \r
46         protected byte[] assembleHeaderBytes() {\r
47                 int binHeader = _functionID;\r
48                 binHeader |= (_rpcType << 28);\r
49                 \r
50                 byte[] ret = new byte[12];\r
51                 System.arraycopy(BitConverter.intToByteArray(binHeader), 0, ret, 0, 4);\r
52                 System.arraycopy(BitConverter.intToByteArray(_correlationID), 0, ret, 4, 4);\r
53                 System.arraycopy(BitConverter.intToByteArray(_jsonSize), 0, ret, 8, 4);\r
54                 \r
55                 return ret;\r
56         }\r
57         \r
58         public byte getRPCType() {\r
59                 return _rpcType;\r
60         }\r
61 \r
62         public void setRPCType(byte _rpcType) {\r
63                 this._rpcType = _rpcType;\r
64         }\r
65 \r
66         public int getFunctionID() {\r
67                 return _functionID;\r
68         }\r
69 \r
70         public void setFunctionID(int _functionID) {\r
71                 this._functionID = _functionID;\r
72         }\r
73 \r
74         public int getCorrID() {\r
75                 return _correlationID;\r
76         }\r
77 \r
78         public void setCorrID(int _correlationID) {\r
79                 this._correlationID = _correlationID;\r
80         }\r
81 \r
82         public int getJsonSize() {\r
83                 return _jsonSize;\r
84         }\r
85 \r
86         public void setJsonSize(int _jsonSize) {\r
87                 this._jsonSize = _jsonSize;\r
88         }\r
89         \r
90         public byte[] getJsonData() {\r
91                 return _jsonData;\r
92         }\r
93         \r
94         public void setJsonData(byte[] _jsonData) {\r
95                 this._jsonData = new byte[this._jsonSize];\r
96                 System.arraycopy(_jsonData, 0, this._jsonData, 0, _jsonSize);\r
97                 //this._jsonData = _jsonData;\r
98         }\r
99         \r
100         public byte[] getBulkData() {\r
101                 return _bulkData;\r
102         }\r
103         \r
104         public void setBulkData(byte[] _bulkData) {\r
105                 this._bulkData = _bulkData;\r
106         }\r
107 }\r