After a lot of Googling, I make below solution whether it good or worst.
Please provide where I may make improvements.
I have created 2 bytes for a header, then the length of the header string and finally the length of the buffered data. The code is below:
import(
"encoding/binary"
"fmt"
"time"
"strings"
"encoding/json"
)
func BufferToBytes(buffer *[]byte, requestId string) *[]byte{
headersString := GetHeaders("audio", requestId, "audio/x-wav")
headersString = strings.Replace(headersString, "
", "
", -1)
headerInt8Array := []byte(headersString)
payload := make([]byte,2)
binary.BigEndian.PutUint16(payload, uint16(len(headerInt8Array)))//till 1st part
t := make([]byte, len(headerInt8Array))
for i := 0; i < len(headerInt8Array); i++ {
t[i] = headerInt8Array[i];
}
payload = append(payload, t...)//till 2nd part
payload = append(payload, *buffer...)//final part
return &payload;
}
func GetHeaders(params... string) string{
header := fmt.Sprintf("path: %s
", params[0])
header += fmt.Sprintf("x-requestid: %s
",params[1])//request id
header += fmt.Sprintf("x-timestamp: %s
",GetTimestamp())// timestamp
header += fmt.Sprintf("content-type: %s
",params[2])////content type
return header
}
func GetTimestamp() string {
format := "2006-01-02T15:04:05.000Z"
return time.Now().UTC().Format(format)
}
Then this data is accepted by MS bing.
Thanks