Documentation ¶
Index ¶
- func Transform(originalNumber int) (encoded string)
- type StringSizer
- func (ss *StringSizer) ExpandMap(m map[string]interface{}) (decoded map[string]interface{}, err error)
- func (ss *StringSizer) ExpandMapFromString(s string) (m map[string]interface{}, err error)
- func (ss *StringSizer) ExpandString(transformed string) (original string, err error)
- func (ss *StringSizer) Save() string
- func (ss *StringSizer) ShrinkMap(m map[string]interface{}) (new map[string]interface{})
- func (ss *StringSizer) ShrinkMapToString(m map[string]interface{}) (shortenedJSON string)
- func (ss *StringSizer) ShrinkString(original string) (transformed string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type StringSizer ¶ added in v1.0.0
type StringSizer struct { Encoding map[string]string `json:"encoding"` Current int `json:"current"` sync.RWMutex }
StringSizer defines the patterns of encoding and the current state of encoding.
func New ¶ added in v1.0.0
func New(savedStringSizer ...string) (ss *StringSizer, err error)
New generates a new map key shrinker. You can optionally pass a previously saved StringSizer that was returned from the `.Save()` function.
func (*StringSizer) ExpandMap ¶ added in v1.0.0
func (ss *StringSizer) ExpandMap(m map[string]interface{}) (decoded map[string]interface{}, err error)
ExpandMap will transform back each string key in a map and return the original map subsituted with its original string keys. Returns an error when a key does not exist.
func (*StringSizer) ExpandMapFromString ¶ added in v1.0.0
func (ss *StringSizer) ExpandMapFromString(s string) (m map[string]interface{}, err error)
ExpandMapFromString will return a map from the shortened JSON of a shrinked map (i.e. the output of `ShrinkMapToString`). Returns an error when a key does not exist.
func (*StringSizer) ExpandString ¶ added in v1.0.0
func (ss *StringSizer) ExpandString(transformed string) (original string, err error)
ExpandString will take a shrunk string and expand it to the original string. Returns an error when a key does not exist.
func (*StringSizer) Save ¶ added in v1.0.0
func (ss *StringSizer) Save() string
StringSizer will return the a JSON string that can be used to reinitialize the previous state.
func (*StringSizer) ShrinkMap ¶ added in v1.0.0
func (ss *StringSizer) ShrinkMap(m map[string]interface{}) (new map[string]interface{})
ShrinkMap takes a map with string keys and converts each string key to the smallest possible string, iterating on the current in the compressor. It returns a new Go map with the transformed string keys.
func (*StringSizer) ShrinkMapToString ¶ added in v1.0.0
func (ss *StringSizer) ShrinkMapToString(m map[string]interface{}) (shortenedJSON string)
ShrinkMapToString takes a map with string keys and converts each string to the smallest possible string, iterating on the current compressor. It returns a shortened JSON string, so that is, the map `{"value_of_pi":3.141}` will be returned as the string `"a":3.141` (the brackets are removed).
func (*StringSizer) ShrinkString ¶ added in v1.0.0
func (ss *StringSizer) ShrinkString(original string) (transformed string)
ShrinkString will take a single string and convert it to the smallest possible based on the current iterator.