-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #908 from DataDog/nogorodnikov/rumm-2139/new-event…
…-storage-format RUMM-2139: New event storage format
- Loading branch information
Showing
30 changed files
with
886 additions
and
1,368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...k-android/src/main/kotlin/com/datadog/android/core/internal/persistence/file/EventMeta.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.android.core.internal.persistence.file | ||
|
||
import com.google.gson.JsonObject | ||
import com.google.gson.JsonParseException | ||
import com.google.gson.JsonParser | ||
import kotlin.jvm.Throws | ||
|
||
internal data class EventMeta(val eventSize: Int) { | ||
|
||
val asBytes: ByteArray | ||
get() { | ||
return JsonObject() | ||
.apply { | ||
addProperty(EVENT_SIZE_KEY, eventSize) | ||
} | ||
.toString() | ||
.toByteArray(Charsets.UTF_8) | ||
} | ||
|
||
companion object { | ||
|
||
private const val EVENT_SIZE_KEY = "ev_size" | ||
|
||
@Throws(JsonParseException::class) | ||
@Suppress("ThrowingInternalException", "TooGenericExceptionCaught") | ||
fun fromBytes(metaBytes: ByteArray): EventMeta { | ||
return try { | ||
@Suppress("UnsafeThirdPartyFunctionCall") // there is Throws annotation | ||
val json = JsonParser.parseString(String(metaBytes, Charsets.UTF_8)) | ||
.asJsonObject | ||
EventMeta( | ||
eventSize = json.get(EVENT_SIZE_KEY).asInt | ||
) | ||
} catch (e: IllegalStateException) { | ||
throw JsonParseException(e) | ||
} catch (e: ClassCastException) { | ||
throw JsonParseException(e) | ||
} catch (e: NumberFormatException) { | ||
throw JsonParseException(e) | ||
} catch (e: NullPointerException) { | ||
throw JsonParseException(e) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.