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

com.github.moaxcp.x11client.protocol.xprint.Printer Maven / Gradle / Ivy

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

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 Printer implements XStruct {
  @NonNull
  private List name;

  @NonNull
  private List description;

  public static Printer readPrinter(X11Input in) throws IOException {
    int nameLen = in.readCard32();
    List name = in.readChar((int) (Integer.toUnsignedLong(nameLen)));
    in.readPadAlign((int) (Integer.toUnsignedLong(nameLen)));
    int descLen = in.readCard32();
    List description = in.readChar((int) (Integer.toUnsignedLong(descLen)));
    in.readPadAlign((int) (Integer.toUnsignedLong(descLen)));
    Printer.PrinterBuilder javaBuilder = Printer.builder();
    javaBuilder.name(name);
    javaBuilder.description(description);
    return javaBuilder.build();
  }

  @Override
  public void write(X11Output out) throws IOException {
    int nameLen = name.size();
    out.writeCard32(nameLen);
    out.writeChar(name);
    out.writePadAlign((int) (Integer.toUnsignedLong(nameLen)));
    int descLen = description.size();
    out.writeCard32(descLen);
    out.writeChar(description);
    out.writePadAlign((int) (Integer.toUnsignedLong(descLen)));
  }

  @Override
  public int getSize() {
    return 8 + 1 * name.size() + XObject.getSizeForPadAlign(4, 1 * name.size()) + 1 * description.size() + XObject.getSizeForPadAlign(4, 1 * description.size());
  }

  public static class PrinterBuilder {
    public int getSize() {
      return 8 + 1 * name.size() + XObject.getSizeForPadAlign(4, 1 * name.size()) + 1 * description.size() + XObject.getSizeForPadAlign(4, 1 * description.size());
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy