Deck encoding and decoding

Encoding

Logic for encoding deck into a deck code string.

Encoding is done by writing a few things into a bytearray thanks to the magic of bitwise operations. That is then encoded to base64 and sanitized for url usage.

class pyartifact.deck_encoding.encode.Encoder(deck_contents, version=2)[source]

Main purpose of this class is to hold shared data across the encoding process.

There shouldn’t be a need to use this part of the library, It offers a more low level access to the encoding process, but doesn’t offer anything more practical than pyartifact.encode_deck() does.

Parameters:
  • deck_contents (DeckContents) – The deck contents.
  • version (int) – Version under which to encode, by default the newest version is used. Must be on of the supported versions for encoding (atm only V2).
deck_code

Returns the deck code for the deck contents provided.

Return type:str
pyartifact.deck_encoding.encode.encode_deck(deck_contents, version=2)[source]

Encodes deck content into a deck code string.

Parameters:
  • deck_contents (DeckContents) – A dictionary with name, heroes and cards (without those included automatically)
  • version (int) – Deck code version, atm only 2 and higher is supported
Return type:

str

Returns:

Deck code

Decoding

pyartifact.deck_encoding.decode.decode_deck_string(deck_code)[source]

Takes in deck code, e.g. ADCJWkTZX05uwGDCRV4XQGy3QGLmqUBg4GQJgGLGgO7AaABR3JlZW4vQmxhY2sgRXhhbXBsZQ__ and decodes it into a dict of name, heroes and cards.

Parameters:

deck_code (str) – Deck code

Return type:

DeckContents

Returns:

Deck contents

Raises:
  • InvalidDeckString – When an invalid deck string is provided, e.g. unknown version, bad checksum etc.
  • DeckDecodeException – When something odd happens while decoding