-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d87deff
commit d666197
Showing
3 changed files
with
27 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
//go:build !appengine | ||
// +build !appengine | ||
|
||
package pgdriver | ||
|
||
import "unsafe" | ||
|
||
func bytesToString(b []byte) string { | ||
return *(*string)(unsafe.Pointer(&b)) | ||
if len(b) == 0 { | ||
return "" | ||
} | ||
return unsafe.String(&b[0], len(b)) | ||
} | ||
|
||
//nolint:deadcode,unused | ||
func stringToBytes(s string) []byte { | ||
return *(*[]byte)(unsafe.Pointer( | ||
&struct { | ||
string | ||
Cap int | ||
}{s, len(s)}, | ||
)) | ||
if s == "" { | ||
return []byte{} | ||
} | ||
return unsafe.Slice(unsafe.StringData(s), len(s)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
//go:build !appengine | ||
// +build !appengine | ||
|
||
package bunotel | ||
|
||
import "unsafe" | ||
|
||
func bytesToString(b []byte) string { | ||
return *(*string)(unsafe.Pointer(&b)) | ||
if len(b) == 0 { | ||
return "" | ||
} | ||
return unsafe.String(&b[0], len(b)) | ||
} | ||
|
||
func stringToBytes(s string) []byte { | ||
return *(*[]byte)(unsafe.Pointer( | ||
&struct { | ||
string | ||
Cap int | ||
}{s, len(s)}, | ||
)) | ||
if s == "" { | ||
return []byte{} | ||
} | ||
return unsafe.Slice(unsafe.StringData(s), len(s)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters