CINXE.COM
string
<!DOCTYPE html> <html class=""> <head> <meta charset="utf-8"> <title>string</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta property="description" content="A basic bare type. Values of type string look differently depending on the length L of the string being serialized:"> <meta property="og:title" content="string"> <meta property="og:image" content=""> <meta property="og:description" content="A basic bare type. Values of type string look differently depending on the length L of the string being serialized:"> <link rel="icon" type="image/svg+xml" href="/img/website_icon.svg?4"> <link rel="apple-touch-icon" sizes="180x180" href="/img/apple-touch-icon.png"> <link rel="icon" type="image/png" sizes="32x32" href="/img/favicon-32x32.png"> <link rel="icon" type="image/png" sizes="16x16" href="/img/favicon-16x16.png"> <link rel="alternate icon" href="/img/favicon.ico" type="image/x-icon" /> <link href="/css/bootstrap.min.css?3" rel="stylesheet"> <link href="/css/telegram.css?241" rel="stylesheet" media="screen"> <style> </style> </head> <body class="preload"> <div class="dev_page_wrap"> <div class="dev_page_head navbar navbar-static-top navbar-tg"> <div class="navbar-inner"> <div class="container clearfix"> <ul class="nav navbar-nav navbar-right hidden-xs"><li class="navbar-twitter"><a href="https://twitter.com/telegram" target="_blank" data-track="Follow/Twitter" onclick="trackDlClick(this, event)"><i class="icon icon-twitter"></i><span> Twitter</span></a></li></ul> <ul class="nav navbar-nav"> <li><a href="//telegram.org/">Home</a></li> <li class="hidden-xs"><a href="//telegram.org/faq">FAQ</a></li> <li class="hidden-xs"><a href="//telegram.org/apps">Apps</a></li> <li class=""><a href="/api">API</a></li> <li class=""><a href="/mtproto">Protocol</a></li> <li class="active"><a href="/schema">Schema</a></li> </ul> </div> </div> </div> <div class="container clearfix"> <div class="dev_page"> <div id="dev_page_content_wrap" class=" "> <div class="dev_page_bread_crumbs"><ul class="breadcrumb clearfix"><li><a href="/api" >API</a></li><i class="icon icon-breadcrumb-divider"></i><li><a href="/schema" >TL-schema</a></li><i class="icon icon-breadcrumb-divider"></i><li><a href="/type/string" >string</a></li></ul></div> <h1 id="dev_page_title">string</h1> <div id="dev_page_content"><p>A basic bare type. Values of type <code>string</code> look differently depending on the length <code>L</code> of the string being serialized:</p> <ul> <li>If <code>L <= 253</code>, the serialization contains one byte with the value of <code>L</code>, then <code>L</code> bytes of the string followed by 0 to 3 characters containing 0, such that the overall length of the value be divisible by 4, whereupon all of this is interpreted as a sequence of <code>int(L/4)+1</code> 32-bit little-endian integers.</li> <li>If <code>L >= 254</code>, the serialization contains byte 254, followed by 3 bytes with the string length <code>L</code> in little-endian order, followed by <code>L</code> bytes of the string, further followed by 0 to 3 null padding bytes.</li> </ul> <p>All strings passed to the API must be encoded in UTF-8. When arbitrary byte sequences have to be serialized, <a href="/type/bytes">bytes</a> alias is to be used.</p> <p><a href="/mtproto/serialize">Further details on basic types禄</a></p> <h3><a class="anchor" href="#related-pages" id="related-pages" name="related-pages"><i class="anchor-icon"></i></a>Related pages</h3> <h4><a class="anchor" href="#bytes" id="bytes" name="bytes"><i class="anchor-icon"></i></a><a href="/type/bytes">bytes</a></h4> <p>Basic bare type. It is an alias of the <strong><a href="/type/string">string</a></strong> type, with the difference that the value may contain arbitrary byte sequences, including invalid UTF-8 sequences.</p> <p>When computing crc32 for a constructor or method it is necessary to replace all byte types with string types.</p> <h4><a class="anchor" href="#binary-data-serialization" id="binary-data-serialization" name="binary-data-serialization"><i class="anchor-icon"></i></a><a href="/mtproto/serialize">锘緽inary Data Serialization</a></h4></div> </div> </div> </div> <div class="footer_wrap"> <div class="footer_columns_wrap footer_desktop"> <div class="footer_column footer_column_telegram"> <h5>Telegram</h5> <div class="footer_telegram_description"></div> Telegram is a cloud-based mobile and desktop messaging app with a focus on security and speed. </div> <div class="footer_column"> <h5><a href="//telegram.org/faq">About</a></h5> <ul> <li><a href="//telegram.org/faq">FAQ</a></li> <li><a href="//telegram.org/privacy">Privacy</a></li> <li><a href="//telegram.org/press">Press</a></li> </ul> </div> <div class="footer_column"> <h5><a href="//telegram.org/apps#mobile-apps">Mobile Apps</a></h5> <ul> <li><a href="//telegram.org/dl/ios">iPhone/iPad</a></li> <li><a href="//telegram.org/android">Android</a></li> <li><a href="//telegram.org/dl/web">Mobile Web</a></li> </ul> </div> <div class="footer_column"> <h5><a href="//telegram.org/apps#desktop-apps">Desktop Apps</a></h5> <ul> <li><a href="//desktop.telegram.org/">PC/Mac/Linux</a></li> <li><a href="//macos.telegram.org/">macOS</a></li> <li><a href="//telegram.org/dl/web">Web-browser</a></li> </ul> </div> <div class="footer_column footer_column_platform"> <h5><a href="/">Platform</a></h5> <ul> <li><a href="/api">API</a></li> <li><a href="//translations.telegram.org/">Translations</a></li> <li><a href="//instantview.telegram.org/">Instant View</a></li> </ul> </div> </div> <div class="footer_columns_wrap footer_mobile"> <div class="footer_column"> <h5><a href="//telegram.org/faq">About</a></h5> </div> <div class="footer_column"> <h5><a href="//telegram.org/blog">Blog</a></h5> </div> <div class="footer_column"> <h5><a href="//telegram.org/apps">Apps</a></h5> </div> <div class="footer_column"> <h5><a href="/">Platform</a></h5> </div> <div class="footer_column"> <h5><a href="//telegram.org/press">Press</a></h5> </div> </div> </div> </div> <script src="/js/main.js?47"></script> <script>backToTopInit("Go up"); removePreloadInit(); </script> </body> </html> <!-- page generated in 10.18ms -->