@Test public void ethernetCodecTest() { final CodecContext context = new MockCodecContext(); final JsonCodec<Ethernet> ethernetCodec = context.codec(Ethernet.class); assertThat(ethernetCodec, notNullValue()); final Ethernet eth1 = new Ethernet(); eth1.setSourceMACAddress("11:22:33:44:55:01"); eth1.setDestinationMACAddress("11:22:33:44:55:02"); eth1.setPad(true); eth1.setEtherType(Ethernet.TYPE_ARP); eth1.setPriorityCode((byte) 7); eth1.setVlanID((short) 33); final ObjectNode eth1Json = ethernetCodec.encode(eth1, context); assertThat(eth1Json, notNullValue()); assertThat(eth1Json, matchesEthernet(eth1)); }
@Override public ObjectNode encode(Ethernet ethernet, CodecContext context) { checkNotNull(ethernet, "Ethernet cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put("vlanId", ethernet.getVlanID()) .put("etherType", ethernet.getEtherType()) .put("priorityCode", ethernet.getPriorityCode()) .put("pad", ethernet.isPad()); if (ethernet.getDestinationMAC() != null) { result.put("destMac", ethernet.getDestinationMAC().toString()); } if (ethernet.getSourceMAC() != null) { result.put("srcMac", ethernet.getSourceMAC().toString()); } return result; }
EthernetCodec extends JsonCodec<Ethernet> { @Override public ObjectNode encode(Ethernet ethernet, CodecContext context) { checkNotNull(ethernet, "Ethernet cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put("vlanId", ethernet.getVlanID()) .put("etherType", ethernet.getEtherType()) .put("priorityCode", ethernet.getPriorityCode()) .put("pad", ethernet.isPad()); if (ethernet.getDestinationMAC() != null) { result.put("destMac", ethernet.getDestinationMAC().toString()); } if (ethernet.getSourceMAC() != null) { result.put("srcMac", ethernet.getSourceMAC().toString()); } return result; } }
EthernetCodec extends JsonCodec<Ethernet> { @Override public ObjectNode encode(Ethernet ethernet, CodecContext context) { checkNotNull(ethernet, "Ethernet cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put("vlanId", ethernet.getVlanID()) .put("etherType", ethernet.getEtherType()) .put("priorityCode", ethernet.getPriorityCode()) .put("pad", ethernet.isPad()); if (ethernet.getDestinationMAC() != null) { result.put("destMac", ethernet.getDestinationMAC().toString()); } if (ethernet.getSourceMAC() != null) { result.put("srcMac", ethernet.getSourceMAC().toString()); } return result; }  }
EthernetCodec extends JsonCodec<Ethernet> { @Override public ObjectNode encode(Ethernet ethernet, CodecContext context) { checkNotNull(ethernet, "Ethernet cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put("vlanId", ethernet.getVlanID()) .put("etherType", ethernet.getEtherType()) .put("priorityCode", ethernet.getPriorityCode()) .put("pad", ethernet.isPad()); if (ethernet.getDestinationMAC() != null) { result.put("destMac", ethernet.getDestinationMAC().toString()); } if (ethernet.getSourceMAC() != null) { result.put("srcMac", ethernet.getSourceMAC().toString()); } return result; }  @Override ObjectNode encode(Ethernet ethernet, CodecContext context); }
EthernetCodec extends JsonCodec<Ethernet> { @Override public ObjectNode encode(Ethernet ethernet, CodecContext context) { checkNotNull(ethernet, "Ethernet cannot be null"); final ObjectNode result = context.mapper().createObjectNode() .put("vlanId", ethernet.getVlanID()) .put("etherType", ethernet.getEtherType()) .put("priorityCode", ethernet.getPriorityCode()) .put("pad", ethernet.isPad()); if (ethernet.getDestinationMAC() != null) { result.put("destMac", ethernet.getDestinationMAC().toString()); } if (ethernet.getSourceMAC() != null) { result.put("srcMac", ethernet.getSourceMAC().toString()); } return result; }  @Override ObjectNode encode(Ethernet ethernet, CodecContext context);  }