Skip to content

Commit

Permalink
compare bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Jun 17, 2024
1 parent 89027ae commit c23ebbc
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,34 @@ func (em *EventManager) Events() Events { return em.events }
// EmitEvent stores a single Event object.
// Deprecated: Use EmitTypedEvent
func (em *EventManager) EmitEvent(event Event) {
if em.maxEventSize > 0 && len(event.Attributes) > em.maxEventSize {
return // Omit the event if it exceeds the max size
if em.maxEventSize > 0 {
totalEventSize := 0
for _, attr := range event.Attributes {
totalEventSize += len([]byte(attr.Key)) + len([]byte(attr.Value))
if totalEventSize > em.maxEventSize {
return // Omit the event if it exceeds the max size
}
}
}
em.events = em.events.AppendEvent(event)
}

// EmitEvents stores a series of Event objects.
// Deprecated: Use EmitTypedEvents
func (em *EventManager) EmitEvents(events Events) {
for _, event := range events {
if em.maxEventSize > 0 && len(event.Attributes) > em.maxEventSize {
continue // Omit the event if it exceeds the max size
if em.maxEventSize > 0 {
for _, event := range events {
totalEventSize := 0
for _, attr := range event.Attributes {
totalEventSize += len([]byte(attr.Key)) + len([]byte(attr.Value))
if totalEventSize > em.maxEventSize {
continue // Omit the event if it exceeds the max size
}
}
em.events = em.events.AppendEvent(event)
}
em.events = em.events.AppendEvent(event)
} else {
em.events = em.events.AppendEvents(events)
}
}

Expand All @@ -67,8 +81,14 @@ func (em *EventManager) EmitTypedEvent(tev proto.Message) error {
return err
}

if em.maxEventSize > 0 && len(event.Attributes) > em.maxEventSize {
return nil // Omit the event if it exceeds the max size
if em.maxEventSize > 0 {
totalEventSize := 0
for _, attr := range event.Attributes {
totalEventSize += len([]byte(attr.Key)) + len([]byte(attr.Value))
if totalEventSize > em.maxEventSize {
return nil // Omit the event if it exceeds the max size
}
}
}

em.EmitEvent(event)
Expand All @@ -83,8 +103,14 @@ func (em *EventManager) EmitTypedEvents(tevs ...proto.Message) error {
if err != nil {
return err
}
if em.maxEventSize > 0 && len(event.Attributes) > em.maxEventSize {
continue // Omit the event if it exceeds the max size
if em.maxEventSize > 0 {
totalEventSize := 0
for _, attr := range event.Attributes {
totalEventSize += len([]byte(attr.Key)) + len([]byte(attr.Value))
if totalEventSize > em.maxEventSize {
continue // Omit the event if it exceeds the max size
}
}
}
events = append(events, event)
}
Expand Down

0 comments on commit c23ebbc

Please sign in to comment.