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

com.github.moaxcp.x11client.protocol.xselinux.ListItem Maven / Gradle / Ivy

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

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.XStruct;
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 ListItem implements XStruct {
  private int name;

  @NonNull
  private List objectContext;

  @NonNull
  private List dataContext;

  public static ListItem readListItem(X11Input in) throws IOException {
    int name = in.readCard32();
    int objectContextLen = in.readCard32();
    int dataContextLen = in.readCard32();
    List objectContext = in.readChar((int) (Integer.toUnsignedLong(objectContextLen)));
    in.readPadAlign((int) (Integer.toUnsignedLong(objectContextLen)));
    List dataContext = in.readChar((int) (Integer.toUnsignedLong(dataContextLen)));
    in.readPadAlign((int) (Integer.toUnsignedLong(dataContextLen)));
    ListItem.ListItemBuilder javaBuilder = ListItem.builder();
    javaBuilder.name(name);
    javaBuilder.objectContext(objectContext);
    javaBuilder.dataContext(dataContext);
    return javaBuilder.build();
  }

  @Override
  public void write(X11Output out) throws IOException {
    out.writeCard32(name);
    int objectContextLen = objectContext.size();
    out.writeCard32(objectContextLen);
    int dataContextLen = dataContext.size();
    out.writeCard32(dataContextLen);
    out.writeChar(objectContext);
    out.writePadAlign((int) (Integer.toUnsignedLong(objectContextLen)));
    out.writeChar(dataContext);
    out.writePadAlign((int) (Integer.toUnsignedLong(dataContextLen)));
  }

  @Override
  public int getSize() {
    return 12 + 1 * objectContext.size() + XObject.getSizeForPadAlign(4, 1 * objectContext.size()) + 1 * dataContext.size() + XObject.getSizeForPadAlign(4, 1 * dataContext.size());
  }

  public static class ListItemBuilder {
    public int getSize() {
      return 12 + 1 * objectContext.size() + XObject.getSizeForPadAlign(4, 1 * objectContext.size()) + 1 * dataContext.size() + XObject.getSizeForPadAlign(4, 1 * dataContext.size());
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy