static DiscreteResources of(Set<DiscreteResource> resources) {
        if (resources.isEmpty()) {
            return DiscreteResources.empty();
        }

        DiscreteResource parent = resources.iterator().next().parent().get();
        return of(parent, resources);
    }
@Test
    public void testPortSerialize() {
        DiscreteResource device = Resources.discrete(DeviceId.deviceId("a")).resource();
        Set<DiscreteResource> resources = IntStream.range(0, 100)
                .mapToObj(PortNumber::portNumber)
                .map(device::child)
                .collect(Collectors.toSet());

        DiscreteResources original = EncodableDiscreteResources.of(resources);

        byte[] bytes = serializer.encode(original);
        DiscreteResources decoded = serializer.decode(bytes);
        assertThat(decoded, is(original));
    }