forked from appleboy/gin-jwt
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
3 changed files
with
890 additions
and
6 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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package jwt | ||
|
||
import ( | ||
"unsafe" | ||
) | ||
|
||
// StringToBytes converts string to byte slice without a memory allocation. | ||
func StringToBytes(s string) []byte { | ||
return *(*[]byte)(unsafe.Pointer( | ||
&struct { | ||
string | ||
Cap int | ||
}{s, len(s)}, | ||
)) | ||
} | ||
|
||
// BytesToString converts byte slice to string without a memory allocation. | ||
func BytesToString(b []byte) string { | ||
return *(*string)(unsafe.Pointer(&b)) | ||
} |
Oops, something went wrong.