github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/serializablebytes.go (about) 1 // Copyright (c) 2019 IoTeX Foundation 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package protocol 7 8 // SerializableBytes defines a type of serializable bytes 9 type SerializableBytes []byte 10 11 // Serialize copies and return bytes 12 func (sb SerializableBytes) Serialize() ([]byte, error) { 13 data := make([]byte, len(sb)) 14 copy(data, sb) 15 16 return data, nil 17 } 18 19 // Deserialize copies data into bytes 20 func (sb *SerializableBytes) Deserialize(data []byte) error { 21 *sb = make([]byte, len(data)) 22 copy(*sb, data) 23 24 return nil 25 }