av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

golang實現java uuid的序列化方法

瀏覽:3日期:2022-08-24 11:20:19

目前只實現了java生成的固定的uuid:85bb94b8-fd4b-4e1c-8f49-3cedd49d8f28的序列化

package mainimport ( '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: %dnn', 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: %dnn', 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); } }}

到此這篇關于golang實現java uuid的序列化方法的文章就介紹到這了,更多相關golang實現java uuid序列化內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Java
相關文章:
主站蜘蛛池模板: 理论片午午伦夜理片影院 | 99久久精品免费看国产四区 | 国产精品高潮呻吟久久av黑人 | 久久国产精品一区二区三区 | 精品国产视频 | 久久久久网站 | 国产一区二区三区四区三区四 | jizz在线看片 | 成年人视频在线免费观看 | 国产精品黄| 一区二区三区四区五区在线视频 | 国产免费视频 | 一级一级一级毛片 | 久久久久九九九女人毛片 | 日韩欧美不卡 | 亚洲一区二区三区 | 日韩黄色小视频 | 亚洲第一成人影院 | 精品乱码一区二区 | 国产区在线看 | caoporon| 久久国产精品视频 | 国产一级片免费看 | 国产在线中文 | 亚洲综合电影 | www久| 亚洲精品二区 | 久草热播 | 天天干天天爱天天爽 | 91国内在线观看 | 日韩精品免费 | 高清黄色毛片 | 羞羞视频在线免费 | 日本福利视频免费观看 | 婷婷91| av网站在线播放 | 欧美一区二区三区在线视频 | 亚洲精品福利视频 | 久久精品a级毛片 | 欧美激情久久久 | 国产免费一区二区三区 |