目前只实现了java生成的固定的uuid:85bb94b8-fd4b-4e1c-8f49-3cedd49d8f28的序列化
package main import ( "encoding/binary" "encoding/json" "fmt" "log" "os" "strings" "time" "github.com/Shopify/sarama" "github.com/google/uuid" ) const ( DATE_TIME_PATTERN = "" STREAM_MAGIC = 0xaced STREAM_VERSION = 5 TC_STRING = 0x74 TC_OBJECT = 0x73 TC_CLASSDESC = 0x72 SC_SERIALIZABLE = 0x02 TC_ENDBLOCKDATA = 0x78 TC_NULL = 0x70 ) func main() { uuidTest() } func uuidTest() { f, _ := os.Create("uuid-go.out") defer f.Close() f.Write(ShortBytes(STREAM_MAGIC)) f.Write(ShortBytes(STREAM_VERSION)) f.Write([]byte{TC_OBJECT}) f.Write([]byte{TC_CLASSDESC}) className := "java.util.UUID" classNameLen := len(className) f.Write(ShortBytes(uint16(classNameLen))) f.Write([]byte(className)) sid := -4856846361193249489 f.Write(LongBytes(uint64(sid))) //flags f.Write([]byte{2}) //fields length f.Write(ShortBytes(2)) //field type code f.Write([]byte{'J'}) f1 := "leastSigBits" f1Len := len(f1) f.Write(ShortBytes(uint16(f1Len))) f.Write([]byte(f1)) //filed type code f.Write([]byte{'J'}) f2 := "mostSigBits" f2Len := len(f2) f.Write(ShortBytes(uint16(f2Len))) f.Write([]byte(f2)) f.Write([]byte{TC_ENDBLOCKDATA}) f.Write([]byte{TC_NULL}) leastSigBits := -8121893460813967576 f.Write(LongBytes(uint64(leastSigBits))) mostSigBits := -8810284723775779300 f.Write(LongBytes(uint64(mostSigBits))) } func ShortBytes(i uint16) []byte { bytes := make([]byte, 2) binary.BigEndian.PutUint16(bytes, i) return bytes } func LongBytes(i uint64) []byte { bytes := make([]byte, 8) binary.BigEndian.PutUint64(bytes, i) return bytes } func BigEndian() { // 大端序 // 二进制形式:0000 0000 0000 0000 0001 0002 0003 0004 var testInt int32 = 0x01020304 // 十六进制表示 fmt.Printf("%d use big endian: \n", testInt) var testBytes []byte = make([]byte, 4) binary.BigEndian.PutUint32(testBytes, uint32(testInt)) //大端序模式 fmt.Println("int32 to bytes:", testBytes) convInt := binary.BigEndian.Uint32(testBytes) //大端序模式的字节转为int32 fmt.Printf("bytes to int32: %d\n\n", convInt) } func LittleEndian() { // 小端序 //二进制形式: 0000 0000 0000 0000 0001 0002 0003 0004 var testInt int32 = 0x01020304 // 16进制 fmt.Printf("%d use little endian: \n", testInt) var testBytes []byte = make([]byte, 4) binary.LittleEndian.PutUint32(testBytes, uint32(testInt)) //小端序模式 fmt.Println("int32 to bytes:", testBytes) convInt := binary.LittleEndian.Uint32(testBytes) //小端序模式的字节转换 fmt.Printf("bytes to int32: %d\n\n", convInt) } func Int64ToBytes(i int64) []byte { var buf = make([]byte, 8) binary.BigEndian.PutUint64(buf, uint64(i)) return buf }
java读取测试
public class Test { public static void main(String[] args) throws IOException, ClassNotFoundException { readUUIDTest(); } private static void readUUIDTest() throws IOException, ClassNotFoundException { try (var fis = new FileInputStream("uuid-go.out"); var is = new ObjectInputStream(fis)) { var uuid = is.readObject(); System.out.print(uuid); } } }
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
更新日志
2024年11月22日
2024年11月22日
- 张梦弘《大城小爱HQ》头版限量编号[低速原抓WAV+CUE]
- 张敬轩《MY 1ST COLLECTION》2CD[WAV+CUE][1.7G]
- 张玮伽《夜归人HQⅡ》2024头版限量编号[WAV+CUE][523M]
- 证声音乐图书馆《夏至 爵士境地》[320K/MP3][70.37MB]
- 孙露《同名专辑》限量1:1母盘直刻[低速原抓WAV+CUE]
- 【宝丽金唱片】群星《鼓舞飞扬》WAV+CUE
- 莫扎特弗雷德沃夏克肖斯塔科维奇《钢琴五重奏》(DG24-96)FLAC
- 证声音乐图书馆《夏至 爵士境地》[FLAC/分轨][360.16MB]
- 证声音乐图书馆《日落琴声 x 弦乐》[320K/MP3][71.2MB]
- 证声音乐图书馆《日落琴声 x 弦乐》[FLAC/分轨][342.58MB]
- 谢采妘2011《难忘的旋律(Non-StopChaCha)》马来西亚版[WAV+CUE]
- 林翠萍《听见林翠萍,记忆就会醒来》2CD[WAV+CUE]
- 木村好夫《天龍HIFI木吉他、木村好夫精选好歌》日本天龙版[WAV整轨]
- 证声音乐图书馆《日出琴声 x 民谣》[320K/MP3][53.76MB]
- 证声音乐图书馆《日出琴声 x 民谣》[FLAC/分轨][239.29MB]