From e60298c839357f391eee398348d14f974b212492 Mon Sep 17 00:00:00 2001 From: Thomas LAY Date: Thu, 18 Feb 2021 10:10:02 +0100 Subject: [PATCH] Compute MaxVendor and MaxVendorIdLI at encoding if not explicitly set --- segment_allowed_vendors.go | 7 +++++++ segment_core_string.go | 16 +++++++++++++++- segment_disclosed_vendors.go | 7 +++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/segment_allowed_vendors.go b/segment_allowed_vendors.go index 68afc3a..2f52ed1 100644 --- a/segment_allowed_vendors.go +++ b/segment_allowed_vendors.go @@ -43,6 +43,13 @@ func (a *AllowedVendors) Encode() string { } bitSize += entriesSize } else { + if a.MaxVendorId == 0 { + for id, _ := range a.AllowedVendors { + if id > a.MaxVendorId { + a.MaxVendorId = id + } + } + } bitSize += a.MaxVendorId } diff --git a/segment_core_string.go b/segment_core_string.go index f6aac44..8821299 100644 --- a/segment_core_string.go +++ b/segment_core_string.go @@ -180,6 +180,13 @@ func (c *CoreString) Encode() string { } bitSize += +entriesSize } else { + if c.MaxVendorId == 0 { + for id, _ := range c.VendorsConsent { + if id > c.MaxVendorId { + c.MaxVendorId = id + } + } + } bitSize += c.MaxVendorId } @@ -196,6 +203,13 @@ func (c *CoreString) Encode() string { } bitSize += entriesSize } else { + if c.MaxVendorIdLI == 0 { + for id, _ := range c.VendorsLITransparency { + if id > c.MaxVendorIdLI { + c.MaxVendorIdLI = id + } + } + } bitSize += c.MaxVendorIdLI } @@ -203,7 +217,7 @@ func (c *CoreString) Encode() string { for _, res := range c.PubRestrictions { entriesSize := 20 for _, entry := range res.RangeEntries { - entriesSize += 1 + entriesSize++ if entry.EndVendorID > entry.StartVendorID { entriesSize += 16 * 2 } else { diff --git a/segment_disclosed_vendors.go b/segment_disclosed_vendors.go index b95ae76..4a464f2 100644 --- a/segment_disclosed_vendors.go +++ b/segment_disclosed_vendors.go @@ -43,6 +43,13 @@ func (d *DisclosedVendors) Encode() string { } bitSize += entriesSize } else { + if d.MaxVendorId == 0 { + for id, _ := range d.DisclosedVendors { + if id > d.MaxVendorId { + d.MaxVendorId = id + } + } + } bitSize += d.MaxVendorId }