com.github.moaxcp.x11client.protocol.sync.ChangeAlarm Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of x11-client Show documentation
Show all versions of x11-client Show documentation
An x11 client implemented in java
package com.github.moaxcp.x11client.protocol.sync;
import com.github.moaxcp.x11client.protocol.OneWayRequest;
import com.github.moaxcp.x11client.protocol.X11Input;
import com.github.moaxcp.x11client.protocol.X11Output;
import java.io.IOException;
import java.lang.Byte;
import java.lang.Override;
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;
@Value
@Builder
public class ChangeAlarm implements OneWayRequest {
public static final byte OPCODE = 9;
private int id;
private int valueMask;
private int counter;
private int valueType;
private Int64 value;
private int testType;
private Int64 delta;
private int events;
public byte getOpCode() {
return OPCODE;
}
public static ChangeAlarm readChangeAlarm(X11Input in) throws IOException {
in.readPad(1);
short length = in.readCard16();
int id = in.readCard32();
int valueMask = in.readCard32();
ChangeAlarm.ChangeAlarmBuilder javaBuilder = ChangeAlarm.builder();
javaBuilder.id(id);
javaBuilder.valueMask(valueMask);
if(javaBuilder.isValueMaskEnabled(Ca.COUNTER)) {
javaBuilder.counter(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Ca.VALUE_TYPE)) {
javaBuilder.valueType(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Ca.VALUE)) {
javaBuilder.value(Int64.readInt64(in));
}
if(javaBuilder.isValueMaskEnabled(Ca.TEST_TYPE)) {
javaBuilder.testType(in.readCard32());
}
if(javaBuilder.isValueMaskEnabled(Ca.DELTA)) {
javaBuilder.delta(Int64.readInt64(in));
}
if(javaBuilder.isValueMaskEnabled(Ca.EVENTS)) {
javaBuilder.events(in.readCard32());
}
in.readPadAlign(javaBuilder.getSize());
return javaBuilder.build();
}
@Override
public void write(byte offset, X11Output out) throws IOException {
out.writeCard8((byte)(Byte.toUnsignedInt(OPCODE) + Byte.toUnsignedInt(offset)));
out.writePad(1);
out.writeCard16((short) getLength());
out.writeCard32(id);
out.writeCard32(valueMask);
if(isValueMaskEnabled(Ca.COUNTER)) {
out.writeCard32(counter);
}
if(isValueMaskEnabled(Ca.VALUE_TYPE)) {
out.writeCard32(valueType);
}
if(isValueMaskEnabled(Ca.VALUE)) {
value.write(out);
}
if(isValueMaskEnabled(Ca.TEST_TYPE)) {
out.writeCard32(testType);
}
if(isValueMaskEnabled(Ca.DELTA)) {
delta.write(out);
}
if(isValueMaskEnabled(Ca.EVENTS)) {
out.writeCard32(events);
}
out.writePadAlign(getSize());
}
public boolean isValueMaskEnabled(@NonNull Ca... maskEnums) {
for(Ca m : maskEnums) {
if(!m.isEnabled(valueMask)) {
return false;
}
}
return true;
}
@Override
public int getSize() {
return 28 + (isValueMaskEnabled(Ca.COUNTER) ? 4 : 0) + (isValueMaskEnabled(Ca.VALUE_TYPE) ? 4 : 0) + (isValueMaskEnabled(Ca.TEST_TYPE) ? 4 : 0) + (isValueMaskEnabled(Ca.EVENTS) ? 4 : 0);
}
public static class ChangeAlarmBuilder {
private ChangeAlarm.ChangeAlarmBuilder valueMask(int valueMask) {
this.valueMask = valueMask;
return this;
}
public boolean isValueMaskEnabled(@NonNull Ca... maskEnums) {
for(Ca m : maskEnums) {
if(!m.isEnabled(valueMask)) {
return false;
}
}
return true;
}
private ChangeAlarm.ChangeAlarmBuilder valueMaskEnable(Ca... maskEnums) {
for(Ca m : maskEnums) {
valueMask((int) m.enableFor(valueMask));
}
return this;
}
private ChangeAlarm.ChangeAlarmBuilder valueMaskDisable(Ca... maskEnums) {
for(Ca m : maskEnums) {
valueMask((int) m.disableFor(valueMask));
}
return this;
}
public ChangeAlarm.ChangeAlarmBuilder counter(int counter) {
this.counter = counter;
valueMaskEnable(Ca.COUNTER);
return this;
}
public ChangeAlarm.ChangeAlarmBuilder valueType(int valueType) {
this.valueType = valueType;
valueMaskEnable(Ca.VALUE_TYPE);
return this;
}
public ChangeAlarm.ChangeAlarmBuilder valueType(Valuetype valueType) {
this.valueType = (int) valueType.getValue();
valueMaskEnable(Ca.VALUE_TYPE);
return this;
}
public ChangeAlarm.ChangeAlarmBuilder value(Int64 value) {
this.value = value;
valueMaskEnable(Ca.VALUE);
return this;
}
public ChangeAlarm.ChangeAlarmBuilder testType(int testType) {
this.testType = testType;
valueMaskEnable(Ca.TEST_TYPE);
return this;
}
public ChangeAlarm.ChangeAlarmBuilder testType(Testtype testType) {
this.testType = (int) testType.getValue();
valueMaskEnable(Ca.TEST_TYPE);
return this;
}
public ChangeAlarm.ChangeAlarmBuilder delta(Int64 delta) {
this.delta = delta;
valueMaskEnable(Ca.DELTA);
return this;
}
public ChangeAlarm.ChangeAlarmBuilder events(int events) {
this.events = events;
valueMaskEnable(Ca.EVENTS);
return this;
}
public int getSize() {
return 28 + (isValueMaskEnabled(Ca.COUNTER) ? 4 : 0) + (isValueMaskEnabled(Ca.VALUE_TYPE) ? 4 : 0) + (isValueMaskEnabled(Ca.TEST_TYPE) ? 4 : 0) + (isValueMaskEnabled(Ca.EVENTS) ? 4 : 0);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy