I apologize in advance if the question seems incomprehensible, since android development and kotlin are not my main stack. I will try to explain in as clear a language as possible.
I have a class that is responsible for intercepting data from HTTP-request. This implementation reflects the following code
class PocketScoutInterceptor() : Interceptor {
fun buildPacket(timestamp: Long, duration: Double, request: Request, response: Response) {
val reqBody = request.body
val respBody = response.body?.string()
val packet = Packet(
id = 0,
userId = PocketScoutConfig.userId,
deviceId = PocketScoutConfig.deviceId,
sessionId = PocketScoutConfig.sessionId,
timestamp = timestamp,
duration = duration.roundToInt(),
protocol = "http",
request = room.entities.Request(
request_method = request.method,
request_url = request.url.toUrl().toString(),
request_headers = request.headers.toMultimap() as Mapping,
request_body = (reqBody?.toString() ?: ""),
request_size = (reqBody?.toString()?.length ?: 0),
),
room.entities.Response(
response_code = response.code,
response_headers = response.headers.toMultimap() as Mapping,
response_body = (respBody ?: ""),
response_size = (respBody?.length ?: 0),
)
)
}
}
Further, I need to save this data in a local database, I chose room.
Next I created a database class
@TypeConverters(value = [RoomTypeConverters::class])
@Database(
version = 1,
entities = [Packet::class],
exportSchema = false
)
abstract class NetworkDatabase : RoomDatabase() {
abstract fun packetDao(): PacketDao
}
I just have to learn how to save data in local storage. I've watched several videos on this topic and read the documentation several times, but as far as my example is concerned, I can't find an answer. Maybe you can help me