-
Notifications
You must be signed in to change notification settings - Fork 347
Expand file tree
/
Copy pathProbeDefinitionDeserializer.java
More file actions
88 lines (74 loc) · 3.51 KB
/
Copy pathProbeDefinitionDeserializer.java
File metadata and controls
88 lines (74 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.datadog.debugger.probe;
import com.datadog.debugger.agent.Configuration;
import com.datadog.debugger.util.MoshiHelper;
import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.JsonReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import okio.Okio;
public class ProbeDefinitionDeserializer {
static final JsonAdapter<Configuration> CONFIGURATION_JSON_ADAPTER =
MoshiHelper.createMoshiConfig().adapter(Configuration.class);
static final JsonAdapter<MetricProbe> METRIC_PROBE_JSON_ADAPTER =
MoshiHelper.createMoshiConfig().adapter(MetricProbe.class);
static final JsonAdapter<LogProbe> LOG_PROBE_JSON_ADAPTER =
MoshiHelper.createMoshiConfig().adapter(LogProbe.class);
static final JsonAdapter<SpanProbe> SPAN_PROBE_JSON_ADAPTER =
MoshiHelper.createMoshiConfig().adapter(SpanProbe.class);
static final JsonAdapter<TriggerProbe> TRIGGER_PROBE_JSON_ADAPTER =
MoshiHelper.createMoshiConfig().adapter(TriggerProbe.class);
static final JsonAdapter<SpanDecorationProbe> SPAN_DECORATION_PROBE_JSON_ADAPTER =
MoshiHelper.createMoshiConfig().adapter(SpanDecorationProbe.class);
public static Configuration deserializeConfiguration(byte[] content) throws IOException {
return deserialize(CONFIGURATION_JSON_ADAPTER, content);
}
public static MetricProbe deserializeMetricProbe(byte[] content) throws IOException {
return deserialize(METRIC_PROBE_JSON_ADAPTER, content);
}
public static MetricProbe deserializeMetricProbe(JsonReader reader) throws IOException {
return METRIC_PROBE_JSON_ADAPTER.fromJson(reader);
}
public static LogProbe deserializeLogProbe(byte[] content) throws IOException {
LogProbe logProbe = deserialize(LOG_PROBE_JSON_ADAPTER, content);
logProbe.initSamplers();
return logProbe;
}
public static LogProbe deserializeLogProbe(JsonReader reader) throws IOException {
LogProbe logProbe = LOG_PROBE_JSON_ADAPTER.fromJson(reader);
logProbe.initSamplers();
return logProbe;
}
public static SpanProbe deserializeSpanProbe(byte[] content) throws IOException {
return deserialize(SPAN_PROBE_JSON_ADAPTER, content);
}
public static SpanProbe deserializeSpanProbe(JsonReader reader) throws IOException {
return SPAN_PROBE_JSON_ADAPTER.fromJson(reader);
}
public static TriggerProbe deserializeTriggerProbe(byte[] content) throws IOException {
TriggerProbe triggerProbe = deserialize(TRIGGER_PROBE_JSON_ADAPTER, content);
triggerProbe.initSamplers();
return triggerProbe;
}
public static TriggerProbe deserializeTriggerProbe(JsonReader jsonReader) throws IOException {
TriggerProbe triggerProbe = TRIGGER_PROBE_JSON_ADAPTER.fromJson(jsonReader);
triggerProbe.initSamplers();
return triggerProbe;
}
public static SpanDecorationProbe deserializeSpanDecorationProbe(byte[] content)
throws IOException {
SpanDecorationProbe spanDecorationProbe =
deserialize(SPAN_DECORATION_PROBE_JSON_ADAPTER, content);
spanDecorationProbe.initSamplers();
return spanDecorationProbe;
}
public static SpanDecorationProbe deserializeSpanDecorationProbe(JsonReader jsonReader)
throws IOException {
SpanDecorationProbe spanDecorationProbe =
SPAN_DECORATION_PROBE_JSON_ADAPTER.fromJson(jsonReader);
spanDecorationProbe.initSamplers();
return spanDecorationProbe;
}
private static <T> T deserialize(JsonAdapter<T> adapter, byte[] content) throws IOException {
return adapter.fromJson(Okio.buffer(Okio.source(new ByteArrayInputStream(content))));
}
}