{"id":6218,"date":"2026-07-08T08:42:41","date_gmt":"2026-07-07T23:42:41","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=6218"},"modified":"2026-07-08T13:28:15","modified_gmt":"2026-07-08T04:28:15","slug":"mediaserver-mini_mediaserver_1-code-description-amf0-cpp1-9","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/07\/08\/mediaserver-mini_mediaserver_1-code-description-amf0-cpp1-9\/","title":{"rendered":"[Mediaserver]mini_Mediaserver_1-\ucf54\ub4dc\uc124\uba85\/code description-amf0.cpp(1-9)"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb \ucf54\ub4dc \uc124\uba85 \/ Code Explanation<\/p>\n\n\n\n<p>\u2714\ufe0f void Amf0::write_string(std::vector&amp; buf, const std::string&amp; str)<\/p>\n\n\n\n<p>&#8212; \ubc84\ud37c\ub9cc \ud0a4\uc6b0\uace0 \uac12\uc744 \ubc18\ud658\ud558\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4.<br>It only expands the buffer and does not return a value.<\/p>\n\n\n\n<p>&#8212; push_back : vector\uc758 \ud604\uc7ac \ub05d\uc5d0 \uadf8 \uac12\uc744 \ubcf5\uc0ac\ud574\uc11c \ubd99\uc785\ub2c8\ub2e4.<br>push_back: Copies the value and appends it to the current end of the vector.<\/p>\n\n\n\n<p>&#8212; AMF0\uc5d0\uc11c\ub294 \uc774 \uccab \ubc14\uc774\ud2b8 0x02\uac00 &#8220;\uc9c0\uae08\ubd80\ud130\ub294 \ubb38\uc790\uc5f4\uc774\ub2e4&#8221;\ub77c\ub294 \ud0c0\uc785 \ub9c8\ucee4 \uc5ed\ud560\uc744 \ud569\ub2c8\ub2e4.<br>In AMF0, this first byte, 0x02, acts as a type marker indicating &#8220;what follows is a string.&#8221;<\/p>\n\n\n\n<p>&#8212; \uadf8\ub798\uc11c \ub514\ucf54\ub354\uac00 \ub4a4\uc5d0 \uc624\ub294 \uae38\uc774\ub97c \ubb38\uc790\uc5f4\ub85c \ud574\uc11d\ud558\uac8c \ub9cc\ub4dc\ub294 \uc2e0\ud638\uc785\ub2c8\ub2e4.<br>So, it is a signal that tells the decoder to interpret the length that follows as a string.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>buf.push_back(0x02);<\/code><\/pre>\n\n\n\n<p>&#8212; UTF-8 \uae30\uc900:\u00a0<code>str.size()<\/code>\ub294 \ubc14\uc774\ud2b8 \uc218\uc785\ub2c8\ub2e4.<br>In UTF-8: str.size() represents the number of bytes.<\/p>\n\n\n\n<p>&#8212; \ubb38\uc790 \uac1c\uc218\uac00 \uc544\ub2d9\ub2c8\ub2e4.<br>It is not the number of characters.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>uint16_t len = str.size();<\/code><\/pre>\n\n\n\n<p>&#8212; len\uc758 \uac12\uc774 6\uc778 \uacbd\uc6b0\ub77c\uace0 \uac00\uc815 \ud560 \uacbd\uc6b0<br>Assuming the value of len is 6<\/p>\n\n\n\n<p>&#8212; ex: len(16bit) = 0000 0000 0000 0110\u2082 = 6<\/p>\n\n\n\n<p>&#8212; len >> 8 = {0000 0000 }{0000 0000 0000 0110 } \u2192 8\uce78 \uc774\ub3d9\/Move 8 spaces \u2192<\/p>\n\n\n\n<p>&#8212; 0xFF = 1111 1111\u2082<\/p>\n\n\n\n<p>&#8212; \ube44\ud2b8 \uc5f0\uc0b0\ud558\uba74 0000 0110 \u2192 0x06<br>Performing a bitwise operation yields 0000 0110 \u2192 0x06.<\/p>\n\n\n\n<p>&#8212; len \u2192 0000 0000 0000 0110 \u2192 8\ube44\ud2b8\uc774\ub3d9 \u2192 \uc624\ub978\ucabd\uc73c\ub85c \ubaa8\ub450 \ubc00\ub824\uc11c 0000 0000 0000 0000<br>    0xFF \u2192 0000 0000 1111 1111 \u2190 \uc55e\uc5d0 0\uc744 \uc790\ub3d9\uc73c\ub85c \ucc44\uc6c0<\/p>\n\n\n\n<p>len \u2192 0000 0000 0000 0110 \u2192 8-bit shift \u2192 shifted entirely to the right, resulting in 0000 0000 0000 0000<br>0xFF \u2192 0000 0000 1111 1111 \u2190 leading zeros are automatically filled in<\/p>\n\n\n\n<p>&#8212; \uadf8\ub798\uc11c \uac19\uc778 and\uc5f0\uc0b0\ud558\uba74 \ub458\ub2e41\uc774\uc5b4\uc57c 1\uc774\ub418\ub2c8\uae4c \uac12\uc740 \uadf8\ub0e5 0000 0000<br>So, when you perform an AND operation, the result is 1 only if both bits are 1; therefore, the value is simply 0000 0000.<\/p>\n\n\n\n<p>&#8212; \ubc31\ud130\uac00 8\ube44\ud2b8 \uc774\ubbc0\ub85c 8\ube44\ud2b8\uae4c\uc9c0\ub9cc\uc785\ub825 \ud560 \uc218 \uc788\uace0 16\ube44\ud2b8\uc758 \uacbd\uc6b0 \ub4a4\uc5d0\uc11c 8\uc790\ub9ac\uc218(8\ube44\ud2b8)\uae4c\uc9c0\ub9cc \uc785\ub825\ub418\uace0 \ub098\uba38\uc9c0\ub294\uc798\ub9bc<br>Since the vector is 8-bit, only up to 8 bits can be entered, and in the case of 16-bit, only the last 8 digits (8 bits) are entered and the rest is truncated.<\/p>\n\n\n\n<p>&#8212; \uadf8\ub798\uc11c \ubc31\ud130\uc5d0\ub294 0\uc774 \uc785\ub825\ub429\ub2c8\ub2e4.<br>Therefore, 0 is input into the vector.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>buf.push_back((len &gt;&gt; 8) &amp; 0xFF);<\/code><\/pre>\n\n\n\n<p>&#8212; \uc704\uc640 \uac19\uc9c0\ub9cc \ubc31\ud130\uc5d0 8\ube44\ud2b8\ub97c \uc785\ub825\ud558\uba74 \ub418\uae30 \ub54c\ubb38\uc5d0 0000 00110\uc774 \uac12\uc744 \ub9cc\ub4e4\uba74\ub429\ub2c8\ub2e4.<br>It is the same as above, but since you need to input 8 bits into the vector, you simply need to create the value <code>0000 0110<\/code>.<\/p>\n\n\n\n<p>&#8212; \uc989 len = 0000 00110 ,0xFF = 1111 1111 \uc774 \ub450 \uac12\uc744 and \uc5f0\uc0b0\ud558\uba74 \ub3d9\uc77c\ud558\uac8c 0000 00110\uc785\ub2c8\ub2e4.<br>In other words, performing an AND operation on the two values\u2014len = 0000 00110 and 0xFF = 1111 1111\u2014results in 0000 00110.<\/p>\n\n\n\n<p>&#8212; \uc774 \uac12\uc740 \uc2ed\uc9c4\uc218\ub85c 6\uc774\uace0 \ubc31\ud130\uc5d0 \uc800\uc7a5\ud569\ub2c8\ub2e4.<br>This value is 6 in decimal, and it is stored in the vector.<\/p>\n\n\n\n<p>&#8212; \uadf8\ub7ec\uba74 \ucd5c\uc885 0,6\uc774 \ucc28\ub840\ub300\ub85c \ubc31\ud130\uc5d0 \uc800\uc7a5\ud55c \uacb0\uacfc\ub97c \uc218\ud589\ud569\ub2c8\ub2e4.<br>Then, the final result of 0.6 is stored in the vector in sequence.<\/p>\n\n\n\n<p>&#8212; \uc774\ub807\uac8c \ubc14\uc774\ud2b8\ub85c \ucabc\uac1c\ub294 \uc774\uc720\ub294 \ub9ac\ud2c0\uc5d4\ub514\uc5b8 CPU\uc5d0\uc11c\ub3c4, \ube45\uc5d4\ub514\uc5b8 CPU\uc5d0\uc11c\ub3c4 \ub611\uac19\uc774 \ube45\uc5d4\ub514\uc5b8 \ubc14\uc774\ud2b8\uc5f4\uc744 \ub9cc\ub4e4\uac8c \ud558\uae30 \uc704\ud574\uc11c\uc785\ub2c8\ub2e4.<br>The reason for breaking the data down into bytes in this way is to ensure that a big-endian byte sequence is produced consistently, regardless of whether the CPU is little-endian or big-endian.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>buf.push_back(len &amp; 0xFF);<\/code><\/pre>\n\n\n\n<p>&#8212; buf\ubc31\ud130\uc5d0 \ubb38\uc790\uc5f4 \ucd94\uac00<br>Append a string to the buf vector.<\/p>\n\n\n\n<p>&#8212; \ubb38\uc790\uc5f4\uc774 string\uc778 \uacbd\uc6b0 s,t,r,i,n,g\ub85c \ucd94\uac00\ub429\ub2c8\ub2e4.<br>If the string is &#8220;string&#8221;, it is added as s, t, r, i, n, g.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>buf.insert(buf.end(), str.begin(), str.end());<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb \ucf54\ub4dc \uc124\uba85 \/ Code Explanation \u2714\ufe0f void Amf0::write_string(std::vector&amp; buf, const std::string&amp; str) &#8212; \ubc84\ud37c\ub9cc \ud0a4\uc6b0\uace0 \uac12\uc744 \ubc18\ud658\ud558\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4.It only expands the buffer and does not return a value. &#8212; push_back : vector\uc758 \ud604\uc7ac \ub05d\uc5d0 \uadf8 \uac12\uc744 \ubcf5\uc0ac\ud574\uc11c \ubd99\uc785\ub2c8\ub2e4.push_back: Copies the value and appends it to the current end of the vector. &#8212; AMF0\uc5d0\uc11c\ub294 \uc774 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,1],"tags":[],"class_list":["post-6218","post","type-post","status-publish","format-standard","hentry","category-cpp","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/6218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=6218"}],"version-history":[{"count":14,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/6218\/revisions"}],"predecessor-version":[{"id":6221,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/6218\/revisions\/6221"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=6218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=6218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=6218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}