@@ -16,7 +16,7 @@ public class SecurityQueryPayload {
1616 private SecurityQueryID _securityQueryID ;
1717 private int _correlationID ;
1818 private int _jsonSize ;
19- private SecurityQueryErrorCode _errorCode ;
19+ private int _bulkDataSize ;
2020
2121 private byte [] _jsonData = null ;
2222 private byte [] _bulkData = null ;
@@ -51,11 +51,6 @@ public static SecurityQueryPayload parseBinaryQueryHeader(byte[] binHeader) {
5151 int _jsonSize = BitConverter .intFromByteArray (binHeader , 8 );
5252 msg .setJsonSize (_jsonSize );
5353
54- //If we get an error message we want the error code from the last 8 bits
55- if (msg .getQueryType () == SecurityQueryType .NOTIFICATION && msg .getQueryID () == SecurityQueryID .SEND_INTERNAL_ERROR ) {
56- msg .setErrorCode (SecurityQueryErrorCode .valueOf (binHeader [binHeader .length - 1 ]));
57- }
58-
5954 try {
6055 //Get the JsonData after the header (after 96 bits) based on the jsonData size
6156 if (_jsonSize > 0 && _jsonSize <= (binHeader .length - SECURITY_QUERY_HEADER_SIZE )) {
@@ -84,40 +79,28 @@ public static SecurityQueryPayload parseBinaryQueryHeader(byte[] binHeader) {
8479 return msg ;
8580 }
8681
87- public byte [] assembleSecurityQueryPayload (int payloadSize ) {
88- byte [] payLoad = new byte [SECURITY_QUERY_HEADER_SIZE ];
89- if (_securityQueryID == SecurityQueryID .SEND_INTERNAL_ERROR && _securityQueryType == SecurityQueryType .NOTIFICATION ) {
90- payLoad = new byte [SECURITY_QUERY_HEADER_SIZE + payloadSize + 1 ];
91- System .arraycopy (_jsonData , 0 , payLoad , SECURITY_QUERY_HEADER_SIZE , _jsonSize );
92- byte [] errorCode = new byte [1 ];
93- if (this ._errorCode != null ) {
94- errorCode [0 ] = _errorCode .getValue ();
95- } else {
96- errorCode [0 ] = SecurityQueryErrorCode .ERROR_UNKNOWN_INTERNAL_ERROR .getValue ();
97- }
98- System .arraycopy (errorCode , 0 , payLoad , payLoad .length - 1 , 1 );
99- } else if (_securityQueryID == SecurityQueryID .SEND_HANDSHAKE_DATA && _securityQueryType == SecurityQueryType .RESPONSE ) {
100- payLoad = new byte [SECURITY_QUERY_HEADER_SIZE + payloadSize ];
101- System .arraycopy (_bulkData , 0 , payLoad , SECURITY_QUERY_HEADER_SIZE , payloadSize );
102- }
103-
104- System .arraycopy (assembleHeaderBytes (), 0 , payLoad , 0 , SECURITY_QUERY_HEADER_SIZE );
105-
106- return payLoad ;
107- }
108-
109- private byte [] assembleHeaderBytes () {
82+ public byte [] assembleBinaryData () {
11083 // From the properties, create a data buffer
11184 // Query Type - first 8 bits
11285 // Query ID - next 24 bits
11386 // Sequence Number - next 32 bits
11487 // JSON size - next 32 bits
115- byte [] ret = new byte [SECURITY_QUERY_HEADER_SIZE ];
116- ret [0 ] = _securityQueryType .getValue ();
117- System .arraycopy (_securityQueryID .getValue (), 0 , ret , 1 , 3 );
118- System .arraycopy (BitConverter .intToByteArray (_correlationID ), 0 , ret , 4 , 4 );
119- System .arraycopy (BitConverter .intToByteArray (_jsonSize ), 0 , ret , 8 , 4 );
120- return ret ;
88+ byte [] header = new byte [SECURITY_QUERY_HEADER_SIZE ];
89+ header [0 ] = _securityQueryType .getValue ();
90+ System .arraycopy (_securityQueryID .getValue (), 0 , header , 1 , 3 );
91+ System .arraycopy (BitConverter .intToByteArray (_correlationID ), 0 , header , 4 , 4 );
92+ System .arraycopy (BitConverter .intToByteArray (_jsonSize ), 0 , header , 8 , 4 );
93+
94+ int size = _jsonSize + _bulkDataSize + SECURITY_QUERY_HEADER_SIZE ;
95+ byte [] dataOut = new byte [size ];
96+ System .arraycopy (header , 0 , dataOut , 0 , SECURITY_QUERY_HEADER_SIZE );
97+ if (_jsonData != null ) {
98+ System .arraycopy (_jsonData , 0 , dataOut , SECURITY_QUERY_HEADER_SIZE , _jsonSize );
99+ }
100+ if (_bulkData != null ) {
101+ System .arraycopy (_bulkData , 0 , dataOut , SECURITY_QUERY_HEADER_SIZE + _jsonSize , _bulkDataSize );
102+ }
103+ return dataOut ;
121104 }
122105
123106 public SecurityQueryType getQueryType () {
@@ -152,12 +135,12 @@ private void setJsonSize(int _jsonSize) {
152135 this ._jsonSize = _jsonSize ;
153136 }
154137
155- public SecurityQueryErrorCode getErrorCode () {
156- return _errorCode ;
138+ public int getBulkDataSize () {
139+ return _bulkDataSize ;
157140 }
158141
159- public void setErrorCode ( SecurityQueryErrorCode _errorCode ) {
160- this ._errorCode = _errorCode ;
142+ private void setBulkDataSize ( int _bulkDataSize ) {
143+ this ._bulkDataSize = _bulkDataSize ;
161144 }
162145
163146 public byte [] getJsonData () {
@@ -180,6 +163,13 @@ public byte[] getBulkData() {
180163 }
181164
182165 public void setBulkData (byte [] _bulkData ) {
183- this ._bulkData = _bulkData ;
166+ if (_bulkData == null ) {
167+ this ._bulkDataSize = 0 ;
168+ this ._bulkData = null ;
169+ return ;
170+ }
171+ this ._bulkDataSize = _bulkData .length ;
172+ this ._bulkData = new byte [this ._bulkDataSize ];
173+ System .arraycopy (_bulkData , 0 , this ._bulkData , 0 , _bulkDataSize );
184174 }
185175}
0 commit comments