/** * Used by NetworkObject to decode the object from a network stream. * * @see org.ccnx.ccn.impl.encoding.XMLEncodable */ public void decode(XMLDecoder decoder) throws ContentDecodingException { decoder.readStartElement(getElementLabel()); if (decoder.peekStartElement(CCNProtocolDTags.Action)) { _action = decoder.readUTF8Element(CCNProtocolDTags.Action); } if (decoder.peekStartElement(CCNProtocolDTags.PublisherPublicKeyDigest)) { _ccndID = new PublisherPublicKeyDigest(); _ccndID.decode(decoder); } if (decoder.peekStartElement(CCNProtocolDTags.FaceID)) { _faceID = decoder.readIntegerElement(CCNProtocolDTags.FaceID); } if (decoder.peekStartElement(CCNProtocolDTags.IPProto)) { int pI = decoder.readIntegerElement(CCNProtocolDTags.IPProto); _ipProto = null; if (NetworkProtocol.TCP.value().intValue() == pI) { _ipProto = NetworkProtocol.TCP; } else if (NetworkProtocol.UDP.value().intValue() == pI) { _ipProto = NetworkProtocol.UDP; } else { throw new ContentDecodingException( "FaceInstance.decoder. Invalid " + CCNProtocolDTags.tagToString(CCNProtocolDTags.IPProto) + " field: " + pI); } } if (decoder.peekStartElement(CCNProtocolDTags.Host)) { _host = decoder.readUTF8Element(CCNProtocolDTags.Host); } if (decoder.peekStartElement(CCNProtocolDTags.Port)) { _port = decoder.readIntegerElement(CCNProtocolDTags.Port); } if (decoder.peekStartElement(CCNProtocolDTags.MulticastInterface)) { _multicastInterface = decoder.readUTF8Element(CCNProtocolDTags.MulticastInterface); } if (decoder.peekStartElement(CCNProtocolDTags.MulticastTTL)) { _multicastTTL = decoder.readIntegerElement(CCNProtocolDTags.MulticastTTL); } if (decoder.peekStartElement(CCNProtocolDTags.FreshnessSeconds)) { _lifetime = decoder.readIntegerElement(CCNProtocolDTags.FreshnessSeconds); } decoder.readEndElement(); }
@Test public void testTagMap() { Log.info(Log.FAC_TEST, "Starting testTagMap"); String name; Long tag; for (int i = 1; i <= CCNProtocolDTags.Parameters; ++i) { name = CCNProtocolDTags.tagToString(i); if (name != null) { tag = CCNProtocolDTags.stringToTag(name); Assert.assertEquals(tag.longValue(), i); } } name = CCNProtocolDTags.tagToString(CCNProtocolDTags.Interest); Assert.assertEquals("Interest", name); name = CCNProtocolDTags.tagToString(CCNProtocolDTags.RootDigest); Assert.assertEquals("RootDigest", name); name = CCNProtocolDTags.tagToString(CCNProtocolDTags.Nonce); Assert.assertEquals("Nonce", name); name = CCNProtocolDTags.tagToString(CCNProtocolDTags.AnswerOriginKind); Assert.assertEquals("AnswerOriginKind", name); name = CCNProtocolDTags.tagToString(CCNProtocolDTags.Witness); Assert.assertEquals("Witness", name); name = CCNProtocolDTags.tagToString(CCNProtocolDTags.FinalBlockID); Assert.assertEquals("FinalBlockID", name); name = CCNProtocolDTags.tagToString(CCNProtocolDTags.EncryptedKey); Assert.assertEquals("EncryptedKey", name); name = CCNProtocolDTags.tagToString(CCNProtocolDTags.BinaryValue); Assert.assertEquals("BinaryValue", name); name = CCNProtocolDTags.tagToString(CCNProtocolDTags.ProfileName); Assert.assertEquals("ProfileName", name); name = CCNProtocolDTags.tagToString(CCNProtocolDTags.Parameters); Assert.assertEquals("Parameters", name); Log.info(Log.FAC_TEST, "Completed testTagMap"); }