golang实现java string的序列化
const (
STREAM_MAGIC = 0xaced
STREAM_VERSION = 5
TC_STRING = 0x74
)
func main() {
f, _ := os.Create("test.out")
defer f.Close()
f.Write(ShortBytes(STREAM_MAGIC))
f.Write(ShortBytes(STREAM_VERSION))
f.Write([]byte{TC_STRING})
str := "85bb94b8-fd4b-4e1c-8f49-3cedd49d8f28"
strLen := len(str)
f.Write(ShortBytes(uint16(strLen)))
f.Write([]byte(str))
}
func ShortBytes(i uint16) []byte {
bytes := make([]byte, 2)
binary.BigEndian.PutUint16(bytes, i)
return bytes
}