List of usage examples for io.netty.handler.codec.dns DefaultDnsRecordDecoder decodeName
public static String decodeName(ByteBuf in)
From source file:com.linecorp.armeria.client.endpoint.dns.DnsServiceEndpointGroup.java
License:Apache License
@Override ImmutableSortedSet<Endpoint> onDnsRecords(List<DnsRecord> records, int ttl) throws Exception { final ImmutableSortedSet.Builder<Endpoint> builder = ImmutableSortedSet.naturalOrder(); for (DnsRecord r : records) { if (!(r instanceof DnsRawRecord) || r.type() != DnsRecordType.SRV) { continue; }/*from w ww . j av a2 s.com*/ final ByteBuf content = ((ByteBufHolder) r).content(); if (content.readableBytes() <= 6) { // Too few bytes warnInvalidRecord(DnsRecordType.SRV, content); continue; } content.markReaderIndex(); content.skipBytes(2); // priority unused final int weight = content.readUnsignedShort(); final int port = content.readUnsignedShort(); final Endpoint endpoint; try { final String target = stripTrailingDot(DefaultDnsRecordDecoder.decodeName(content)); endpoint = port > 0 ? Endpoint.of(target, port) : Endpoint.of(target); } catch (Exception e) { content.resetReaderIndex(); warnInvalidRecord(DnsRecordType.SRV, content); continue; } builder.add(endpoint.withWeight(weight)); } final ImmutableSortedSet<Endpoint> endpoints = builder.build(); if (logger().isDebugEnabled()) { logger().debug("{} Resolved: {} (TTL: {})", logPrefix(), endpoints.stream().map(e -> e.authority() + '/' + e.weight()).collect(Collectors.joining(", ")), ttl); } return endpoints; }