Search in sources :

Example 1 with AbstractBranchEndRequest

use of io.seata.core.protocol.transaction.AbstractBranchEndRequest in project seata by seata.

the class AbstractBranchEndRequestCodec method decode.

@Override
public <T> void decode(T t, ByteBuffer in) {
    AbstractBranchEndRequest abstractBranchEndRequest = (AbstractBranchEndRequest) t;
    int xidLen = 0;
    if (in.remaining() >= 2) {
        xidLen = in.getShort();
    }
    if (xidLen <= 0) {
        return;
    }
    if (in.remaining() < xidLen) {
        return;
    }
    byte[] bs = new byte[xidLen];
    in.get(bs);
    abstractBranchEndRequest.setXid(new String(bs, UTF8));
    if (in.remaining() < 8) {
        return;
    }
    abstractBranchEndRequest.setBranchId(in.getLong());
    if (in.remaining() < 1) {
        return;
    }
    abstractBranchEndRequest.setBranchType(BranchType.get(in.get()));
    int resourceIdLen = 0;
    if (in.remaining() < 2) {
        return;
    }
    resourceIdLen = in.getShort();
    if (resourceIdLen <= 0) {
        return;
    }
    if (in.remaining() < resourceIdLen) {
        return;
    }
    bs = new byte[resourceIdLen];
    in.get(bs);
    abstractBranchEndRequest.setResourceId(new String(bs, UTF8));
    int applicationDataLen = 0;
    if (in.remaining() < 4) {
        return;
    }
    applicationDataLen = in.getInt();
    if (applicationDataLen > 0) {
        if (in.remaining() < applicationDataLen) {
            return;
        }
        bs = new byte[applicationDataLen];
        in.get(bs);
        abstractBranchEndRequest.setApplicationData(new String(bs, UTF8));
    }
}
Also used : AbstractBranchEndRequest(io.seata.core.protocol.transaction.AbstractBranchEndRequest)

Example 2 with AbstractBranchEndRequest

use of io.seata.core.protocol.transaction.AbstractBranchEndRequest in project seata by seata.

the class AbstractBranchEndRequestCodec method encode.

@Override
public <T> void encode(T t, ByteBuf out) {
    AbstractBranchEndRequest abstractBranchEndRequest = (AbstractBranchEndRequest) t;
    String xid = abstractBranchEndRequest.getXid();
    long branchId = abstractBranchEndRequest.getBranchId();
    BranchType branchType = abstractBranchEndRequest.getBranchType();
    String resourceId = abstractBranchEndRequest.getResourceId();
    String applicationData = abstractBranchEndRequest.getApplicationData();
    // 1. xid
    if (xid != null) {
        byte[] bs = xid.getBytes(UTF8);
        out.writeShort((short) bs.length);
        if (bs.length > 0) {
            out.writeBytes(bs);
        }
    } else {
        out.writeShort((short) 0);
    }
    // 2. Branch Id
    out.writeLong(branchId);
    // 3. Branch Type
    out.writeByte(branchType.ordinal());
    // 4. Resource Id
    if (resourceId != null) {
        byte[] bs = resourceId.getBytes(UTF8);
        out.writeShort((short) bs.length);
        if (bs.length > 0) {
            out.writeBytes(bs);
        }
    } else {
        out.writeShort((short) 0);
    }
    // 5. Application Data
    byte[] applicationDataBytes = null;
    if (applicationData != null) {
        applicationDataBytes = applicationData.getBytes(UTF8);
        out.writeInt(applicationDataBytes.length);
        if (applicationDataBytes.length > 0) {
            out.writeBytes(applicationDataBytes);
        }
    } else {
        out.writeInt(0);
    }
}
Also used : AbstractBranchEndRequest(io.seata.core.protocol.transaction.AbstractBranchEndRequest) BranchType(io.seata.core.model.BranchType)

Aggregations

AbstractBranchEndRequest (io.seata.core.protocol.transaction.AbstractBranchEndRequest)2 BranchType (io.seata.core.model.BranchType)1