private void Parse(byte[] contents) { if (contents.Length <= 17) { throw new ArgumentOutOfRangeException("contents", string.Format("length mismatch - expected at least 17, got {0} - {1}", contents.Length.ToString(), BitConverter.ToString(contents))); } byte messageId = contents[14]; int messageLength = 0; messageLength |= (contents[15] & 0xFF) << 8; messageLength |= contents[16] & 0xFF; int messageBodyLength = messageLength - 7; byte[] messageBody = new byte[messageBodyLength]; Array.Copy(contents, 24, messageBody, 0, messageBodyLength); if ((MessageId)messageId == MessageId.InventoryResponse) { if (messageBody.Length > 0) { InventoryType inventoryType = (InventoryType)messageBody[0]; if (inventoryType == InventoryType.ListActiveSuId) { KmmBody kmmBody = new InventoryResponseListActiveSuId(messageBody); KmmBody = kmmBody; } else { throw new Exception(string.Format("unknown inventory response type: 0x{0:X2}", (byte)inventoryType)); } } else { throw new Exception("inventory response length zero"); } } else if ((MessageId)messageId == MessageId.NegativeAcknowledgement) { KmmBody kmmBody = new NegativeAcknowledgement(messageBody); KmmBody = kmmBody; } else if ((MessageId)messageId == MessageId.LoadAuthenticationKeyResponse) { KmmBody kmmBody = new LoadAuthenticationKeyResponse(messageBody); KmmBody = kmmBody; } else if ((MessageId)messageId == MessageId.DeleteAuthenticationKeyResponse) { KmmBody kmmBody = new DeleteAuthenticationKeyResponse(messageBody); KmmBody = kmmBody; } else { throw new Exception(string.Format("unknown kmm - message id: 0x{0:X2}", messageId)); } }
public KmmFrame(KmmBody kmmBody) { if (kmmBody == null) { throw new ArgumentNullException("kmmBody"); } KmmBody = kmmBody; }