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

com.github.moaxcp.x11client.protocol.xv.EncodingInfo Maven / Gradle / Ivy

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

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 EncodingInfo implements XStruct {
  private int encoding;

  private short width;

  private short height;

  @NonNull
  private Rational rate;

  @NonNull
  private List name;

  public static EncodingInfo readEncodingInfo(X11Input in) throws IOException {
    int encoding = in.readCard32();
    short nameSize = in.readCard16();
    short width = in.readCard16();
    short height = in.readCard16();
    in.readPad(2);
    Rational rate = Rational.readRational(in);
    List name = in.readChar(Short.toUnsignedInt(nameSize));
    in.readPadAlign(Short.toUnsignedInt(nameSize));
    EncodingInfo.EncodingInfoBuilder javaBuilder = EncodingInfo.builder();
    javaBuilder.encoding(encoding);
    javaBuilder.width(width);
    javaBuilder.height(height);
    javaBuilder.rate(rate);
    javaBuilder.name(name);
    return javaBuilder.build();
  }

  @Override
  public void write(X11Output out) throws IOException {
    out.writeCard32(encoding);
    short nameSize = (short) name.size();
    out.writeCard16(nameSize);
    out.writeCard16(width);
    out.writeCard16(height);
    out.writePad(2);
    rate.write(out);
    out.writeChar(name);
    out.writePadAlign(Short.toUnsignedInt(nameSize));
  }

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy