From 2d7b5fe532650562e83aa98b1e5f2c41149dadc6 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 21 Aug 2025 16:01:05 -0500 Subject: update with code snippet --- helpers.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 helpers.go (limited to 'helpers.go') diff --git a/helpers.go b/helpers.go new file mode 100644 index 0000000..8f63de0 --- /dev/null +++ b/helpers.go @@ -0,0 +1,42 @@ +package chatpb + +import ( + "time" + + timestamppb "google.golang.org/protobuf/types/known/timestamppb" +) + +func (c *Chats) AddGeminiComment(s string) *Chat { + chat := new(Chat) + + chat.From = Who_GEMINI + chat.Content = s + chat.Ctime = timestamppb.New(time.Now()) + + c.Append(chat) + + return chat +} + +func (c *Chats) AddUserComment(s string) *Chat { + chat := new(Chat) + + chat.From = Who_USER + chat.Content = s + + c.Append(chat) + + return 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 +} -- cgit v1.2.3