main

square/leakcanary

Last updated at: 29/12/2023 09:40

PrimitiveType.kt

TLDR

This file defines an enumeration class called PrimitiveType that represents different primitive types in the project. Each primitive type has a corresponding Hprof type and byte size associated with it.

Classes

PrimitiveType

This class represents a primitive type in the project. It has the following properties:

  • hprofType: The Hprof defined "basic type" for the primitive type.
  • byteSize: The size in bytes for each value of the primitive type.

The PrimitiveType class also has the following companion object properties:

  • REFERENCE_HPROF_TYPE: The Hprof defined "basic type" for references.
  • byteSizeByHprofType: A map that associates each Hprof type with its corresponding byte size.
  • primitiveTypeByHprofType: A map that associates each Hprof type with its corresponding primitive type.
package shark

/**
 * A primitive type in the prof.
 */
enum class PrimitiveType(
  /**
   * The hprof defined "basic type".
   */
  val hprofType: Int,
  /**
   * The size in bytes for each value of that type.
   */
  val byteSize: Int
) {
  BOOLEAN(4, 1),
  CHAR(5, 2),
  FLOAT(6, 4),
  DOUBLE(7, 8),
  BYTE(8, 1),
  SHORT(9, 2),
  INT(10, 4),
  LONG(11, 8);

  companion object {
    /**
     * The hprof defined "basic type" for references.
     */
    const val REFERENCE_HPROF_TYPE = 2

    val byteSizeByHprofType = values().associate { it.hprofType to it.byteSize }

    val primitiveTypeByHprofType = values().associateBy { it.hprofType }
  }
}