Skip to content

Commit 5466ced

Browse files
Mobile Ads Developer Relationscopybara-github
authored andcommitted
Add support for JSPB conversion for CUIs.
PiperOrigin-RevId: 832506826
1 parent fd2d252 commit 5466ced

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace GoogleMobileAds.Common
6+
{
7+
[Serializable]
8+
public struct CuiLoggablePayload
9+
{
10+
public Insight unity_gma_sdk_cui_message;
11+
}
12+
}

source/plugin/Assets/GoogleMobileAds/Common/JspbConverter.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ internal static string ToJspb<TPayload>(LoggableRemoteCaptureRequest<TPayload> r
2020
{
2121
payloads.Add(ToJspb((ExceptionLoggablePayload)(object)payload));
2222
}
23+
else if (payload is CuiLoggablePayload)
24+
{
25+
payloads.Add(ToJspb((CuiLoggablePayload)(object)payload));
26+
}
2327
else
2428
{
2529
Debug.LogError("JspbConverter encountered an unknown payload type: " +
@@ -43,6 +47,18 @@ internal static string ToJspb(ClientPingMetadata metadata)
4347
return string.Format("[{0}]", metadata.binary_name);
4448
}
4549

50+
private static string ToJspb(List<string> list)
51+
{
52+
if (list == null || list.Count == 0) return "null";
53+
54+
var quotedElements = new List<string>();
55+
foreach(string elem in list)
56+
{
57+
quotedElements.Add(QuoteString(elem));
58+
}
59+
return string.Format("[{0}]", string.Join(",", quotedElements.ToArray()));
60+
}
61+
4662
// VisibleForTesting
4763
internal static string QuoteString(string s)
4864
{
@@ -140,5 +156,58 @@ internal static string ToJspb(ExceptionReport report)
140156
return string.Format("[{0}]", string.Join(",", fields.ToArray()));
141157
}
142158
#endregion
159+
160+
#region CUIs handling
161+
// VisibleForTesting
162+
internal static string ToJspb(CuiLoggablePayload payload)
163+
{
164+
if (payload.unity_gma_sdk_cui_message == null) return "[]";
165+
166+
// unity_gma_sdk_cui_message has field index 36.
167+
return string.Format("[{{\"36\":{0}}}]",
168+
ToJspb(payload.unity_gma_sdk_cui_message));
169+
}
170+
171+
// VisibleForTesting
172+
internal static string ToJspb(Insight insight)
173+
{
174+
// The order must match the proto field numbers.
175+
var fields = new List<string>
176+
{
177+
((int)insight.Name).ToString(), // 1
178+
insight.Success.ToString().ToLower(), // 2
179+
insight.StartTimeEpochMillis.ToString(), // 3
180+
QuoteString(insight.SdkVersion), // 4
181+
QuoteString(insight.AppId), // 5
182+
QuoteString(insight.AdUnitId), // 6
183+
((int)insight.Format).ToString(), // 7
184+
((int)insight.Platform).ToString(), // 8
185+
QuoteString(insight.AppVersionName), // 9
186+
QuoteString(insight.UnityVersion), // 10
187+
QuoteString(insight.OSVersion), // 11
188+
QuoteString(insight.DeviceModel), // 12
189+
ToJspb(insight.Tags), // 13
190+
ToJspb(insight.Tracing), // 14
191+
QuoteString(insight.Details) // 15
192+
};
193+
return string.Format("[{0}]", string.Join(",", fields.ToArray()));
194+
}
195+
196+
private static string ToJspb(Insight.TracingActivity tracing)
197+
{
198+
if (tracing == null) return "null";
199+
200+
// The order must match the proto field numbers.
201+
var fields = new List<string>
202+
{
203+
QuoteString(tracing.OperationName), // 1
204+
QuoteString(tracing.Id), // 2
205+
QuoteString(tracing.ParentId), // 3
206+
tracing.DurationMillis.ToString(), // 4
207+
tracing.HasEnded.ToString().ToLower() // 5
208+
};
209+
return string.Format("[{0}]", string.Join(",", fields.ToArray()));
210+
}
211+
#endregion
143212
}
144213
}

0 commit comments

Comments
 (0)