add method to load from bytes
This commit is contained in:
parent
79c235de31
commit
e2d0cb303e
16
config.go
16
config.go
@ -91,7 +91,6 @@ func (c *Config) Zero() TinD {
|
|||||||
bytes: make([]byte, c.size),
|
bytes: make([]byte, c.size),
|
||||||
config: c,
|
config: c,
|
||||||
}
|
}
|
||||||
t.String() // set the string so it's faster to recall
|
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +109,7 @@ func (c *Config) Gen() TinD {
|
|||||||
}
|
}
|
||||||
t := TinD{
|
t := TinD{
|
||||||
bytes: bytes,
|
bytes: bytes,
|
||||||
runes: runes,
|
runes: runes,
|
||||||
config: c,
|
config: c,
|
||||||
}
|
}
|
||||||
return t
|
return t
|
||||||
@ -124,7 +123,7 @@ func (c *Config) FromString(in string) (TinD, error) {
|
|||||||
return c.Zero(), errors.New("given id isn't the same size as the configuration")
|
return c.Zero(), errors.New("given id isn't the same size as the configuration")
|
||||||
}
|
}
|
||||||
t := TinD{
|
t := TinD{
|
||||||
bytes: make([]byte, c.size),
|
bytes: make([]byte, c.size),
|
||||||
config: c,
|
config: c,
|
||||||
}
|
}
|
||||||
r := []rune(in)
|
r := []rune(in)
|
||||||
@ -138,3 +137,14 @@ func (c *Config) FromString(in string) (TinD, error) {
|
|||||||
}
|
}
|
||||||
return TinD(t), nil
|
return TinD(t), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Config) Load(in []byte) (TinD, error) {
|
||||||
|
if len(in) != c.size {
|
||||||
|
return c.Zero(), errors.New("given id isn't the same size as the configuration")
|
||||||
|
}
|
||||||
|
t := TinD{
|
||||||
|
bytes: in,
|
||||||
|
config: c,
|
||||||
|
}
|
||||||
|
return t, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user