VarInt एन्कोडर / डिकोडर
दशांश मूल्ये
VarInt आउटपुट
तांत्रिक तपशील
VarInt Encoder / Decoder कसा काम करतो
हे टूल काय करते
VarInt tool unsigned integers ला Protobuf-style LEB128 variable-length integers म्हणून encode करतो आणि binary VarInt streams परत integer lists मध्ये decode करतो. प्रत्येक value त्याच्या magnitude नुसार 1–10 bytes मध्ये encode होते, आणि प्रत्येक byte चा high bit पुढे आणखी bytes येणार आहेत का हे दर्शवतो. output byte array, hexadecimal, किंवा Base64 म्हणून दाखवला जातो, ज्यामुळे tests आणि fixtures मध्ये embed करणे सोपे होते.
डेव्हलपरसाठी सामान्य वापर प्रकरणे
Protobuf wire-format payloads debug करणारे engineers पूर्ण Protobuf runtime उभे न करता field tags आणि unsigned integer field values तपासण्यासाठी VarInt encode/decode वापरतात. Bitcoin आणि इतर cryptocurrency विकसक VarInt-encoded script lengths आणि transaction counts पार्स करतात. लहान संख्यांसाठी compact असल्यामुळे LEB128 स्वीकारणाऱ्या custom binary protocols चे reverse-engineering करतानाही हे साधन उपयुक्त ठरते.
डेटा फॉरमॅट्स, प्रकार किंवा व्हेरिएंट्स
LEB128 (Little-Endian Base 128) प्रत्येक byte मध्ये 7 payload bits देते आणि most significant bit continuation flag म्हणून काम करतो. लहान संख्या (0–127) एकच byte वापरतात; 16,383 पर्यंतच्या संख्या दोन bytes वापरतात; आणि पुढे तसेच. inputs मध्ये whitespace, commas, किंवा newlines ने वेगळ्या केलेल्या decimal numbers स्वीकारल्या जातात. outputs hexadecimal, Base64, आणि raw byte array notation मध्ये उपलब्ध आहेत. Signed integers encode करण्यासाठी आधी ZigZag transformation (n << 1) ^ (n >> 31) लागू करू शकता.
सामान्य चुका आणि एज केसेस
JavaScript number precision ची मर्यादा 2^53 − 1 पर्यंत आहे; Number.MAX_SAFE_INTEGER पेक्षा मोठ्या values सुरक्षितपणे encode करता येत नाहीत. Truncated VarInt streams (terminator byte नसलेले) अंशतः decode होतात आणि offset दर्शवणारी error परत करतात. Negative numbers थेट encode करता येत नाहीत — आधी ZigZag encoding वापरा. screenshots मधून VarInt bytes कॉपी करणे टाळा, कारण Base64 padding काढलेले असू शकते; padding नसल्यास byte boundaries बदलतात.
कोडच्या तुलनेत हे टूल कधी वापरावे
debugging दरम्यान किंवा tests लिहिताना Protobuf wire bytes चे जलद inspection करण्यासाठी browser tool वापरा. production encoding साठी language-native VarInt libraries (`varint` on npm, `binary.varint` in Go's encoding/binary, `decode_varint` in Python's google.protobuf.internal) वापरा; या streaming, error recovery, आणि ZigZag transformation एकाच call मध्ये हाताळतात.