VarInt एन्कोडर / डिकोडर
दशमलव मान
VarInt आउटपुट
तकनीकी विवरण
VarInt एन्कोडर / डिकोडर कैसे काम करता है
यह टूल क्या करता है
VarInt टूल unsigned integers को Protobuf-स्टाइल LEB128 variable-length integers के रूप में एन्कोड करता है और बाइनरी VarInt streams को वापस integer lists में डिकोड करता है। प्रत्येक वैल्यू उसकी magnitude के अनुसार 1–10 bytes में एन्कोड होती है, और हर byte का high bit संकेत देता है कि आगे और bytes आते हैं या नहीं। आउटपुट को byte array, hexadecimal, या Base64 के रूप में दिखाया जाता है ताकि tests और fixtures में आसानी से embed किया जा सके।
डेवलपर्स के सामान्य उपयोग मामले
Protobuf wire-format payloads को डिबग करने वाले इंजीनियर्स VarInt encode/decode का उपयोग field tags और unsigned integer field values का निरीक्षण करने के लिए करते हैं, बिना पूरा Protobuf runtime चलाए। Bitcoin और अन्य क्रिप्टोकरेंसी डेवलपर्स VarInt-encoded script lengths और transaction counts पार्स करते हैं। यह टूल उन कस्टम बाइनरी प्रोटोकॉल्स की reverse-engineering में भी मददगार है जो छोटे नंबरों के लिए compactness के कारण LEB128 अपनाते हैं।
डेटा फ़ॉर्मैट्स, टाइप्स, या वैरिएंट्स
LEB128 (Little-Endian Base 128) प्रति byte 7 payload bits आउटपुट करता है, जहाँ most significant bit continuation flag के रूप में काम करता है। छोटे नंबर (0–127) एक single byte उपयोग करते हैं; 16,383 तक के नंबर दो bytes उपयोग करते हैं; और इसी तरह आगे। इनपुट्स whitespace, commas, या newlines से अलग किए गए decimal numbers स्वीकार करते हैं। आउटपुट्स hexadecimal, Base64, और raw byte array notation में उपलब्ध हैं। Signed integers को पहले ZigZag transformation (n << 1) ^ (n >> 31) लागू करके एन्कोड किया जा सकता है।
सामान्य समस्याएँ और किनारी मामले
JavaScript number precision 2^53 − 1 तक सीमित है; Number.MAX_SAFE_INTEGER से ऊपर की वैल्यूज़ को सुरक्षित रूप से एन्कोड नहीं किया जा सकता। Truncated VarInt streams (terminator byte गायब) आंशिक रूप से डिकोड होती हैं और offset दर्शाने वाली त्रुटि लौटाती हैं। Negative numbers को सीधे एन्कोड नहीं किया जा सकता — पहले ZigZag encoding का उपयोग करें। Screenshots से VarInt bytes कॉपी करने से बचें जहाँ Base64 padding हटाई गई हो सकती है, क्योंकि missing padding byte boundaries बदल देती है।
यह टूल बनाम कोड कब उपयोग करें
डिबगिंग के दौरान या tests लिखते समय Protobuf wire bytes का त्वरित निरीक्षण करने के लिए इस ब्राउज़र टूल का उपयोग करें। प्रोडक्शन एन्कोडिंग के लिए 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 को एक ही कॉल में संभालती हैं।