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

您的位置:首頁技術(shù)文章
文章詳情頁

golang實現(xiàn)java uuid的序列化方法

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

目前只實現(xiàn)了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) //大端序模式的字節(jié)轉(zhuǎn)為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) //小端序模式的字節(jié)轉(zhuǎn)換 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); } }}

到此這篇關(guān)于golang實現(xiàn)java uuid的序列化方法的文章就介紹到這了,更多相關(guān)golang實現(xiàn)java uuid序列化內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 99精品在线观看 | 日本aaaa| 在线黄色av| 成人欧美一区二区三区黑人孕妇 | 欧美一级免费 | 国产日韩欧美一区 | 亚洲精品久 | 国产亚洲视频在线观看 | 蜜桃av一区 | 精品久久久久久久久久 | 婷婷久久综合 | 久草福利在线观看 | 久久中文字幕视频 | 激情五月激情综合网 | 国产一区在线观看视频 | 成人动漫一区二区 | 成人黄色在线 | 黄色一节片 | 亚洲最大av网站 | 久久久久综合 | 国产福利一区二区三区 | 成人在线a | 黄色免费网站视频 | 午夜激情在线 | 日韩视频免费大全中文字幕 | 人人看人人干 | 亚洲一区久久 | 免费理论片 | 日日操av| 婷婷导航 | 日韩黄网 | 五月激情综合网 | 国产黄色在线 | a级一级片 | 久草资源站 | 免费观看av网站 | 中文字幕在线观看网站 | 国产探花在线精品一区二区 | 99re视频在线 | 国产一级片免费观看 | 久久久黄色片 |