コード例 #1
0
ファイル: Spread.cs プロジェクト: jonas12/SD-LI61D-1112
        // Puts a group name into an array of bytes.
        ////////////////////////////////////////////
        private static void toBytes(SpreadGroup group, byte[] buffer, int bufferIndex)
        {
            // Get the group's name.
            ////////////////////////
            byte[] name;
            try {
                name = System.Text.Encoding.ASCII.GetBytes(group.ToString());
            }
            catch(Exception e) {
                // Already checked for this exception in connect.
                /////////////////////////////////////////////////
                name = new byte[0];
                Console.WriteLine(e);
            }

            // Put a cap on the length.
            ///////////////////////////
            int len = name.Length;
            if(len > MAX_GROUP_NAME)
                len = MAX_GROUP_NAME;

            // Copy the name into the buffer.
            /////////////////////////////////
            System.Array.Copy(name,0,buffer,bufferIndex,len);
            for( ; len < MAX_GROUP_NAME ; len++ )
                buffer[bufferIndex + len] = 0;
        }