@Override public String bytesToUtf8String(byte[] rawData) throws AvpDataException { try { return new String(rawData, "utf8"); } catch (UnsupportedEncodingException e) { throw new AvpDataException("Invalid data type", e); } }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) { logger.debug("Decode message size: {}", in.readableBytes()); if (in.readableBytes() >= 4) { int first = in.getInt(in.readerIndex()); byte version = (byte) (first >> 24); if (version != 1) { return; } int messageLength = (first & 0xFFFFFF); if (in.readableBytes() < messageLength) { return; } logger.debug("Decoding message version: {}, length: {}", version, messageLength); byte[] bytes = new byte[messageLength]; in.readBytes(bytes); try { out.add(this.parser.createMessage(bytes)); } catch (AvpDataException e) { logger.error(e.getMessage(), e); this.parentConnection.onAvpDataException(e); } } } }
@Override public String bytesToOctetString(byte[] rawData) throws AvpDataException { try { return new String(rawData, "iso-8859-1"); } catch (UnsupportedEncodingException e) { throw new AvpDataException("Invalid data type", e); } }
protected ByteBuffer prepareBuffer(byte [] bytes, int len) throws AvpDataException { if (bytes.length != len) { throw new AvpDataException("Incorrect data length"); } return ByteBuffer.wrap(bytes); }
@Override public InetAddress bytesToAddress(byte[] rawData) throws AvpDataException { InetAddress inetAddress; try { boolean isIPv6 = rawData[INT_INET4] != INT_INET4; byte[] address = new byte[isIPv6 ? 16 : 4]; System.arraycopy(rawData, 2, address, 0, address.length); inetAddress = isIPv6 ? InetAddress.getByAddress(address) : InetAddress.getByAddress(address); } catch (Exception e) { throw new AvpDataException(e); } return inetAddress; }
@Override public int getInteger32() throws AvpDataException { try { return parser.bytesToInt(rawData); } catch (Exception e) { throw new AvpDataException(e, this); } }
@Override public Date bytesToDate(byte[] rawData) throws AvpDataException { try { byte[] tmp = new byte[8]; System.arraycopy(rawData, 0 , tmp, 4, 4); return new Date(((bytesToLong(tmp) - SECOND_SHIFT) * 1000L)); } catch (Exception e) { throw new AvpDataException(e); } }
@Override public String getUTF8String() throws AvpDataException { try { return parser.bytesToUtf8String(rawData); } catch (Exception e) { throw new AvpDataException(e, this); } }
@Override public long getUnsigned32() throws AvpDataException { try { byte[] u32ext = new byte[8]; System.arraycopy(rawData, 0, u32ext, 4, 4); return parser.bytesToLong(u32ext); } catch (Exception e) { throw new AvpDataException(e, this); } }
@Override public long getUnsigned64() throws AvpDataException { try { return parser.bytesToLong(rawData); } catch (Exception e) { throw new AvpDataException(e, this); } }
@Override public Date getTime() throws AvpDataException { try { return parser.bytesToDate(rawData); } catch (Exception e) { throw new AvpDataException(e, this); } }
@Override public String getDiameterIdentity() throws AvpDataException { try { return parser.bytesToOctetString(rawData); } catch (Exception e) { throw new AvpDataException(e, this); } }
@Override public URI getDiameterURI() throws AvpDataException { try { return new URI(parser.bytesToOctetString(rawData)); } catch (URISyntaxException e) { throw new AvpDataException(e, this); } catch (UnknownServiceException e) { throw new AvpDataException(e, this); } }
@Override public long getInteger64() throws AvpDataException { try { return parser.bytesToLong(rawData); } catch (Exception e) { throw new AvpDataException(e, this); } }
@Override public float getFloat32() throws AvpDataException { try { return parser.bytesToFloat(rawData); } catch (Exception e) { throw new AvpDataException(e, this); } }
@Override public double getFloat64() throws AvpDataException { try { return parser.bytesToDouble(rawData); } catch (Exception e) { throw new AvpDataException(e, this); } }
@Override public InetAddress getAddress() throws AvpDataException { try { return parser.bytesToAddress(rawData); } catch (Exception e) { throw new AvpDataException(e, this); } }
@Override public AvpSet getGrouped() throws AvpDataException { try { if (groupedData == null) { groupedData = parser.decodeAvpSet(rawData); rawData = new byte[0]; } return groupedData; } catch (Exception e) { throw new AvpDataException(e, this); } }
throw new AvpDataException(exc);