glogcenter/glc/ldb/storage/logdata_document.go
2022-07-02 11:31:38 +08:00

36 lines
745 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 日志文档
* 1面向leveldb存储接口
*/
package storage
import (
"bytes"
"encoding/gob"
)
// 日志的文档索引
type LogDataDocument struct {
Id uint32 `json:"id,omitempty"` // 文档ID从1开始递增
Content string `json:"content,omitempty"` // 文档内容,内容格式自行定义
}
func (d *LogDataDocument) ToBytes() []byte {
buffer := new(bytes.Buffer)
encoder := gob.NewEncoder(buffer)
encoder.Encode(d)
return buffer.Bytes()
}
func (d *LogDataDocument) LoadBytes(data []byte) {
buffer := bytes.NewBuffer(data)
decoder := gob.NewDecoder(buffer)
decoder.Decode(d)
}
func (d *LogDataDocument) ToLogDataModel() *LogDataModel {
rs := new(LogDataModel)
rs.LoadJson(d.Content)
return rs
}