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

com.github.moaxcp.x11client.protocol.dri2.ConnectReply Maven / Gradle / Ivy

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

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

@Value
@Builder
public class ConnectReply implements XReply {
  private short sequenceNumber;

  @NonNull
  private List driverName;

  @NonNull
  private List alignmentPad;

  @NonNull
  private List deviceName;

  public static ConnectReply readConnectReply(byte pad, short sequenceNumber, X11Input in) throws
      IOException {
    int length = in.readCard32();
    int driverNameLength = in.readCard32();
    int deviceNameLength = in.readCard32();
    in.readPad(16);
    List driverName = in.readChar((int) (Integer.toUnsignedLong(driverNameLength)));
    List alignmentPad = in.readVoid((int) ((Integer.toUnsignedLong(driverNameLength) + 3) & (~ (3)) - Integer.toUnsignedLong(driverNameLength)));
    List deviceName = in.readChar((int) (Integer.toUnsignedLong(deviceNameLength)));
    ConnectReply.ConnectReplyBuilder javaBuilder = ConnectReply.builder();
    javaBuilder.sequenceNumber(sequenceNumber);
    javaBuilder.driverName(driverName);
    javaBuilder.alignmentPad(alignmentPad);
    javaBuilder.deviceName(deviceName);
    if(javaBuilder.getSize() < 32) {
      in.readPad(32 - javaBuilder.getSize());
    }
    return javaBuilder.build();
  }

  @Override
  public void write(X11Output out) throws IOException {
    out.writeCard8(getResponseCode());
    out.writePad(1);
    out.writeCard16(sequenceNumber);
    out.writeCard32(getLength());
    int driverNameLength = driverName.size();
    out.writeCard32(driverNameLength);
    int deviceNameLength = deviceName.size();
    out.writeCard32(deviceNameLength);
    out.writePad(16);
    out.writeChar(driverName);
    out.writeVoid(alignmentPad);
    out.writeChar(deviceName);
    out.writePadAlign(getSize());
  }

  @Override
  public int getSize() {
    return 32 + 1 * driverName.size() + 1 * alignmentPad.size() + 1 * deviceName.size();
  }

  public static class ConnectReplyBuilder {
    public int getSize() {
      return 32 + 1 * driverName.size() + 1 * alignmentPad.size() + 1 * deviceName.size();
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy