27 lines
388 B
Go
27 lines
388 B
Go
package packable
|
|
|
|
type Packable interface {
|
|
Encode() ([]byte, error)
|
|
Decode([]byte) error
|
|
}
|
|
|
|
type String string
|
|
|
|
func (s *String) String() string {
|
|
return string(*s)
|
|
}
|
|
|
|
func (s *String) Encode() ([]byte, error) {
|
|
return []byte(*s), nil
|
|
}
|
|
|
|
func (s *String) Decode(b []byte) error {
|
|
*s = String(string(b))
|
|
return nil
|
|
}
|
|
|
|
func NewString(s string) *String {
|
|
w := String(s)
|
|
return &w
|
|
}
|