chatpb/make_chat.go

104 lines
1.7 KiB
Go

package chatpb
import (
"time"
"go.wit.com/log"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)
func TestChat() {
conversation := NewChats()
/*
chat := new(Chat)
chat.Content = "this was fun"
t := new(Table)
t.Columns = 4
// t.Rows = append(t.Rows, []string{"a", "b"})
chat.Table = t
r := new(Row)
r.Fields = []string{"a", "b"}
t.Rows = append(t.Rows, r)
r = new(Row)
r.Fields = []string{"1", "", "2", "3"}
t.Rows = append(t.Rows, r)
conversation.Append(chat)
*/
t := conversation.AddTable()
t.AddRow([]string{"apple", "pear"})
conversation.AddGeminiComment("funny")
conversation.AddUserComment("yes")
conversation.AddGeminiComment("I like astronomy")
dump := conversation.FormatTEXT()
log.Println(dump)
}
func (t *Table) AddRow(f []string) {
r := new(Row)
r.Fields = f
t.Rows = append(t.Rows, r)
}
func (c *Chats) AddTable() *Table {
chat := new(Chat)
t := new(Table)
t.Columns = 4
// t.Rows = append(t.Rows, []string{"a", "b"})
r := new(Row)
r.Fields = []string{"j", "r", "a", "b"}
t.Rows = append(t.Rows, r)
r = new(Row)
r.Fields = []string{"1", "", "2", "3"}
t.Rows = append(t.Rows, r)
chat.Table = t
c.Append(chat)
return t
}
func (c *Chats) AddGeminiComment(s string) {
chat := new(Chat)
chat.From = Who_GEMINI
chat.Content = s
chat.Ctime = timestamppb.New(time.Now())
c.Append(chat)
}
func (c *Chats) AddUserComment(s string) {
chat := new(Chat)
chat.From = Who_USER
chat.Content = s
c.Append(chat)
}
func UnmarshalChats(data []byte) (*Chats, error) {
c := new(Chats)
err := c.Unmarshal(data)
return c, err
}
func UnmarshalChatsTEXT(data []byte) (*Chats, error) {
c := new(Chats)
err := c.UnmarshalTEXT(data)
return c, err
}