]> Cypherpunks repositories - gostls13.git/commitdiff
StringBytes help routine, common functionality put into package io for sharing.
authorRob Pike <r@golang.org>
Wed, 10 Dec 2008 23:46:45 +0000 (15:46 -0800)
committerRob Pike <r@golang.org>
Wed, 10 Dec 2008 23:46:45 +0000 (15:46 -0800)
R=rsc
DELTA=10  (10 added, 0 deleted, 0 changed)
OCL=20928
CL=20931

src/lib/io/io.go

index 9ae9264416100ed5d811213903be7434f2829795..26c2aaab76b5dac21d846c291fa61edbe55430c8 100644 (file)
@@ -144,3 +144,13 @@ export func Copy(src Read, dst Write) (written int64, err *os.Error) {
        return written, err
 }
 
+// Convert a string to an array of bytes for easy marshaling.
+// Could fill with syscall.StringToBytes but it adds an unnecessary \000
+// so the length would be wrong.
+export func StringBytes(s string) *[]byte {
+       b := new([]byte, len(s));
+       for i := 0; i < len(s); i++ {
+               b[i] = s[i];
+       }
+       return b;
+}