1 package com.smartdevicelink.protocol;
\r
3 import com.smartdevicelink.util.BitConverter;
\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
11 private byte[] _jsonData;
\r
12 private byte[] _bulkData;
\r
14 public BinaryFrameHeader() {}
\r
16 public static BinaryFrameHeader parseBinaryHeader(byte[] binHeader) {
\r
17 BinaryFrameHeader msg = new BinaryFrameHeader();
\r
19 byte RPC_Type = (byte) (binHeader[0] >>> 4);
\r
20 msg.setRPCType(RPC_Type);
\r
22 int _functionID = (BitConverter.intFromByteArray(binHeader, 0) & 0x0FFFFFFF);
\r
23 msg.setFunctionID(_functionID);
\r
25 int corrID = BitConverter.intFromByteArray(binHeader, 4);
\r
26 msg.setCorrID(corrID);
\r
28 int _jsonSize = BitConverter.intFromByteArray(binHeader, 8);
\r
29 msg.setJsonSize(_jsonSize);
\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
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
46 protected byte[] assembleHeaderBytes() {
\r
47 int binHeader = _functionID;
\r
48 binHeader |= (_rpcType << 28);
\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
58 public byte getRPCType() {
\r
62 public void setRPCType(byte _rpcType) {
\r
63 this._rpcType = _rpcType;
\r
66 public int getFunctionID() {
\r
70 public void setFunctionID(int _functionID) {
\r
71 this._functionID = _functionID;
\r
74 public int getCorrID() {
\r
75 return _correlationID;
\r
78 public void setCorrID(int _correlationID) {
\r
79 this._correlationID = _correlationID;
\r
82 public int getJsonSize() {
\r
86 public void setJsonSize(int _jsonSize) {
\r
87 this._jsonSize = _jsonSize;
\r
90 public byte[] getJsonData() {
\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
100 public byte[] getBulkData() {
\r
104 public void setBulkData(byte[] _bulkData) {
\r
105 this._bulkData = _bulkData;
\r