整理文档
withlin opened this issue · comments
as title
将message.entries打印出来是这样的模样,这是什么问题呢,不能可视化的看到操作语句
[]com_alibaba_otter_canal_protocol.Entry{com_alibaba_otter_canal_protocol.Entry{Header:(*com_alibaba_otter_canal_protocol.Header)(0xc00010a000), EntryTypePresent:(*com_alibaba_otter_canal_protocol.Entry_EntryType)(0xc0000f8044), StoreValue:[]uint8{0x20, 0xb}, XXX_NoUnkeyedLiteral:struct {}{}, XXX_unrecognized:[]uint8(nil), XXX_sizecache:0}, com_alibaba_otter_canal_protocol.Entry{Header:(*com_alibaba_otter_canal_protocol.Header)(0xc00010a0e0), EntryTypePresent:(*com_alibaba_otter_canal_protocol.Entry_EntryType)(0xc0000f8070), StoreValue:[]uint8{0x12, 0x4, 0x31, 0x38, 0x38, 0x30}, XXX_NoUnkeyedLiteral:struct {}{}, XXX_unrecognized:[]uint8(nil), XXX_sizecache:0}}
麻烦看一下 samples
里面有说,因为entries 还需要进一步解析
func printEntry(entrys []protocol.Entry) {
for _, entry := range entrys {
if entry.GetEntryType() == protocol.EntryType_TRANSACTIONBEGIN || entry.GetEntryType() == protocol.EntryType_TRANSACTIONEND {
continue
}
rowChange := new(protocol.RowChange)
err := proto.Unmarshal(entry.GetStoreValue(), rowChange)
checkError(err)
if rowChange != nil {
eventType := rowChange.GetEventType()
header := entry.GetHeader()
fmt.Println(fmt.Sprintf("================> binlog[%s : %d],name[%s,%s], eventType: %s", header.GetLogfileName(), header.GetLogfileOffset(), header.GetSchemaName(), header.GetTableName(), header.GetEventType()))
for _, rowData := range rowChange.GetRowDatas() {
if eventType == protocol.EventType_DELETE {
printColumn(rowData.GetBeforeColumns())
} else if eventType == protocol.EventType_INSERT {
printColumn(rowData.GetAfterColumns())
} else {
fmt.Println("-------> before")
printColumn(rowData.GetBeforeColumns())
fmt.Println("-------> after")
printColumn(rowData.GetAfterColumns())
}
}
}
}
}
func printColumn(columns []*protocol.Column) {
for _, col := range columns {
fmt.Println(fmt.Sprintf("%s : %s update= %t", col.GetName(), col.GetValue(), col.GetUpdated()))
}
}