示例#1
0
        /**
         * Appends C# code to write a string to the byte buffer.
         */
        public static void AppendWriteString(ref string code, string varName)
        {
            string sizeFieldName = PB.CreateRandomFieldName("stringLength");

            code += "                uint " + sizeFieldName + ";\r\n";
            PBUV.AppendGetUnsignedVariantSize(ref code, varName + ".Length", sizeFieldName, "uint", 2);
            AppendWriteString(ref code, varName, sizeFieldName);
        }
示例#2
0
 /**
  * Appends C# code to write a variable-length whole value to the byte buffer.
  */
 public static void AppendWriteVariant(ref string code, string varName, int maxBytes)
 {
     code += "                if (" + varName + " == 0) {\r\n";
     code += "                    bytes[index++] = (byte)0;\r\n";
     code += "                }\r\n";
     code += "                else {\r\n";
     code += "                    int byteCount;\r\n";
     code += "                    ulong value = (ulong)" + varName + ";\r\n";
     PBUV.AppendGetUnsignedVariantSize(ref code, varName, "byteCount", "int", maxBytes);
     AppendWriteVariantInner(ref code, "byteCount");
     code += "                }\r\n";
 }