I'm currently writing a []byte
array with Golang to a file (code below). After I have written it to the file, I want to open the file in PHP and read the string. However, since it's encoded I need to use unpack
? I'm not sure what format(s) to use.
Here is my Golang code:
var jsonlen uint16
// 16KB output buffer
wbuf := bufio.NewWriterSize(os.Stdout, 16384)
// write the magic bytes
fmt.Print(MagicBytes)
// encode and write json
json, err := json.Marshal(Metadata)
if err != nil {
fmt.Println("Failed to encode the Metadata JSON:", err)
return
}
jsonlen = uint16(len(json))
err = binary.Write(wbuf, binary.LittleEndian, &jsonlen)
if err != nil {
fmt.Println("error writing output: ", err)
return
}
err = binary.Write(wbuf, binary.LittleEndian, &json)
if err != nil {
fmt.Println("error writing output: ", err)
return
}
Haven't written any permanent PHP code yet so don't have any to show here.