12345678910111213141516171819202122232425262728293031323334353637 |
- package uuid
- import "fmt"
- func (uuid UUID) MarshalText() ([]byte, error) {
- var js [36]byte
- encodeHex(js[:], uuid)
- return js[:], nil
- }
- func (uuid *UUID) UnmarshalText(data []byte) error {
- id, err := ParseBytes(data)
- if err == nil {
- *uuid = id
- }
- return err
- }
- func (uuid UUID) MarshalBinary() ([]byte, error) {
- return uuid[:], nil
- }
- func (uuid *UUID) UnmarshalBinary(data []byte) error {
- if len(data) != 16 {
- return fmt.Errorf("invalid UUID (got %d bytes)", len(data))
- }
- copy(uuid[:], data)
- return nil
- }
|