org.tarantool.protocol.TarantoolPacket Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of connector Show documentation
Show all versions of connector Show documentation
Tarantool client for java
The newest version!
package org.tarantool.protocol;
import org.tarantool.Key;
import java.util.Map;
public class TarantoolPacket {
private final Map headers;
private final Map body;
public TarantoolPacket(Map headers, Map body) {
this.headers = headers;
this.body = body;
}
public TarantoolPacket(Map headers) {
this.headers = headers;
body = null;
}
public Long getCode() {
Object potenticalCode = headers.get(Key.CODE.getId());
if (!(potenticalCode instanceof Long)) {
//noinspection ConstantConditions
throw new IllegalStateException(
"A value contained in the header by key '" + Key.CODE.name() +
"' is not instance of Long class: " +
potenticalCode != null ? potenticalCode.getClass().toString() : "null"
);
}
Long code = (Long) potenticalCode;
return code == 0 ? code : ProtoUtils.extractErrorCode(code);
}
public Long getSync() {
return (Long) getHeaders().get(Key.SYNC.getId());
}
public Map getHeaders() {
return headers;
}
public Map getBody() {
return body;
}
public boolean hasBody() {
return body != null && body.size() > 0;
}
public long getSchemaId() {
return (Long) headers.get(Key.SCHEMA_ID.getId());
}
public Object getData() {
return hasBody() ? body.get(Key.DATA.getId()) : null;
}
public Object getError() {
return hasBody() ? body.get(Key.ERROR.getId()) : null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy