gpkm/pkm/ser_de

Types

pub type Errors {
  InvalidSize(dt: EncryptedDataType)
  ReadError(dt: EncryptedDataType)
  UnhandledDataType(dt: EncryptedDataType)
}

Constructors

  • InvalidSize(dt: EncryptedDataType)
  • ReadError(dt: EncryptedDataType)
  • UnhandledDataType(dt: EncryptedDataType)

Functions

pub fn as_binary(
  bits_read: Result(BitArray, Nil),
  data_type: EncryptedDataType,
) -> Result(BitArray, Nil)

Converts BitArray’s encoding to Bin:

  • if the BitArray’s content is already Bin, it remains unchained
  • else, it decodes the B64 BitArray
pub fn build_pkm_from_bytes(pbs: UnencryptedPkmBytes) -> Pkm

Construct Pkm record, by selecting, then converting pkm_bytes fields

This Pkm record will be serialized to JSON

pub fn deserialize_b64(b64: String) -> Result(BitArray, Nil)

Deserialize base64 string, no matter its format:

  • single line
  • multiple spaced lines
pub fn get_current_pkm_bytes_size(
  bits_read: Result(BitArray, Nil),
) -> Result(Int, Nil)
pub fn get_unencrypted_header(
  pkm_bytes: List(Int),
  endian: Endian,
) -> UnencryptedHeaderBytes
pub fn get_unencrypted_pkm_bytes(
  pkm_bits: BitArray,
  endian: Endian,
) -> UnencryptedPkmBytes

Construct UnencryptedPkmBytes record, storing named pkm data bytes, according to ProjectPokemon documentation

Handling Gen4 PKM structure for now, but newer generations should be handled later

pub fn header_as_bytes(h: UnencryptedHeaderBytes) -> List(Int)
pub fn read_pkm(
  pkm_data: String,
  dt: EncryptedDataType,
) -> Result(Pkm, Errors)

Read and deserialize PKM data depending on data type

 read_pkm(pkm_path, PkmFile(Bin))
 // read simple .pkm file (where content is binary data)

 read_pkm(pkm_path, PkmFile(B64))
 // read base64 .pkm file (where content is a base64 pkm string)

 read_pkm(pkm_bitarray, PkmBits(Bin))
 // read pkm bitarray

 read_pkm(pkm_b64_str, PkmBits(B64))
 // read base64 pkm string (convert it to binary data)
pub fn slice_bits(
  bits_read: Result(BitArray, Nil),
  dt: EncryptedDataType,
) -> Result(BitArray, Errors)

Sanitize read data by limiting its size

  • 236 if pkm size >= 236
  • 136 if pkm size >= 136
Search Document