-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoder.go
38 lines (31 loc) · 841 Bytes
/
encoder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package base58
import (
"encoding/json"
"github.com/pkg/errors"
data "github.com/blockservice/echoin/sdk/go-wire/data"
)
var (
BTCEncoder data.ByteEncoder = base58Encoder{BTCAlphabet}
FlickrEncoder = base58Encoder{FlickrAlphabet}
)
// base58Encoder implements ByteEncoder encoding the slice as
// base58 url-safe encoding
type base58Encoder struct {
alphabet string
}
func (e base58Encoder) _assertByteEncoder() data.ByteEncoder {
return e
}
func (e base58Encoder) Unmarshal(dst *[]byte, src []byte) (err error) {
var s string
err = json.Unmarshal(src, &s)
if err != nil {
return errors.Wrap(err, "parse string")
}
*dst, err = DecodeAlphabet(s, e.alphabet)
return err
}
func (e base58Encoder) Marshal(bytes []byte) ([]byte, error) {
s := EncodeAlphabet(bytes, e.alphabet)
return json.Marshal(s)
}