Module: UniversalID::Encoder

Defined in:
lib/universalid/encoder.rb

Overview

This module provides the ability to encode and decode objects into a compressed, URL-safe string

Class Method Summary collapse

Class Method Details

.decode(string) ⇒ Object



15
16
17
18
19
# File 'lib/universalid/encoder.rb', line 15

def decode(string)
  decoded = Base64.urlsafe_decode64(string)
  inflated = Brotli.inflate(decoded)
  UniversalID::Packer.unpack inflated
end

.encode(object, options = {}) ⇒ Object



9
10
11
12
13
# File 'lib/universalid/encoder.rb', line 9

def encode(object, options = {})
  packed = UniversalID::Packer.pack(object, options)
  deflated = Brotli.deflate(packed)
  Base64.urlsafe_encode64 deflated, padding: false
end