// +build !unsafe // Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved. // Use of this source code is governed by a MIT license found in the LICENSE file. package codec // stringView returns a view of the []byte as a string. // In unsafe mode, it doesn't incur allocation and copying caused by conversion. // In regular safe mode, it is an allocation and copy. // // Usage: Always maintain a reference to v while result of this call is in use, // and call keepAlive4BytesView(v) at point where done with view. func stringView(v []byte) string { return string(v) } // bytesView returns a view of the string as a []byte. // In unsafe mode, it doesn't incur allocation and copying caused by conversion. // In regular safe mode, it is an allocation and copy. // // Usage: Always maintain a reference to v while result of this call is in use, // and call keepAlive4BytesView(v) at point where done with view. func bytesView(v string) []byte { return []byte(v) } // keepAlive4BytesView maintains a reference to the input parameter for bytesView. // // Usage: call this at point where done with the bytes view. func keepAlive4BytesView(v string) {} // keepAlive4BytesView maintains a reference to the input parameter for stringView. // // Usage: call this at point where done with the string view. func keepAlive4StringView(v []byte) {}