fixed semi sync format & refactor

This commit is contained in:
agapple
2017-12-27 16:53:09 +08:00
parent c6f4de9f88
commit 9595e6abbd
7 changed files with 81 additions and 90 deletions

View File

@@ -10,26 +10,23 @@ import com.alibaba.otter.canal.parse.driver.mysql.utils.ByteHelper;
/**
* semi ack command
*
* @author amos_chen
*
*/
public class SemiAckCommandPacket extends CommandPacket {
public long binlogPosition;
public String binlogFileName;
public SemiAckCommandPacket(){
}
@Override
public void fromBytes(byte[] data) throws IOException {
// TODO Auto-generated method stub
public long binlogPosition;
public String binlogFileName;
}
public SemiAckCommandPacket(){
/**
}
@Override
public void fromBytes(byte[] data) throws IOException {
}
/**
* <pre>
* Bytes Name
* --------------------------------------------------------
@@ -37,22 +34,22 @@ public class SemiAckCommandPacket extends CommandPacket {
* ----- ----
* 1 semi mark
* 8 binlog position to start at (little endian)
* n binlog file name
* n binlog file name
*
* </pre>
*/
public byte[] toBytes() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
//0 write semi mark
out.write(0xef);
//1 write 8 bytes for position
ByteHelper.write8ByteUnsignedIntLittleEndian(binlogPosition, out);
//2 write binlog filename
if(StringUtils.isNotEmpty(binlogFileName)){
out.write(binlogFileName.getBytes());
}
return out.toByteArray();
}
public byte[] toBytes() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
// 0 write semi mark
out.write(0xef);
// 1 write 8 bytes for position
ByteHelper.write8ByteUnsignedIntLittleEndian(binlogPosition, out);
// 2 write binlog filename
if (StringUtils.isNotEmpty(binlogFileName)) {
out.write(binlogFileName.getBytes());
}
return out.toByteArray();
}
}