typehack

package
v0.0.0-...-9b6af6b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2017 License: CC0-1.0 Imports: 0 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToByteSlice

func ToByteSlice(s string) (bs []byte)

ToByteSlice returns the string s as a []byte. Note that cap in bs is set to the length of s. WARNING! bs uses the same memory as s and has therefore broken the immutability of the string s. This can lead to serious bugs, vulnerabilities or other errors if used incorrectly.

Example
package main

import (
	typehack "."
	"fmt"
)

func main() {
	s := "Hello, Gophers!"
	fmt.Println("ToByteSlice:", typehack.ToByteSlice(s))
	fmt.Println("Raw s:", s)
}
Output:
ToByteSlice: [72 101 108 108 111 44 32 71 111 112 104 101 114 115 33]
Raw s: Hello, Gophers!

func ToString

func ToString(bs []byte) (s string)

ToString returns the []byte bs as a string. Note that the cap value from bs is discarded. WARNING! s uses the same memory as bs and is therfor not Immutable. This can lead to serious bugs, vulnerabilities or other errors if used incorrectly.

Example
package main

import (
	typehack "."
	"fmt"
)

func main() {
	bs := []byte("Hello, Gophers!")
	fmt.Println("ToString:", typehack.ToString(bs))
	fmt.Println("Raw bs:", bs)
}
Output:
ToString: Hello, Gophers!
Raw bs: [72 101 108 108 111 44 32 71 111 112 104 101 114 115 33]

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL