diff options
Diffstat (limited to 'helpers.go')
| -rw-r--r-- | helpers.go | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -101,3 +101,35 @@ func (x *Chat) AppendEntry(y *ChatEntry) { x.Entries = append(x.Entries, proto.Clone(y).(*ChatEntry)) } + +// returns true if the pb is probably the same +func (c *ChatEntry) VerifyGeminiRequest(pb *GeminiRequest) (int, int, bool) { + if c.GeminiRequest == nil { + log.Warn("There is no GeminiRequest in the chat protobuf") + return -1, -1, false + } + if pb == nil { + log.Warn("There is no GeminiRequest in the passed in protobuf") + return -1, -1, false + } + if len(c.GeminiRequest.GetContents()) != len(pb.GetContents()) { + log.Warn("c != pb", len(c.GeminiRequest.GetContents()), len(pb.GetContents())) + return -1, -1, false + } + var cCount int // # of Parts in all the Contents + var pbCount int // # of Parts in all the Contents + for _, grc := range c.GeminiRequest.GetContents() { + cCount += len(grc.GetParts()) + + } + for _, grc := range pb.GetContents() { + pbCount += len(grc.GetParts()) + + } + if cCount != pbCount { + log.Warn("c != pb", cCount, pbCount) + return len(c.GeminiRequest.GetContents()), cCount, false + } + log.Info("EVERYTHING MATCHED", cCount, pbCount, len(c.GeminiRequest.GetContents()), len(pb.GetContents())) + return len(c.GeminiRequest.GetContents()), cCount, true +} |
