All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.moaxcp.x11client.protocol.xproto.ListHostsReply Maven / Gradle / Ivy

There is a newer version: 0.18.2
Show newest version
package com.github.moaxcp.x11client.protocol.xproto;

import com.github.moaxcp.x11client.protocol.X11Input;
import com.github.moaxcp.x11client.protocol.X11Output;
import com.github.moaxcp.x11client.protocol.XObject;
import com.github.moaxcp.x11client.protocol.XReply;
import java.io.IOException;
import java.lang.Override;
import java.util.ArrayList;
import java.util.List;
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;

@Value
@Builder
public class ListHostsReply implements XReply {
  private byte mode;

  private short sequenceNumber;

  private short hostsLen;

  @NonNull
  private List hosts;

  public static ListHostsReply readListHostsReply(byte mode, short sequenceNumber, X11Input in)
      throws IOException {
    int length = in.readCard32();
    short hostsLen = in.readCard16();
    in.readPad(22);
    List hosts = new ArrayList<>(Short.toUnsignedInt(hostsLen));
    for(int i = 0; i < Short.toUnsignedInt(hostsLen); i++) {
      hosts.add(Host.readHost(in));
    }
    ListHostsReply.ListHostsReplyBuilder javaBuilder = ListHostsReply.builder();
    javaBuilder.mode(mode);
    javaBuilder.sequenceNumber(sequenceNumber);
    javaBuilder.hostsLen(hostsLen);
    javaBuilder.hosts(hosts);
    if(javaBuilder.getSize() < 32) {
      in.readPad(32 - javaBuilder.getSize());
    }
    return javaBuilder.build();
  }

  @Override
  public void write(X11Output out) throws IOException {
    out.writeCard8(getResponseCode());
    out.writeByte(mode);
    out.writeCard16(sequenceNumber);
    out.writeCard32(getLength());
    out.writeCard16(hostsLen);
    out.writePad(22);
    for(Host t : hosts) {
      t.write(out);
    }
    out.writePadAlign(getSize());
  }

  @Override
  public int getSize() {
    return 32 + XObject.sizeOf(hosts);
  }

  public static class ListHostsReplyBuilder {
    public ListHostsReply.ListHostsReplyBuilder mode(AccessControl mode) {
      this.mode = (byte) mode.getValue();
      return this;
    }

    public ListHostsReply.ListHostsReplyBuilder mode(byte mode) {
      this.mode = mode;
      return this;
    }

    public int getSize() {
      return 32 + XObject.sizeOf(hosts);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy