Path: blob/main/vendor/github.com/google/uuid/marshal.go
2875 views
// Copyright 2016 Google Inc. All rights reserved.1// Use of this source code is governed by a BSD-style2// license that can be found in the LICENSE file.34package uuid56import "fmt"78// MarshalText implements encoding.TextMarshaler.9func (uuid UUID) MarshalText() ([]byte, error) {10var js [36]byte11encodeHex(js[:], uuid)12return js[:], nil13}1415// UnmarshalText implements encoding.TextUnmarshaler.16func (uuid *UUID) UnmarshalText(data []byte) error {17id, err := ParseBytes(data)18if err != nil {19return err20}21*uuid = id22return nil23}2425// MarshalBinary implements encoding.BinaryMarshaler.26func (uuid UUID) MarshalBinary() ([]byte, error) {27return uuid[:], nil28}2930// UnmarshalBinary implements encoding.BinaryUnmarshaler.31func (uuid *UUID) UnmarshalBinary(data []byte) error {32if len(data) != 16 {33return fmt.Errorf("invalid UUID (got %d bytes)", len(data))34}35copy(uuid[:], data)36return nil37}383940